r220714 - Frontend: Define __EXCEPTIONS if -fexceptions is passed
Nico Weber
thakis at chromium.org
Thu Dec 4 16:01:18 PST 2014
This doesn't look right. Isn't cc1 -fexceptions passed if either ObjC or
C++ exceptions are enabled?
As is, it looks like this breaks this lovely bit of code from breakpad in a
.mm file:
#ifndef __EXCEPTIONS
// This file uses C++ try/catch (but shouldn't). Duplicate the macros from
// <c++/4.2.1/exception_defines.h> allowing this file to work properly with
// exceptions disabled even when other C++ libraries are used. #undef the
try
// and catch macros first in case libstdc++ is in use and has already
provided
// its own definitions.
#undef try
#define try if (true)
#undef catch
#define catch(X) if (false)
#endif // __EXCEPTIONS
even though that file is built with an explicit -fno-exceptions. Repro:
$ bin/clang -fno-exceptions -x objective-c++ -dM /dev/null -E | grep EXCE
#define OBJC_ZEROCOST_EXCEPTIONS 1
#define __EXCEPTIONS 1
On Mon, Oct 27, 2014 at 1:02 PM, David Majnemer <david.majnemer at gmail.com>
wrote:
> Author: majnemer
> Date: Mon Oct 27 15:02:19 2014
> New Revision: 220714
>
> URL: http://llvm.org/viewvc/llvm-project?rev=220714&view=rev
> Log:
> Frontend: Define __EXCEPTIONS if -fexceptions is passed
>
> GCC defines __EXCEPTIONS, regardless of language mode, if -fexceptions
> is passed. We should do the same.
>
> This fixes PR21358.
>
> Modified:
> cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> cfe/trunk/test/Frontend/exceptions.c
> cfe/trunk/test/Preprocessor/predefined-exceptions.m
>
> Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=220714&r1=220713&r2=220714&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
> +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Oct 27 15:02:19 2014
> @@ -550,7 +550,7 @@ static void InitializePredefinedMacros(c
> Builder.defineMacro("__BLOCKS__");
> }
>
> - if (!LangOpts.MSVCCompat && LangOpts.CXXExceptions)
> + if (!LangOpts.MSVCCompat && LangOpts.Exceptions)
> Builder.defineMacro("__EXCEPTIONS");
> if (!LangOpts.MSVCCompat && LangOpts.RTTI)
> Builder.defineMacro("__GXX_RTTI");
>
> Modified: cfe/trunk/test/Frontend/exceptions.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/exceptions.c?rev=220714&r1=220713&r2=220714&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Frontend/exceptions.c (original)
> +++ cfe/trunk/test/Frontend/exceptions.c Mon Oct 27 15:02:19 2014
> @@ -1,6 +1,9 @@
> -// RUN: %clang_cc1 -fms-compatibility -fexceptions -fcxx-exceptions
> -verify %s
> +// RUN: %clang_cc1 -fms-compatibility -fexceptions -fcxx-exceptions
> -DMS_MODE -verify %s
> // expected-no-diagnostics
>
> -#if defined(__EXCEPTIONS)
> +// RUN: %clang_cc1 -fms-compatibility -fexceptions -verify %s
> +// expected-no-diagnostics
> +
> +#if defined(MS_MODE) && defined(__EXCEPTIONS)
> #error __EXCEPTIONS should not be defined.
> #endif
>
> Modified: cfe/trunk/test/Preprocessor/predefined-exceptions.m
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/predefined-exceptions.m?rev=220714&r1=220713&r2=220714&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Preprocessor/predefined-exceptions.m (original)
> +++ cfe/trunk/test/Preprocessor/predefined-exceptions.m Mon Oct 27
> 15:02:19 2014
> @@ -1,6 +1,6 @@
> // RUN: %clang_cc1 -x objective-c -fobjc-exceptions -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
> +// CHECK-OBJC-NOCXX: #define __EXCEPTIONS 1
>
> // RUN: %clang_cc1 -x objective-c++ -fobjc-exceptions -fexceptions
> -fcxx-exceptions -E -dM %s | FileCheck -check-prefix=CHECK-OBJC-CXX %s
> // CHECK-OBJC-CXX: #define OBJC_ZEROCOST_EXCEPTIONS 1
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141204/55645e89/attachment.html>
More information about the cfe-commits
mailing list