[Frontend] Add a predefined macro that describes the Objective-C bool type
authorAlex Lorenz <arphaman@gmail.com>
Mon, 21 Nov 2016 11:05:15 +0000 (11:05 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Mon, 21 Nov 2016 11:05:15 +0000 (11:05 +0000)
This commit adds a new predefined macro named __OBJC_BOOL_IS_BOOL that describes
the Objective-C boolean type: its value is zero if the Objective-C boolean uses
the signed character type, otherwise its value is one as the Objective-C boolean
uses the builtin boolean type.

rdar://21170440

Differential Revision: https://reviews.llvm.org/D26234

llvm-svn: 287529

clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Frontend/objc-bool-is-bool.m [new file with mode: 0644]

index 613248a..7e078fe 100644 (file)
@@ -591,6 +591,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
         Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS");
     }
 
+    Builder.defineMacro("__OBJC_BOOL_IS_BOOL",
+                        Twine(TI.useSignedCharForObjCBool() ? "0" : "1"));
+
     if (LangOpts.getGC() != LangOptions::NonGC)
       Builder.defineMacro("__OBJC_GC__");
 
diff --git a/clang/test/Frontend/objc-bool-is-bool.m b/clang/test/Frontend/objc-bool-is-bool.m
new file mode 100644 (file)
index 0000000..464fe2e
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=armv7k-apple-watchos %s | FileCheck --check-prefix=BOOL %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=x86_64-apple-darwin16 %s | FileCheck --check-prefix=CHAR %s
+// RUN: %clang_cc1 -x c -fsyntax-only -E -dM -triple=x86_64-apple-darwin16 %s | FileCheck --check-prefix=NONE %s
+
+// rdar://21170440
+
+// BOOL: #define __OBJC_BOOL_IS_BOOL 1
+// BOOL-NOT: #define __OBJC_BOOL_IS_BOOL 0
+
+// CHAR: #define __OBJC_BOOL_IS_BOOL 0
+// CHAR-NOT: #define __OBJC_BOOL_IS_BOOL 1
+
+// NONE-NOT: __OBJC_BOOL_IS_BOOL