]> granicus.if.org Git - clang/commitdiff
PR4283: Don't truncate multibyte character constants in the
authorEli Friedman <eli.friedman@gmail.com>
Mon, 1 Jun 2009 05:25:02 +0000 (05:25 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 1 Jun 2009 05:25:02 +0000 (05:25 +0000)
preprocessor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72686 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/LiteralSupport.h
lib/Lex/LiteralSupport.cpp
lib/Lex/PPExpressions.cpp
test/Preprocessor/expr_multichar.c [new file with mode: 0644]

index d4fd43bbd2f04e23aa68dde82398b54b8b834a5b..8ee8ecf7359fed19bf14bfb0d1ea3799fa2cfa53 100644 (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; }
 };
 
index 398082ff70c4301d82aafe66b36d1493b7429d07..0324c0b01289ec26c7f9ef51559d5c31a809cec5 100644 (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
index 47c3f8d1c709ad6a2b22856bd95f2972658686e9..709e316b8036d9ad075c7278848cf50387a8f590 100644 (file)
@@ -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/test/Preprocessor/expr_multichar.c b/test/Preprocessor/expr_multichar.c
new file mode 100644 (file)
index 0000000..4df8f3d
--- /dev/null
@@ -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