From: Alex Lorenz Date: Mon, 21 Nov 2016 11:05:15 +0000 (+0000) Subject: [Frontend] Add a predefined macro that describes the Objective-C bool type X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e960676a0763386aa9c622098df8781709d630db;p=clang [Frontend] Add a predefined macro that describes the Objective-C bool 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287529 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 613248a7f1..7e078fec92 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -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/test/Frontend/objc-bool-is-bool.m b/test/Frontend/objc-bool-is-bool.m new file mode 100644 index 0000000000..464fe2ea8c --- /dev/null +++ b/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