r230333 - Commit patch for PR19649. Set the correct sign of wide character for literals based on underlying type of wchar_t.

Michael Wong fraggamuffin at gmail.com
Tue Feb 24 05:34:20 PST 2015


Author: fraggamuffin
Date: Tue Feb 24 07:34:20 2015
New Revision: 230333

URL: http://llvm.org/viewvc/llvm-project?rev=230333&view=rev
Log:
Commit patch for PR19649. Set the correct sign of wide character for literals based on underlying type of wchar_t.
Reviewed:
http://reviews.llvm.org/D7559
Patch by Rachel Craig; Test cases by Hubert Tong.

Added:
    cfe/trunk/test/Preprocessor/pr19649-signed-wchar_t.c
    cfe/trunk/test/Preprocessor/pr19649-unsigned-wchar_t.c
Modified:
    cfe/trunk/lib/Lex/PPExpressions.cpp

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=230333&r1=230332&r2=230333&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Tue Feb 24 07:34:20 2015
@@ -310,7 +310,9 @@ static bool EvaluateValue(PPValue &Resul
     // Set the value.
     Val = Literal.getValue();
     // Set the signedness. UTF-16 and UTF-32 are always unsigned
-    if (!Literal.isUTF16() && !Literal.isUTF32())
+    if (Literal.isWide())
+      Val.setIsUnsigned(!TargetInfo::isTypeSigned(TI.getWCharType()));
+    else if (!Literal.isUTF16() && !Literal.isUTF32())
       Val.setIsUnsigned(!PP.getLangOpts().CharIsSigned);
 
     if (Result.Val.getBitWidth() > Val.getBitWidth()) {

Added: cfe/trunk/test/Preprocessor/pr19649-signed-wchar_t.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pr19649-signed-wchar_t.c?rev=230333&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/pr19649-signed-wchar_t.c (added)
+++ cfe/trunk/test/Preprocessor/pr19649-signed-wchar_t.c Tue Feb 24 07:34:20 2015
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -E -x c %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -E -fno-signed-char -x c %s
+
+#if (L'\0' - 1 > 0)
+# error "Unexpected expression evaluation result"
+#endif

Added: cfe/trunk/test/Preprocessor/pr19649-unsigned-wchar_t.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pr19649-unsigned-wchar_t.c?rev=230333&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/pr19649-unsigned-wchar_t.c (added)
+++ cfe/trunk/test/Preprocessor/pr19649-unsigned-wchar_t.c Tue Feb 24 07:34:20 2015
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple i386-pc-cygwin -E -x c %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -E -fshort-wchar -x c %s
+
+#if (L'\0' - 1 < 0)
+# error "Unexpected expression evaluation result"
+#endif





More information about the cfe-commits mailing list