[PATCH] D26234: [Frontend] Add a predefined macro that describes the Objective-C bool type

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 2 03:06:49 PDT 2016


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__");
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26234.76680.patch
Type: text/x-patch
Size: 1231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161102/471b0dd2/attachment.bin>


More information about the cfe-commits mailing list