Code generation for noexcept.

llvm-svn: 127617
This commit is contained in:
Sebastian Redl 2011-03-14 20:33:20 +00:00
parent cf5e83b471
commit 97022fd325
3 changed files with 55 additions and 16 deletions

View File

@ -449,19 +449,23 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
if (Proto == 0) if (Proto == 0)
return; return;
// FIXME: What about noexcept? ExceptionSpecificationType EST = Proto->getExceptionSpecType();
if (!Proto->hasDynamicExceptionSpec()) if (isNoexceptExceptionSpec(EST)) {
return; if (Proto->getNoexceptSpec(getContext()) == FunctionProtoType::NR_Nothrow) {
// noexcept functions are simple terminate scopes.
EHStack.pushTerminate();
}
} else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
unsigned NumExceptions = Proto->getNumExceptions();
EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
unsigned NumExceptions = Proto->getNumExceptions(); for (unsigned I = 0; I != NumExceptions; ++I) {
EHFilterScope *Filter = EHStack.pushFilter(NumExceptions); QualType Ty = Proto->getExceptionType(I);
QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType();
for (unsigned I = 0; I != NumExceptions; ++I) { llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType,
QualType Ty = Proto->getExceptionType(I); /*ForEH=*/true);
QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType(); Filter->setFilter(I, EHType);
llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType, }
/*ForEH=*/true);
Filter->setFilter(I, EHType);
} }
} }
@ -476,10 +480,14 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
if (Proto == 0) if (Proto == 0)
return; return;
if (!Proto->hasDynamicExceptionSpec()) ExceptionSpecificationType EST = Proto->getExceptionSpecType();
return; if (isNoexceptExceptionSpec(EST)) {
if (Proto->getNoexceptSpec(getContext()) == FunctionProtoType::NR_Nothrow) {
EHStack.popFilter(); EHStack.popTerminate();
}
} else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
EHStack.popFilter();
}
} }
void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) { void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s
void external();
void target() throw(int)
{
// CHECK: invoke void @_Z8externalv()
external();
}
// CHECK: %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 2, i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind
// CHECK: ehspec.unexpected:
// CHECK: call void @__cxa_call_unexpected(i8* %1) noreturn

View File

@ -0,0 +1,19 @@
// RUN: %clang_cc1 %s -std=c++0x -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s
void external();
void target() noexcept
{
// CHECK: invoke void @_Z8externalv()
external();
}
// CHECK: terminate.lpad:
// CHECK: %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) nounwind
// CHECK-NEXT: call void @_ZSt9terminatev() noreturn nounwind
// CHECK-NEXT: unreachable
void reverse() noexcept(false)
{
// CHECK: call void @_Z8externalv()
external();
}