aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplex.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2002-05-08 21:02:31 +0000
committerNeil Booth <neil@gcc.gnu.org>2002-05-08 21:02:31 +0000
commitb9e2d17b40af155da708201a231836c1930fe152 (patch)
treedcf24c4e35c90d6be02f200980d40c51523db0ad /gcc/cpplex.c
parent4434687a6ce7af0d637a4b1683bc91d8508fa2c5 (diff)
downloadgcc-b9e2d17b40af155da708201a231836c1930fe152.zip
gcc-b9e2d17b40af155da708201a231836c1930fe152.tar.gz
gcc-b9e2d17b40af155da708201a231836c1930fe152.tar.bz2
cpplex.c (cpp_interpret_charconst): Truncate as well as sign-extend.
* cpplex.c (cpp_interpret_charconst): Truncate as well as sign-extend. doc: * cpp.texi: Clarify multichar charconst valuation. testsuite: * gcc.dg/cpp/charconst-4.c: More tests. From-SVN: r53301
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r--gcc/cpplex.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index 39afc59..bba6f07 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -1954,16 +1954,18 @@ cpp_interpret_charconst (pfile, token, pchars_seen, unsignedp)
cpp_error (pfile, DL_WARNING, "multi-character character constant");
}
- /* Sign-extend the constant. */
- if (!unsigned_p)
+ /* Sign-extend or truncate the constant to cppchar_t. The value is
+ in WIDTH bits, but for multi-char charconsts it's value is the
+ full target type's width. */
+ if (chars_seen > 1)
+ width *= max_chars;
+ if (width < BITS_PER_CPPCHAR_T)
{
- size_t precision = width;
-
- if (chars_seen > 1)
- precision *= max_chars;
- if (precision < BITS_PER_CPPCHAR_T
- && (result & ((cppchar_t) 1 << (precision - 1))))
- result |= ~(((cppchar_t) 1 << precision) - 1);
+ mask = ((cppchar_t) 1 << width) - 1;
+ if (unsigned_p || !(result & (1 << (width - 1))))
+ result &= mask;
+ else
+ result |= ~mask;
}
*pchars_seen = chars_seen;