diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 05befe08c12528c7b0d82511e7e53d79cf7c47c0..c55aa17eb2b6a7fe6d8552042ea13ae5f611fcaf 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -362,6 +362,17 @@ LaxVectorConversions("flax-vector-conversions", " with a different number of elements or " "different element types")); +// FIXME: This (and all GCC -f options) really come in -f... and +// -fno-... forms, and additionally support automagic behavior when +// they are not defined. For example, -fexceptions defaults to on or +// off depending on the language. We should support this behavior in +// some form (perhaps just add a facility for distinguishing when an +// has its default value from when it has been set to its default +// value). +static llvm::cl::opt +Exceptions("fexceptions", + llvm::cl::desc("Enable support for exception handling.")); + // FIXME: add: // -ansi // -trigraphs @@ -427,6 +438,7 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK) { Options.Microsoft = MSExtensions; Options.WritableStrings = WritableStrings; Options.LaxVectorConversions = LaxVectorConversions; + Options.Exceptions = Exceptions; } static llvm::cl::opt diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 589153f47ecc82dac62930bcfbd7aa713b903582..7756a2ab5be3b82766f5b253a46d175b8adcaf70 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -42,6 +42,7 @@ struct LangOptions { unsigned Boolean : 1; // Allow bool/true/false unsigned WritableStrings : 1; // Allow writable strings unsigned LaxVectorConversions : 1; + unsigned Exceptions : 1; // Support exception handling. private: unsigned GC : 2; // Objective-C Garbage Collection modes. We declare @@ -57,7 +58,7 @@ public: GC = ObjC1 = ObjC2 = 0; C99 = Microsoft = CPlusPlus = CPlusPlus0x = NoExtensions = 0; CXXOperatorNames = PascalStrings = Boolean = WritableStrings = 0; - LaxVectorConversions = 0; + LaxVectorConversions = Exceptions = 0; } GCMode getGCMode() const { return (GCMode) GC; } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c77dfa6a813391f235c49dbedb015dc0e86cd834..b3e721308d654bbda4a134e943645e76a7c63dde 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -751,6 +751,12 @@ void CodeGenModule::EmitGlobalFunctionDefinition(const FunctionDecl *D) { llvm::Function *Fn = cast(Entry); CodeGenFunction(*this).GenerateCode(D, Fn); + // Set attributes specific to definition. + // FIXME: This needs to be cleaned up by clearly emitting the + // declaration / definition at separate times. + if (!Features.Exceptions) + Fn->addParamAttr(0, llvm::ParamAttr::NoUnwind); + if (const ConstructorAttr *CA = D->getAttr()) { AddGlobalCtor(Fn, CA->getPriority()); } else if (const DestructorAttr *DA = D->getAttr()) {