arphaman created this revision.
arphaman added reviewers: bob.wilson, steven_wu.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch 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.


Repository:
  rL LLVM

https://reviews.llvm.org/D26234

Files:
  lib/Frontend/InitPreprocessor.cpp
  test/Frontend/objc-bool-is-bool.m


Index: test/Frontend/objc-bool-is-bool.m
===================================================================
--- /dev/null
+++ test/Frontend/objc-bool-is-bool.m
@@ -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
Index: lib/Frontend/InitPreprocessor.cpp
===================================================================
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -591,6 +591,9 @@
         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__");
 


Index: test/Frontend/objc-bool-is-bool.m
===================================================================
--- /dev/null
+++ test/Frontend/objc-bool-is-bool.m
@@ -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
Index: lib/Frontend/InitPreprocessor.cpp
===================================================================
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -591,6 +591,9 @@
         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__");
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to