[cfe-commits] r161008 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/destructor-exception-spec.cpp

Richard Smith richard-llvm at metafoo.co.uk
Mon Jul 30 16:48:14 PDT 2012


Author: rsmith
Date: Mon Jul 30 18:48:14 2012
New Revision: 161008

URL: http://llvm.org/viewvc/llvm-project?rev=161008&view=rev
Log:
PR13479: If we see the definition of an out-of-line destructor in C++11, be
sure to update the exception specification on the declaration as well as the
definition. If we're building in -fno-exceptions mode, nothing else will
trigger it to be updated.

Added:
    cfe/trunk/test/CodeGenCXX/destructor-exception-spec.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=161008&r1=161007&r2=161008&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Jul 30 18:48:14 2012
@@ -4007,19 +4007,37 @@
   llvm_unreachable("only special members have implicit exception specs");
 }
 
+static void
+updateExceptionSpec(Sema &S, FunctionDecl *FD, const FunctionProtoType *FPT,
+                    const Sema::ImplicitExceptionSpecification &ExceptSpec) {
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  ExceptSpec.getEPI(EPI);
+  const FunctionProtoType *NewFPT = cast<FunctionProtoType>(
+    S.Context.getFunctionType(FPT->getResultType(), FPT->arg_type_begin(),
+                              FPT->getNumArgs(), EPI));
+  FD->setType(QualType(NewFPT, 0));
+}
+
 void Sema::EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD) {
   const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
   if (FPT->getExceptionSpecType() != EST_Unevaluated)
     return;
 
-  // Evaluate the exception specification and update the type of the special
-  // member to use it.
-  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
-  computeImplicitExceptionSpec(*this, Loc, MD).getEPI(EPI);
-  const FunctionProtoType *NewFPT = cast<FunctionProtoType>(
-    Context.getFunctionType(FPT->getResultType(), FPT->arg_type_begin(),
-                            FPT->getNumArgs(), EPI));
-  MD->setType(QualType(NewFPT, 0));
+  // Evaluate the exception specification.
+  ImplicitExceptionSpecification ExceptSpec =
+      computeImplicitExceptionSpec(*this, Loc, MD);
+
+  // Update the type of the special member to use it.
+  updateExceptionSpec(*this, MD, FPT, ExceptSpec);
+
+  // A user-provided destructor can be defined outside the class. When that
+  // happens, be sure to update the exception specification on both
+  // declarations.
+  const FunctionProtoType *CanonicalFPT =
+    MD->getCanonicalDecl()->getType()->castAs<FunctionProtoType>();
+  if (CanonicalFPT->getExceptionSpecType() == EST_Unevaluated)
+    updateExceptionSpec(*this, MD->getCanonicalDecl(),
+                        CanonicalFPT, ExceptSpec);
 }
 
 static bool isImplicitCopyCtorArgConst(Sema &S, CXXRecordDecl *ClassDecl);

Added: cfe/trunk/test/CodeGenCXX/destructor-exception-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructor-exception-spec.cpp?rev=161008&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructor-exception-spec.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/destructor-exception-spec.cpp Mon Jul 30 18:48:14 2012
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -emit-llvm-only %s -std=c++11
+
+// PR13479: don't crash with -fno-exceptions.
+namespace {
+  struct SchedulePostRATDList {
+    virtual ~SchedulePostRATDList();
+  };
+
+  SchedulePostRATDList::~SchedulePostRATDList() {}
+
+  SchedulePostRATDList Scheduler;
+}





More information about the cfe-commits mailing list