diff options
author | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2021-11-09 15:57:45 +0100 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2021-11-16 09:30:36 +0100 |
commit | 168495d726e623e0b4bd6364f949ae577fa8b52e (patch) | |
tree | 0591835e5eb831cd5b6e19988374867b3950ac5b /VERSION | |
parent | 6431b483760b6b039f97a1749a055a3c181084b4 (diff) | |
download | compcert-168495d726e623e0b4bd6364f949ae577fa8b52e.tar.gz compcert-168495d726e623e0b4bd6364f949ae577fa8b52e.zip |
Revised checks for multi-character constants 'xyz'
The previous code for elaborating character constants has a small bug:
the value of a wide character constant consisting of several characters
was normalized to type `int`, while, statically, it has type `wchar_t`.
If `wchar_t` is `unsigned short`, for example, the constant `L'ab'`
would elaborate to 6357090, which is not of type `unsigned short`.
This commit fixes the bug by normalizing wide character constants to type
`wchar_t`, regardless of how many characters they contain.
The previous code was odd in another respect: leading `\0` characters
in multi-character constants were ignored. Hence, `'\0bcde'` was accepted
while `'abcde'` caused a warning.
This commit implements a more predictable behavior: the number of characters
in a character literal is limited a priori to
sizeof(type of result) / sizeof(type of each character)
So, for non-wide character constants we can typically have up to 4
characters (sizeof(int) / sizeof(char)), while for wide character
constants we can only have one character.
In effect, multiple-character wide character literals are not supported.
This is allowed by the ISO C99 standard and seems consistent with GCC
and Clang.
Finally, a multi-character constant with too many characters was
reported either as an error (if the computation overflowed the 64-bit
accumulator) or as a warning (otherwise). Here, we make this an error
in all cases.
GCC and Clang only produce warnings, and truncate the value of the
character constant, but an error feels safer.
Diffstat (limited to 'VERSION')
0 files changed, 0 insertions, 0 deletions