<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 3, 2012, at 11:16 AM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On Oct 2, 2012, at 2:09 AM, Axel Naumann <<a href="mailto:Axel.Naumann@cern.ch">Axel.Naumann@cern.ch</a>> wrote:<br><br><blockquote type="cite">Author: axel<br>Date: Tue Oct  2 04:09:43 2012<br>New Revision: 164993<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=164993&view=rev">http://llvm.org/viewvc/llvm-project?rev=164993&view=rev</a><br>Log:<br>Merge pending instantiations instead of overwriting existing ones.<br>Check whether a pending instantiation needs to be instantiated (or whether an instantiation already exists).<br>Verify the size of the PendingInstantiations record (was only checking size of existing PendingInstantiations).<br></blockquote><blockquote type="cite"><font color="#0f61c8">[snip]</font><br>Modified: cfe/trunk/lib/Serialization/ASTReader.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=164993&r1=164992&r2=164993&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=164993&r1=164992&r2=164993&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)<br>+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Oct  2 04:09:43 2012<br>@@ -2223,13 +2223,15 @@<br><br>    case PENDING_IMPLICIT_INSTANTIATIONS:<br>      if (PendingInstantiations.size() % 2 != 0) {<br>+        Error("Invalid existing PendingInstantiations");<br>+        return Failure;<br>+      }<br>+<br>+      if (Record.size() % 2 != 0) {<br>        Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block");<br>        return Failure;<br>      }<br>-        <br>-      // Later lists of pending instantiations overwrite earlier ones.<br>-      // FIXME: This is most certainly wrong for modules.<br>-      PendingInstantiations.clear();<br>+<br>      for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {<br>        PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++]));<br>        PendingInstantiations.push_back(<br>@@ -5592,7 +5594,11 @@<br>    ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++]));<br>    SourceLocation Loc<br>      = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]);<br>-    Pending.push_back(std::make_pair(D, Loc));<br>+<br>+    // For modules, find out whether an instantiation already exists<br>+    if (!getContext().getLangOpts().Modules<br>+        || needPendingInstantiation(D))<br>+      Pending.push_back(std::make_pair(D, Loc));<br>  }  <br>  PendingInstantiations.clear();<br>}<br></blockquote><br>Why do we even bother with needPendingInstantiation()? Extra pending instantiations don't actually do any harm, because the instantiation routines that Sema::PerformPendingInstantiations delegates to---InstantiateFunctionDefinition and InstantiateStaticDataMemberDefinition---already know how to return early if the thing they are supposed to instantiate already has a definition. So we're doing a bunch of work up front in the ASTReader to save us from a cheap check in Sema.<br><br>FWIW, all tests pass if needPendingInstantiation(D) here always returns true. If you have other code that the call to needPendingInstantiation() fixes, it's a symptom of a different problem.<br></div></blockquote><div><br></div><div>I ended up reverting the needPendingInstantiation() in r165139. For future non-trivial commits that affect modules, please send a patch rather than relying on post-commit review. Modules are a fairly complicated feature with a lot of interactions with the AST and Sema, and we need to be sure we're building things correctly.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>- Doug</div></div></body></html>