[modules][PATCH] Teach the ASTDeclReader to update the exception specs of the deserialized decl's redecl chain.

Vassil Vassilev vvasilev at cern.ch
Mon Nov 24 11:09:29 PST 2014


Sorry for the delay. Attaching the new version.
Vassil
On 14/11/14 02:47, Richard Smith wrote:
> +    }
> +    else { // FPT->getExceptionSpecType() is resolved and the other 
> is not
>
> You're not checking for this condition; the code here is getting run 
> even if both or neither are unresolved.
>
> The patch needs rebasing (we have a new helper function in ASTContext 
> to update the exception specification of a declaration), but looks 
> like the right direction.
>
> On Thu, Nov 6, 2014 at 4:23 AM, Vassil Vassilev 
> <vasil.georgiev.vasilev at cern.ch 
> <mailto:vasil.georgiev.vasilev at cern.ch>> wrote:
>
>     Hi Richard,
>       I am attaching the patch we discussed at the dev meeting. Still
>     haven't found small reproducer...
>       The issue appears to stem from the fact that module A contains
>     only a forward declaration of a function and it exception spec
>     cannot be computed. In module B is the definition with computed
>     exception spec, which gets deserialized after the one in module A.
>     This patch teaches the ASTDeclReader to update all the exception
>     specs of the previous decls to the current one.
>
>       Could you review, please?
>     Many thanks,
>     Vassil
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141124/ade0251c/attachment.html>
-------------- next part --------------
commit b7209a33ece8c5f426a41d9f2f92c7caa9bba0ae
Author: Vassil Vassilev <vvasilev at cern.ch>
Date:   Mon Nov 24 19:58:23 2014 +0100

    [modules] Update exception specs of the redecl chain when deserializing a module.
    
    The issue appears to stem from the fact that module A contains only a forward
    declaration of a function and it exception spec cannot be computed. In module B
    is the definition with computed exception spec, which gets deserialized after
    the one in module A. This patch teaches the ASTDeclReader to update all the
    exception specs of the previous decls to the current one.
    
    Test case: still didn't manage to reduce it to something that makes sense.

Index: lib/Serialization/ASTReaderDecl.cpp
===================================================================
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -2779,11 +2779,22 @@ void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
   // specification 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(
+  if (FPT && PrevFPT) {
+    if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
+        !isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType())) {
+      Reader.Context.adjustExceptionSpec(
         FD, PrevFPT->getExtProtoInfo().ExceptionSpec);
+    }
+    else if (!isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
+             isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType())) {
+      // Happens in cases where module A contains only a fwd decl and module B
+      // contains the definition.
+      FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+      while (PrevFD) {
+        Reader.Context.adjustExceptionSpec(PrevFD, EPI.ExceptionSpec);
+        PrevFD = PrevFD->getPreviousDecl();
+      }
+    }
   }
 }
 }


More information about the cfe-commits mailing list