PR4283: Don't truncate multibyte character constants in the

preprocessor.

llvm-svn: 72686
This commit is contained in:
Eli Friedman 2009-06-01 05:25:02 +00:00
parent cb8317dac9
commit d8cec57b9d
4 changed files with 14 additions and 2 deletions

View File

@ -126,6 +126,7 @@ private:
class CharLiteralParser {
uint64_t Value;
bool IsWide;
bool IsMultiChar;
bool HadError;
public:
CharLiteralParser(const char *begin, const char *end,
@ -133,6 +134,7 @@ public:
bool hadError() const { return HadError; }
bool isWide() const { return IsWide; }
bool isMultiChar() const { return IsMultiChar; }
uint64_t getValue() const { return Value; }
};

View File

@ -680,6 +680,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
PP.Diag(Loc, diag::ext_multichar_character_literal);
else
PP.Diag(Loc, diag::ext_four_char_character_literal);
IsMultiChar = true;
}
// Transfer the value from APInt to uint64_t

View File

@ -221,7 +221,11 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
// Character literals are always int or wchar_t, expand to intmax_t.
TargetInfo &TI = PP.getTargetInfo();
unsigned NumBits = TI.getCharWidth(Literal.isWide());
unsigned NumBits;
if (Literal.isMultiChar())
NumBits = TI.getIntWidth();
else
NumBits = TI.getCharWidth(Literal.isWide());
// Set the width.
llvm::APSInt Val(NumBits);

View File

@ -0,0 +1,5 @@
// RUN: clang-cc < %s -E -verify -triple i686-pc-linux-gnu
#if (('1234' >> 24) != '1')
#error Bad multichar constant calculation!
#endif