PR4283: Don't truncate multibyte character constants in the
preprocessor. llvm-svn: 72686
This commit is contained in:
parent
cb8317dac9
commit
d8cec57b9d
|
@ -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; }
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -221,8 +221,12 @@ 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);
|
||||
// Set the value.
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue