Hi rsmith, hfinkel,

Set the correct sign of wide character literals based on the underlying type of 
wchar_t

Fix for PR 19649

http://reviews.llvm.org/D7559

Files:
  lib/Lex/PPExpressions.cpp
  test/Preprocessor/pr19649-signed-wchar_t.c
  test/Preprocessor/pr19649-unsigned-wchar_t.c

Index: lib/Lex/PPExpressions.cpp
===================================================================
--- lib/Lex/PPExpressions.cpp
+++ lib/Lex/PPExpressions.cpp
@@ -310,7 +310,9 @@
     // 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()) {
Index: test/Preprocessor/pr19649-signed-wchar_t.c
===================================================================
--- test/Preprocessor/pr19649-signed-wchar_t.c
+++ test/Preprocessor/pr19649-signed-wchar_t.c
@@ -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
Index: test/Preprocessor/pr19649-unsigned-wchar_t.c
===================================================================
--- test/Preprocessor/pr19649-unsigned-wchar_t.c
+++ test/Preprocessor/pr19649-unsigned-wchar_t.c
@@ -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

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Lex/PPExpressions.cpp
===================================================================
--- lib/Lex/PPExpressions.cpp
+++ lib/Lex/PPExpressions.cpp
@@ -310,7 +310,9 @@
     // 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()) {
Index: test/Preprocessor/pr19649-signed-wchar_t.c
===================================================================
--- test/Preprocessor/pr19649-signed-wchar_t.c
+++ test/Preprocessor/pr19649-signed-wchar_t.c
@@ -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
Index: test/Preprocessor/pr19649-unsigned-wchar_t.c
===================================================================
--- test/Preprocessor/pr19649-unsigned-wchar_t.c
+++ test/Preprocessor/pr19649-unsigned-wchar_t.c
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to