Skip to content

Commit

Permalink
[Frontend] Add a predefined macro that describes the Objective-C bool…
Browse files Browse the repository at this point in the history
… type

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
  • Loading branch information
hyp committed Nov 21, 2016
1 parent 3bc6fe7 commit 9229d33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Frontend/InitPreprocessor.cpp
Expand Up @@ -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__");

Expand Down
13 changes: 13 additions & 0 deletions clang/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

0 comments on commit 9229d33

Please sign in to comment.