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 {
|
class CharLiteralParser {
|
||||||
uint64_t Value;
|
uint64_t Value;
|
||||||
bool IsWide;
|
bool IsWide;
|
||||||
|
bool IsMultiChar;
|
||||||
bool HadError;
|
bool HadError;
|
||||||
public:
|
public:
|
||||||
CharLiteralParser(const char *begin, const char *end,
|
CharLiteralParser(const char *begin, const char *end,
|
||||||
|
@ -133,6 +134,7 @@ public:
|
||||||
|
|
||||||
bool hadError() const { return HadError; }
|
bool hadError() const { return HadError; }
|
||||||
bool isWide() const { return IsWide; }
|
bool isWide() const { return IsWide; }
|
||||||
|
bool isMultiChar() const { return IsMultiChar; }
|
||||||
uint64_t getValue() const { return Value; }
|
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);
|
PP.Diag(Loc, diag::ext_multichar_character_literal);
|
||||||
else
|
else
|
||||||
PP.Diag(Loc, diag::ext_four_char_character_literal);
|
PP.Diag(Loc, diag::ext_four_char_character_literal);
|
||||||
|
IsMultiChar = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer the value from APInt to uint64_t
|
// Transfer the value from APInt to uint64_t
|
||||||
|
|
|
@ -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.
|
// Character literals are always int or wchar_t, expand to intmax_t.
|
||||||
TargetInfo &TI = PP.getTargetInfo();
|
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.
|
// Set the width.
|
||||||
llvm::APSInt Val(NumBits);
|
llvm::APSInt Val(NumBits);
|
||||||
|
|
|
@ -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