Switch to using -fsjlj-exceptions instead of hard-coding it. Notably, this fixes

calls to the UnwindResumeOrRethrow function for C++/Obj-C exception handling,
for Darwin ARM.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95787 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2010-02-10 18:49:11 +00:00
Родитель 809b9bb733
Коммит b2987d159a
9 изменённых файлов: 33 добавлений и 9 удалений

Просмотреть файл

@ -123,6 +123,9 @@ public:
/// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
/// compile unit information. /// compile unit information.
virtual bool UseDwarfDebugFlags() const { return false; } virtual bool UseDwarfDebugFlags() const { return false; }
/// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
virtual bool UseSjLjExceptions() const { return false; };
}; };
} // end namespace driver } // end namespace driver

Просмотреть файл

@ -1385,9 +1385,6 @@ public:
// when Neon instructions are actually available. // when Neon instructions are actually available.
if (FPU == NeonFPU && !SoftFloat && IsThumb2) if (FPU == NeonFPU && !SoftFloat && IsThumb2)
Builder.defineMacro("__ARM_NEON__"); Builder.defineMacro("__ARM_NEON__");
if (getTriple().getOS() == llvm::Triple::Darwin)
Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
} }
virtual void getTargetBuiltins(const Builtin::Info *&Records, virtual void getTargetBuiltins(const Builtin::Info *&Records,
unsigned &NumRecords) const { unsigned &NumRecords) const {

Просмотреть файл

@ -100,10 +100,6 @@ static llvm::Constant *getUnexpectedFn(CodeGenFunction &CGF) {
return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_call_unexpected"); return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_call_unexpected");
} }
// FIXME: Eventually this will all go into the backend. Set from the target for
// now.
static int using_sjlj_exceptions = 0;
static llvm::Constant *getUnwindResumeOrRethrowFn(CodeGenFunction &CGF) { static llvm::Constant *getUnwindResumeOrRethrowFn(CodeGenFunction &CGF) {
const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGF.getLLVMContext()); const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
std::vector<const llvm::Type*> Args(1, Int8PtrTy); std::vector<const llvm::Type*> Args(1, Int8PtrTy);
@ -112,7 +108,7 @@ static llvm::Constant *getUnwindResumeOrRethrowFn(CodeGenFunction &CGF) {
llvm::FunctionType::get(llvm::Type::getVoidTy(CGF.getLLVMContext()), Args, llvm::FunctionType::get(llvm::Type::getVoidTy(CGF.getLLVMContext()), Args,
false); false);
if (using_sjlj_exceptions) if (CGF.CGM.getLangOptions().SjLjExceptions)
return CGF.CGM.CreateRuntimeFunction(FTy, "_Unwind_SjLj_Resume"); return CGF.CGM.CreateRuntimeFunction(FTy, "_Unwind_SjLj_Resume");
return CGF.CGM.CreateRuntimeFunction(FTy, "_Unwind_Resume_or_Rethrow"); return CGF.CGM.CreateRuntimeFunction(FTy, "_Unwind_Resume_or_Rethrow");
} }

Просмотреть файл

@ -738,7 +738,8 @@ public:
return CGM.CreateRuntimeFunction( return CGM.CreateRuntimeFunction(
llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
Params, false), Params, false),
"_Unwind_Resume_or_Rethrow"); (CGM.getLangOptions().SjLjExceptions ? "_Unwind_SjLj_Resume" :
"_Unwind_Resume_or_Rethrow"));
} }
llvm::Constant *getObjCEndCatchFn() { llvm::Constant *getObjCEndCatchFn() {

Просмотреть файл

@ -640,6 +640,12 @@ bool Darwin::UseDwarfDebugFlags() const {
return false; return false;
} }
bool Darwin::UseSjLjExceptions() const {
// Darwin uses SjLj exceptions on ARM.
return (getTriple().getArch() == llvm::Triple::arm ||
getTriple().getArch() == llvm::Triple::thumb);
}
const char *Darwin::GetDefaultRelocationModel() const { const char *Darwin::GetDefaultRelocationModel() const {
return "pic"; return "pic";
} }

Просмотреть файл

@ -176,6 +176,8 @@ public:
virtual bool UseDwarfDebugFlags() const; virtual bool UseDwarfDebugFlags() const;
virtual bool UseSjLjExceptions() const;
/// } /// }
}; };

Просмотреть файл

@ -1004,6 +1004,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (needsExceptions(Args, InputType, getToolChain().getTriple())) if (needsExceptions(Args, InputType, getToolChain().getTriple()))
CmdArgs.push_back("-fexceptions"); CmdArgs.push_back("-fexceptions");
if (getToolChain().UseSjLjExceptions())
CmdArgs.push_back("-fsjlj-exceptions");
// -frtti is default. // -frtti is default.
if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti)) if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti))
CmdArgs.push_back("-fno-rtti"); CmdArgs.push_back("-fno-rtti");

Просмотреть файл

@ -279,6 +279,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
if (LangOpts.Exceptions) if (LangOpts.Exceptions)
Builder.defineMacro("__EXCEPTIONS"); Builder.defineMacro("__EXCEPTIONS");
if (LangOpts.SjLjExceptions)
Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
if (LangOpts.CPlusPlus) { if (LangOpts.CPlusPlus) {
Builder.defineMacro("__DEPRECATED"); Builder.defineMacro("__DEPRECATED");

Просмотреть файл

@ -0,0 +1,14 @@
// RUN: %clang_cc1 -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT_EH %s
// RUN: %clang_cc1 -fsjlj-exceptions -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck --check-prefix=SJLJ_EH %s
// DEFAULT_EH: declare void @_Unwind_Resume_or_Rethrow(i8*)
// SJLJ_EH: declare void @_Unwind_SjLj_Resume(i8*)
void f1(), f2();
void f0() {
@try {
f1();
} @catch (...) {
f2();
}
}