From 9229d332bfc4521d6213d3cc9b485e70f812f1ee Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Mon, 21 Nov 2016 11:05:15 +0000 Subject: [PATCH] [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 llvm-svn: 287529 --- clang/lib/Frontend/InitPreprocessor.cpp | 3 +++ clang/test/Frontend/objc-bool-is-bool.m | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 clang/test/Frontend/objc-bool-is-bool.m diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 613248a..7e078fe 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/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/clang/test/Frontend/objc-bool-is-bool.m b/clang/test/Frontend/objc-bool-is-bool.m new file mode 100644 index 0000000..464fe2e --- /dev/null +++ b/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 -- 2.7.4