Author: majnemer Date: Sun Feb 28 19:40:36 2016 New Revision: 262198 URL: http://llvm.org/viewvc/llvm-project?rev=262198&view=rev Log: [clang-cl] /EHc should not effect functions with explicit exception specifications
Functions with an explicit exception specification have their behavior dictated by the specification. The additional /EHc behavior only comes into play if no exception specification is given. Modified: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/lib/Driver/Tools.h cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/CodeGenCXX/exceptions-cxx-ehsc.cpp cfe/trunk/test/Driver/cl-options.c Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=262198&r1=262197&r2=262198&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Sun Feb 28 19:40:36 2016 @@ -4119,8 +4119,9 @@ void Clang::ConstructJob(Compilation &C, bool EmitCodeView = false; // Add clang-cl arguments. + types::ID InputType = Input.getType(); if (getToolChain().getDriver().IsCLMode()) - AddClangCLArgs(Args, CmdArgs, &DebugInfoKind, &EmitCodeView); + AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView); // Pass the linker version in use. if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { @@ -4133,7 +4134,6 @@ void Clang::ConstructJob(Compilation &C, // Explicitly error on some things we know we don't support and can't just // ignore. - types::ID InputType = Input.getType(); if (!Args.hasArg(options::OPT_fallow_unsupported)) { Arg *Unsupported; if (types::isCXX(InputType) && getToolChain().getTriple().isOSDarwin() && @@ -5859,7 +5859,8 @@ static EHFlags parseClangCLEHFlags(const return EH; } -void Clang::AddClangCLArgs(const ArgList &Args, ArgStringList &CmdArgs, +void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType, + ArgStringList &CmdArgs, codegenoptions::DebugInfoKind *DebugInfoKind, bool *EmitCodeView) const { unsigned RTOptionID = options::OPT__SLASH_MT; @@ -5934,11 +5935,12 @@ void Clang::AddClangCLArgs(const ArgList const Driver &D = getToolChain().getDriver(); EHFlags EH = parseClangCLEHFlags(D, Args); if (EH.Synch || EH.Asynch) { - CmdArgs.push_back("-fcxx-exceptions"); + if (types::isCXX(InputType)) + CmdArgs.push_back("-fcxx-exceptions"); CmdArgs.push_back("-fexceptions"); - if (EH.Synch && EH.NoUnwindC) - CmdArgs.push_back("-fexternc-nounwind"); } + if (types::isCXX(InputType) && EH.Synch && EH.NoUnwindC) + CmdArgs.push_back("-fexternc-nounwind"); // /EP should expand to -E -P. if (Args.hasArg(options::OPT__SLASH_EP)) { Modified: cfe/trunk/lib/Driver/Tools.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.h?rev=262198&r1=262197&r2=262198&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.h (original) +++ cfe/trunk/lib/Driver/Tools.h Sun Feb 28 19:40:36 2016 @@ -91,7 +91,7 @@ private: llvm::opt::ArgStringList &cmdArgs, RewriteKind rewrite) const; - void AddClangCLArgs(const llvm::opt::ArgList &Args, + void AddClangCLArgs(const llvm::opt::ArgList &Args, types::ID InputType, llvm::opt::ArgStringList &CmdArgs, codegenoptions::DebugInfoKind *DebugInfoKind, bool *EmitCodeView) const; Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=262198&r1=262197&r2=262198&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Feb 28 19:40:36 2016 @@ -11635,8 +11635,11 @@ void Sema::AddKnownFunctionAttributes(Fu // throw, add an implicit nothrow attribute to any extern "C" function we come // across. if (getLangOpts().CXXExceptions && getLangOpts().ExternCNoUnwind && - FD->isExternC() && !FD->hasAttr<NoThrowAttr>()) - FD->addAttr(NoThrowAttr::CreateImplicit(Context, FD->getLocation())); + FD->isExternC() && !FD->hasAttr<NoThrowAttr>()) { + const auto *FPT = FD->getType()->getAs<FunctionProtoType>(); + if (!FPT || FPT->getExceptionSpecType() == EST_None) + FD->addAttr(NoThrowAttr::CreateImplicit(Context, FD->getLocation())); + } IdentifierInfo *Name = FD->getIdentifier(); if (!Name) Modified: cfe/trunk/test/CodeGenCXX/exceptions-cxx-ehsc.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/exceptions-cxx-ehsc.cpp?rev=262198&r1=262197&r2=262198&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/exceptions-cxx-ehsc.cpp (original) +++ cfe/trunk/test/CodeGenCXX/exceptions-cxx-ehsc.cpp Sun Feb 28 19:40:36 2016 @@ -14,3 +14,18 @@ void caller() { // CHECK-LABEL: define void @"\01?caller@test1@@YAXXZ"( // CHECK: call void @never_throws( // CHECK: invoke void @"\01?may_throw@test1@@YAXXZ"( + +namespace test2 { +struct Cleanup { ~Cleanup(); }; +extern "C" void throws_int() throw(int); +void may_throw(); + +void caller() { + Cleanup x; + throws_int(); + may_throw(); +} +} +// CHECK-LABEL: define void @"\01?caller@test2@@YAXXZ"( +// CHECK: invoke void @throws_int( +// CHECK: invoke void @"\01?may_throw@test2@@YAXXZ"( Modified: cfe/trunk/test/Driver/cl-options.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=262198&r1=262197&r2=262198&view=diff ============================================================================== --- cfe/trunk/test/Driver/cl-options.c (original) +++ cfe/trunk/test/Driver/cl-options.c Sun Feb 28 19:40:36 2016 @@ -211,13 +211,13 @@ // RUN: %clang_cl /FI asdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI_ %s // FI_: "-include" "asdf.h" -// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=NO-GX %s +// RUN: %clang_cl /TP /c -### -- %s 2>&1 | FileCheck -check-prefix=NO-GX %s // NO-GX-NOT: "-fcxx-exceptions" "-fexceptions" -// RUN: %clang_cl /c /GX -### -- %s 2>&1 | FileCheck -check-prefix=GX %s +// RUN: %clang_cl /TP /c /GX -### -- %s 2>&1 | FileCheck -check-prefix=GX %s // GX: "-fcxx-exceptions" "-fexceptions" -// RUN: %clang_cl /c /GX /GX- -### -- %s 2>&1 | FileCheck -check-prefix=GX_ %s +// RUN: %clang_cl /TP /c /GX /GX- -### -- %s 2>&1 | FileCheck -check-prefix=GX_ %s // GX_-NOT: "-fcxx-exceptions" "-fexceptions" // We forward any unrecognized -W diagnostic options to cc1. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits