[PATCH] Fix sign of wide character literals in preprocessor conditions
Rachel Craik
rcraik at ca.ibm.com
Wed Feb 11 07:04:04 PST 2015
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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7559.19751.patch
Type: text/x-patch
Size: 1536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150211/98af74c1/attachment.bin>
More information about the cfe-commits
mailing list