]> granicus.if.org Git - clang/commitdiff
Add a predefine __WINT_UNSIGNED__, similar to __WCHAR_UNSIGNED__, and test them both...
authorJames Molloy <james.molloy@arm.com>
Fri, 4 May 2012 11:23:40 +0000 (11:23 +0000)
committerJames Molloy <james.molloy@arm.com>
Fri, 4 May 2012 11:23:40 +0000 (11:23 +0000)
Use this to fully fix Sema/format-strings.c for non-x86 platforms.

Reviewed by Chandler on IRC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156169 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/InitPreprocessor.cpp
test/Lexer/wchar-signedness.c [new file with mode: 0644]
test/Sema/format-strings.c

index 4df7cfd5befd7026f2f408f8e696cdbc0e9fdb73..3d9d1311c3fecf1f81848205c2366a1b052ed248 100644 (file)
@@ -497,6 +497,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   if (!LangOpts.CharIsSigned)
     Builder.defineMacro("__CHAR_UNSIGNED__");
 
+  if (!TargetInfo::isTypeSigned(TI.getWCharType()))
+    Builder.defineMacro("__WCHAR_UNSIGNED__");
+
   if (!TargetInfo::isTypeSigned(TI.getWIntType()))
     Builder.defineMacro("__WINT_UNSIGNED__");
 
diff --git a/test/Lexer/wchar-signedness.c b/test/Lexer/wchar-signedness.c
new file mode 100644 (file)
index 0000000..fea0eca
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -dM -E %s -triple x86_64-none-linux-gnu | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 -fsyntax-only -dM -E %s -triple armv7-none-eabi | FileCheck %s --check-prefix=ARM
+
+// CHECK-X86-NOT: #define __WCHAR_UNSIGNED__
+// CHECK-X86: #define __WINT_UNSIGNED__ 1
+
+// CHECK-ARM: #define __WCHAR_UNSIGNED__ 1
+// CHECK-ARM-NOT: #define __WINT_UNSIGNED__ 1
index d1dca7e2fb023b874a65f107cc35e30d0ae52dac..5d8e4cbb874ca50fef7f34f48aa38a907e426d66 100644 (file)
@@ -339,7 +339,12 @@ void pr7981(wint_t c, wchar_t c2) {
   printf("%lc", 1.0); // expected-warning{{the argument has type 'double'}}
   printf("%lc", (char) 1); // no-warning
   printf("%lc", &c); // expected-warning{{the argument has type 'wint_t *'}}
+  // If wint_t and wchar_t are the same width and wint_t is signed where
+  // wchar_t is unsigned, an implicit conversion isn't possible.
+#if defined(__WINT_UNSIGNED__) || !defined(__WCHAR_UNSIGNED__) ||   \
+  __WINT_WIDTH__ > __WCHAR_WIDTH__
   printf("%lc", c2); // no-warning
+#endif
 }
 
 // <rdar://problem/8269537> -Wformat-security says NULL is not a string literal