r231738 - PR21687: when adding a redeclaration of a function with an implicit exception

Richard Smith richard-llvm at metafoo.co.uk
Mon Mar 9 19:00:54 PDT 2015


Author: rsmith
Date: Mon Mar  9 21:00:53 2015
New Revision: 231738

URL: http://llvm.org/viewvc/llvm-project?rev=231738&view=rev
Log:
PR21687: when adding a redeclaration of a function with an implicit exception
specification, update all prior declarations if the new one has an explicit
exception specification and the prior ones don't.

Patch by Vassil Vassilev! Some minor tweaking and test case by me.

Added:
    cfe/trunk/test/Modules/Inputs/PR21687/
    cfe/trunk/test/Modules/Inputs/PR21687/a.h
    cfe/trunk/test/Modules/Inputs/PR21687/b.h
    cfe/trunk/test/Modules/Inputs/PR21687/c.h
    cfe/trunk/test/Modules/Inputs/PR21687/module.modulemap
    cfe/trunk/test/Modules/pr21687.cpp
Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=231738&r1=231737&r2=231738&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Mar  9 21:00:53 2015
@@ -2833,14 +2833,23 @@ void ASTDeclReader::attachPreviousDeclIm
 
   // If this declaration has an unresolved exception specification but the
   // previous declaration had a resolved one, resolve the exception
-  // specification now.
+  // specification now. If this declaration has a resolved exception
+  // specification but the previous declarations did not, apply our exception
+  // specification to all prior ones now.
   auto *FPT = FD->getType()->getAs<FunctionProtoType>();
   auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>();
-  if (FPT && PrevFPT &&
-      isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
-      !isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType())) {
-    Reader.Context.adjustExceptionSpec(
-        FD, PrevFPT->getExtProtoInfo().ExceptionSpec);
+  if (FPT && PrevFPT) {
+    bool WasUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType());
+    bool IsUnresolved = isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType());
+    if (WasUnresolved && !IsUnresolved) {
+      Reader.Context.adjustExceptionSpec(
+          FD, PrevFPT->getExtProtoInfo().ExceptionSpec);
+    } else if (!WasUnresolved && IsUnresolved) {
+      FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+      for (FunctionDecl *PrevFDToUpdate = PrevFD; PrevFDToUpdate;
+           PrevFDToUpdate = PrevFDToUpdate->getPreviousDecl())
+         Reader.Context.adjustExceptionSpec(PrevFDToUpdate, EPI.ExceptionSpec);
+    }
   }
 }
 }

Added: cfe/trunk/test/Modules/Inputs/PR21687/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR21687/a.h?rev=231738&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR21687/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR21687/a.h Mon Mar  9 21:00:53 2015
@@ -0,0 +1 @@
+struct X { X(); virtual ~X(); };

Added: cfe/trunk/test/Modules/Inputs/PR21687/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR21687/b.h?rev=231738&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR21687/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR21687/b.h Mon Mar  9 21:00:53 2015
@@ -0,0 +1,2 @@
+#include "a.h"
+X *n = new X;

Added: cfe/trunk/test/Modules/Inputs/PR21687/c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR21687/c.h?rev=231738&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR21687/c.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR21687/c.h Mon Mar  9 21:00:53 2015
@@ -0,0 +1,4 @@
+#include "a.h"
+inline void f() { X x, y(x); }
+#include "b.h"
+X x, y(x);

Added: cfe/trunk/test/Modules/Inputs/PR21687/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR21687/module.modulemap?rev=231738&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR21687/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/PR21687/module.modulemap Mon Mar  9 21:00:53 2015
@@ -0,0 +1,3 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
+module c { header "c.h" export * }

Added: cfe/trunk/test/Modules/pr21687.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/pr21687.cpp?rev=231738&view=auto
==============================================================================
--- cfe/trunk/test/Modules/pr21687.cpp (added)
+++ cfe/trunk/test/Modules/pr21687.cpp Mon Mar  9 21:00:53 2015
@@ -0,0 +1,3 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/PR21687 -emit-llvm-only %s
+#include "c.h"





More information about the cfe-commits mailing list