From eced60c185c92a34953090b98d8458fb2df9dc81 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 12 Sep 2011 15:17:19 +0000 Subject: [PATCH] Only predefine the __EXCEPTIONS macro if C++ exceptions are turned on. Only predefine the OBJC_ZEROCOST_EXCEPTIONS macro if Objective-C exceptions are turned on. Fixes PR10910. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139496 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/InitPreprocessor.cpp | 6 ++++-- test/Preprocessor/init.c | 2 +- test/Preprocessor/predefined-exceptions.m | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 test/Preprocessor/predefined-exceptions.m diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 125242b5d4..d356c66c94 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -426,7 +426,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (LangOpts.ObjC1) { if (LangOpts.ObjCNonFragileABI) { Builder.defineMacro("__OBJC2__"); - Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS"); + + if (LangOpts.ObjCExceptions) + Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS"); } if (LangOpts.getGCMode() != LangOptions::NonGC) @@ -452,7 +454,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, Builder.defineMacro("__BLOCKS__"); } - if (LangOpts.Exceptions) + if (LangOpts.CXXExceptions) Builder.defineMacro("__EXCEPTIONS"); if (LangOpts.RTTI) Builder.defineMacro("__GXX_RTTI"); diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index f0920c9ded..099a51dd6e 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -94,7 +94,7 @@ // OBJCGC:#define __OBJC_GC__ 1 // // -// RUN: %clang_cc1 -x objective-c -fobjc-nonfragile-abi -E -dM < /dev/null | FileCheck -check-prefix NONFRAGILE %s +// RUN: %clang_cc1 -x objective-c -fobjc-exceptions -fobjc-nonfragile-abi -E -dM < /dev/null | FileCheck -check-prefix NONFRAGILE %s // // NONFRAGILE:#define OBJC_ZEROCOST_EXCEPTIONS 1 // NONFRAGILE:#define __OBJC2__ 1 diff --git a/test/Preprocessor/predefined-exceptions.m b/test/Preprocessor/predefined-exceptions.m new file mode 100644 index 0000000000..61fbe6a945 --- /dev/null +++ b/test/Preprocessor/predefined-exceptions.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -x objective-c -fobjc-exceptions -fobjc-nonfragile-abi -fexceptions -E -dM %s | FileCheck -check-prefix=CHECK-OBJC-NOCXX %s +// CHECK-OBJC-NOCXX: #define OBJC_ZEROCOST_EXCEPTIONS 1 +// CHECK-OBJC-NOCXX-NOT: #define __EXCEPTIONS 1 + +// RUN: %clang_cc1 -x objective-c++ -fobjc-exceptions -fobjc-nonfragile-abi -fexceptions -fcxx-exceptions -E -dM %s | FileCheck -check-prefix=CHECK-OBJC-CXX %s +// CHECK-OBJC-CXX: #define OBJC_ZEROCOST_EXCEPTIONS 1 +// CHECK-OBJC-CXX: #define __EXCEPTIONS 1 + +// RUN: %clang_cc1 -x objective-c++ -fobjc-nonfragile-abi -fexceptions -fcxx-exceptions -E -dM %s | FileCheck -check-prefix=CHECK-NOOBJC-CXX %s +// CHECK-NOOBJC-CXX-NOT: #define OBJC_ZEROCOST_EXCEPTIONS 1 +// CHECK-NOOBJC-CXX: #define __EXCEPTIONS 1 + +// RUN: %clang_cc1 -x objective-c -fobjc-nonfragile-abi -E -dM %s | FileCheck -check-prefix=CHECK-NOOBJC-NOCXX %s +// CHECK-NOOBJC-NOCXX-NOT: #define OBJC_ZEROCOST_EXCEPTIONS 1 +// CHECK-NOOBJC-NOCXX-NOT: #define __EXCEPTIONS 1