diff --git a/clang/include/clang/Lex/LiteralSupport.h b/clang/include/clang/Lex/LiteralSupport.h index d4fd43bbd2f0..8ee8ecf7359f 100644 --- a/clang/include/clang/Lex/LiteralSupport.h +++ b/clang/include/clang/Lex/LiteralSupport.h @@ -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; } }; diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp index 398082ff70c4..0324c0b01289 100644 --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -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 diff --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp index 47c3f8d1c709..709e316b8036 100644 --- a/clang/lib/Lex/PPExpressions.cpp +++ b/clang/lib/Lex/PPExpressions.cpp @@ -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. diff --git a/clang/test/Preprocessor/expr_multichar.c b/clang/test/Preprocessor/expr_multichar.c new file mode 100644 index 000000000000..4df8f3d4f9ea --- /dev/null +++ b/clang/test/Preprocessor/expr_multichar.c @@ -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