[cfe-commits] r127685 - in /cfe/trunk: lib/CodeGen/CGException.cpp test/CXX/except/except.spec/p9-dynamic.cpp test/CXX/except/except.spec/p9-noexcept.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Tue Mar 15 11:42:48 PDT 2011


Author: cornedbee
Date: Tue Mar 15 13:42:48 2011
New Revision: 127685

URL: http://llvm.org/viewvc/llvm-project?rev=127685&view=rev
Log:
Reintroduce r127617: "Code generation for noexcept." with fixes.

Added:
    cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp
    cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGException.cpp

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=127685&r1=127684&r2=127685&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Tue Mar 15 13:42:48 2011
@@ -449,19 +449,23 @@
   if (Proto == 0)
     return;
 
-  // FIXME: What about noexcept?
-  if (!Proto->hasDynamicExceptionSpec())
-    return;
-
-  unsigned NumExceptions = Proto->getNumExceptions();
-  EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
-
-  for (unsigned I = 0; I != NumExceptions; ++I) {
-    QualType Ty = Proto->getExceptionType(I);
-    QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType();
-    llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType,
-                                                      /*ForEH=*/true);
-    Filter->setFilter(I, EHType);
+  ExceptionSpecificationType EST = Proto->getExceptionSpecType();
+  if (isNoexceptExceptionSpec(EST)) {
+    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);
+
+    for (unsigned I = 0; I != NumExceptions; ++I) {
+      QualType Ty = Proto->getExceptionType(I);
+      QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType();
+      llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType,
+                                                        /*ForEH=*/true);
+      Filter->setFilter(I, EHType);
+    }
   }
 }
 
@@ -476,10 +480,14 @@
   if (Proto == 0)
     return;
 
-  if (!Proto->hasDynamicExceptionSpec())
-    return;
-
-  EHStack.popFilter();
+  ExceptionSpecificationType EST = Proto->getExceptionSpecType();
+  if (isNoexceptExceptionSpec(EST)) {
+    if (Proto->getNoexceptSpec(getContext()) == FunctionProtoType::NR_Nothrow) {
+      EHStack.popTerminate();
+    }
+  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+    EHStack.popFilter();
+  }
 }
 
 void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {

Added: cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp?rev=127685&view=auto
==============================================================================
--- cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp (added)
+++ cfe/trunk/test/CXX/except/except.spec/p9-dynamic.cpp Tue Mar 15 13:42:48 2011
@@ -0,0 +1,11 @@
+// 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: call i32 (i8*, i8*, ...)* @llvm.eh.selector({{.*}} i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind
+// CHECK: call void @__cxa_call_unexpected

Added: cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp?rev=127685&view=auto
==============================================================================
--- cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp (added)
+++ cfe/trunk/test/CXX/except/except.spec/p9-noexcept.cpp Tue Mar 15 13:42:48 2011
@@ -0,0 +1,18 @@
+// 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:  call i32 (i8*, i8*, ...)* @llvm.eh.selector({{.*}} i8* null) nounwind
+// CHECK-NEXT: call void @_ZSt9terminatev() noreturn nounwind
+// CHECK-NEXT: unreachable
+
+void reverse() noexcept(false)
+{
+  // CHECK: call void @_Z8externalv()
+  external();
+}





More information about the cfe-commits mailing list