aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-06-01 05:25:02 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-06-01 05:25:02 +0000
commit2a1c363f38e59a5044fc349aa7e538a50954c244 (patch)
treea0fb324775573ed4cd50f35464f98ae0ac80b15c
parent852d63b806c5cbd730c6b9d696e2e27d02546b49 (diff)
PR4283: Don't truncate multibyte character constants in the
preprocessor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72686 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Lex/LiteralSupport.h2
-rw-r--r--lib/Lex/LiteralSupport.cpp1
-rw-r--r--lib/Lex/PPExpressions.cpp8
-rw-r--r--test/Preprocessor/expr_multichar.c5
4 files changed, 14 insertions, 2 deletions
diff --git a/include/clang/Lex/LiteralSupport.h b/include/clang/Lex/LiteralSupport.h
index d4fd43bbd2..8ee8ecf735 100644
--- a/include/clang/Lex/LiteralSupport.h
+++ b/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/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp
index 398082ff70..0324c0b012 100644
--- a/lib/Lex/LiteralSupport.cpp
+++ b/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/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp
index 47c3f8d1c7..709e316b80 100644
--- a/lib/Lex/PPExpressions.cpp
+++ b/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/test/Preprocessor/expr_multichar.c b/test/Preprocessor/expr_multichar.c
new file mode 100644
index 0000000000..4df8f3d4f9
--- /dev/null
+++ b/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