[cfe-commits] r72686 - in /cfe/trunk: include/clang/Lex/LiteralSupport.h lib/Lex/LiteralSupport.cpp lib/Lex/PPExpressions.cpp test/Preprocessor/expr_multichar.c

Eli Friedman eli.friedman at gmail.com
Sun May 31 22:25:02 PDT 2009


Author: efriedma
Date: Mon Jun  1 00:25:02 2009
New Revision: 72686

URL: http://llvm.org/viewvc/llvm-project?rev=72686&view=rev
Log:
PR4283: Don't truncate multibyte character constants in the 
preprocessor.


Added:
    cfe/trunk/test/Preprocessor/expr_multichar.c
Modified:
    cfe/trunk/include/clang/Lex/LiteralSupport.h
    cfe/trunk/lib/Lex/LiteralSupport.cpp
    cfe/trunk/lib/Lex/PPExpressions.cpp

Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=72686&r1=72685&r2=72686&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h Mon Jun  1 00:25:02 2009
@@ -126,6 +126,7 @@
 class CharLiteralParser {
   uint64_t Value;
   bool IsWide;
+  bool IsMultiChar;
   bool HadError;
 public:
   CharLiteralParser(const char *begin, const char *end,
@@ -133,6 +134,7 @@
 
   bool hadError() const { return HadError; }
   bool isWide() const { return IsWide; }
+  bool isMultiChar() const { return IsMultiChar; }
   uint64_t getValue() const { return Value; }
 };
 

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=72686&r1=72685&r2=72686&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Mon Jun  1 00:25:02 2009
@@ -680,6 +680,7 @@
       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

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=72686&r1=72685&r2=72686&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Mon Jun  1 00:25:02 2009
@@ -221,8 +221,12 @@
 
     // 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.

Added: cfe/trunk/test/Preprocessor/expr_multichar.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/expr_multichar.c?rev=72686&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/expr_multichar.c (added)
+++ cfe/trunk/test/Preprocessor/expr_multichar.c Mon Jun  1 00:25:02 2009
@@ -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





More information about the cfe-commits mailing list