<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 10, 2015, at 3:46 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Fri, Apr 10, 2015 at 3:28 PM, Ben Langmuir<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><div class=""><div class="h5"><blockquote type="cite" class=""><div class="">On Mar 23, 2015, at 8:20 PM, Ben Langmuir <<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>> wrote:</div><br class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="">On Mar 23, 2015, at 7:52 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank" class="">richard@metafoo.co.uk</a>> wrote:</div><br class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 23, 2015 at 7:36 PM, Ben Langmuir<span class=""> </span><span dir="ltr" class=""><<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 23, 2015, at 5:06 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank" class="">richard@metafoo.co.uk</a>> wrote:</div><br class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 23, 2015 at 5:01 PM, Ben Langmuir<span class=""> </span><span dir="ltr" class=""><<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 23, 2015, at 4:18 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank" class="">richard@metafoo.co.uk</a>> wrote:</div><br class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 23, 2015 at 3:59 PM, Ben Langmuir<span class=""> </span><span dir="ltr" class=""><<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Mar 23, 2015, at 3:43 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank" class="">richard@metafoo.co.uk</a>> wrote:</div><br class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 23, 2015 at 2:41 PM, Ben Langmuir<span class=""> </span><span dir="ltr" class=""><<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Mar 23, 2015, at 1:05 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank" class="">richard@metafoo.co.uk</a>> wrote:</div><br class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Sat, Mar 14, 2015 at 9:25 AM, Ben Langmuir<span class=""> </span><span dir="ltr" class=""><<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Hi Richard,<br class=""><br class="">This commit looks like it caused a regression in PCH-loading performance when the PCH imports modules.  It doesn’t affect performance of loading modules on their own, or of a PCH that doesn’t use modules.  If you have access to a Darwin system, it’s easy to reproduce with:<br class=""><br class="">$ cat t.h<br class="">@import Cocoa;<br class=""><br class="">$ cat t.m<br class="">// empty<br class=""><br class="">$ clang -fmodules -fmodules-cache-path=mcp -x objective-c-header t.h -o t.pch<br class="">$ time clang -fmodules -fmodules-cache-path=mcp -Xclang -include-pch -Xclang t.pch t.m -fsyntax-only<br class=""><br class="">I’m seeing ~8x difference between r228233 and r228234.  In real world code (where the .m file isn’t empty) we’ve seen up to a ~90% difference.<br class=""><br class="">Do you know what’s going on here?</blockquote><div class=""><br class=""></div><div class="">Hmm. I suspect this change causes the lookup table for the translation unit to be built, which in turn pulls in all the lexical contents of the translation unit (because outside of C++ we don't serialize a DeclContext lookup table for the TU, nor even build one usually).</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">When a PCH loads I think we do it without Sema, but (at least previously) queued up the interesting Decls we saw for when Sema was added later.  So I’m surprised this had such a big effect.</blockquote><div class=""><br class=""></div><div class="">If we were loading PCHs without Sema, then I think before this change we would not have merged declarations of the same entity from two independent modules imported into the same PCH.</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Wouldn’t that happen in InitializeSema() when we called pushExternalDeclIntoScope() on the contents of PreloadedDeclIDs?</div></div></div></blockquote><div class=""><br class=""></div><div class="">No; we're talking about the case where a Decl is deserialized before we have a Sema instance. If we never deserialized the Decl from its DeclID before we had a Sema (which I think is what you're suggesting) we'd never have reached the modified code.</div></div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">If we want to support loading Decls without Sema, we need to be able to merge them without Sema. If we don't, then we should find whichever codepath is leading us to do so and fix it. Being able to load a serialized AST without a Sema seems useful to me, in the absence of a good reason why it shouldn't work.</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">I thought PCH intentionally wouldn’t deserialize decls until after we initialized Sema.   Maybe we have a bug (which wouldn’t surprise me), or maybe that wasn’t the intent (which would scare me a bit since then we have some decls showing up immediately and some waiting for sema with no clear split between them).</div><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><span class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">Perhaps we should use a separate side-table for merging in this case outside C++, rather than falling back to DeclContext lookup?</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">I don’t know this code path well enough to say.  What would go into the table (or perhaps more importantly what wouldn’t)?</div></div></div></blockquote><div class=""><br class=""></div><div class="">Any deserialized declarations that should be visible by name lookup in the TU would be in the table. The only difference would be that we'd be more careful to ensure that we never trigger the import of all lexical declarations in the TU in order to build the table.</div><div class=""><br class=""></div><div class="">Are you still seeing this performance problem with Clang trunk? Towards the end of last week I fixed a bug where we would unnecessarily pull in all lexical declarations within the TU when doing certain lookups, which might have fixed this slowdown. (If not, it'd be useful to find out whether that's the problem, and if so, what is causing us to load these declarations.)</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Cool, I’ll give ToT a shot.  I last tried with r232229.</div></div></div></blockquote><div class=""><br class=""></div><div class="">r232928 onwards, or a revision in [232793, 232905), have the change I'm referring to.</div></div></div></div></div></blockquote><div class=""><br class=""></div></div></div><div class="">ToT got faster, but not even close to pre-228234.</div><div class=""><br class=""></div><div class="">r228233: 0.0574 s <== “before”</div><div class="">r228234: 0.4433 s <== “after"</div><div class="">r232229: 0.4028 s</div><div class="">r233028: 0.3097 s <== ToT</div></div></div></blockquote><div class=""><br class=""></div><div class="">Where's ToT spending its time?</div></div></div></div></div></blockquote><div class=""><br class=""></div></div></div><div class="">Suspiciously it’s coming from LoadLexicalDeclsFromExternalStorage inside **noload_lookup**…</div></div></div></blockquote><div class=""><br class=""></div><div class="">Aha, thanks! Should be fixed in r233046, let me know if there are still problems.</div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Excellent, thanks for the fix!  I’ve verified we’re back to the pre-228234 performance.</div></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div></div></div><div class="">Hey Richard,</div><div class=""><br class=""></div><div class="">Sorry to drag this back up, but apparently I didn’t verify it carefully enough.  Your commit fixed the regression for initially loading the PCH, but it’s still slow if you actually do any lookups into the ASTReader.  If I add:</div><div class=""><br class=""></div><div class="">void foo() {</div><div class="">}</div><div class=""><br class=""></div><div class="">to my test .m file, which means we try to lookup ‘foo’ in the ASTReader, clang is still slow (3-5 seconds with -fsyntax-only).  The trace is:</div><div class=""><br class=""></div><div class=""><div class="">Running Time<span style="white-space: pre-wrap;" class="">    </span>Self (ms)<span style="white-space: pre-wrap;" class="">          </span>Symbol Name</div><div class="">3202.0ms   98.6%<span style="white-space: pre-wrap;" class=""> </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>             clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Declarator&)</div><div class="">3202.0ms   98.6%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>             <span class="Apple-converted-space"> </span>clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>)</div><div class="">3202.0ms   98.6%<span style="white-space: pre-wrap;" class="">      </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>               clang::Sema::PushOnScopeChains(clang::NamedDecl*, clang::Scope*, bool)</div><div class="">3202.0ms   98.6%<span style="white-space: pre-wrap;" class="">        </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>               <span class="Apple-converted-space"> </span>clang::DeclContext::makeDeclVisibleInContextWithFlags(clang::NamedDecl*, bool, bool)</div><div class="">3202.0ms   98.6%<span style="white-space: pre-wrap;" class="">   </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                 clang::DeclContext::buildLookup()</div><div class="">3199.0ms   98.5%<span style="white-space: pre-wrap;" class="">      </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                 <span class="Apple-converted-space"> </span>clang::DeclContext::LoadLexicalDeclsFromExternalStorage() const</div><div class="">3004.0ms   92.5%<span style="white-space: pre-wrap;" class=""> </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                   clang::ASTReader::FinishedDeserializing()</div><div class="">3004.0ms   92.5%<span style="white-space: pre-wrap;" class="">       </span>1.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                   <span class="Apple-converted-space"> </span>clang::ASTReader::finishPendingActions()</div><div class="">2955.0ms   91.0%<span style="white-space: pre-wrap;" class=""> </span>3.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                     clang::ASTReader::pushExternalDeclIntoScope(clang::NamedDecl*, clang::DeclarationName)</div><div class="">2942.0ms   90.6%<span style="white-space: pre-wrap;" class="">   </span>1721.0<span style="white-space: pre-wrap;" class="">     </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                     <span class="Apple-converted-space"> </span>llvm::MapVector<clang::IdentifierInfo*, llvm::SmallVector<clang::NamedDecl*, 2u>, llvm::SmallDenseMap<clang::IdentifierInfo*, unsigned int, 16u, llvm::DenseMapInfo<clang::IdentifierInfo*>, llvm::detail::DenseMapPair<clang::IdentifierInfo*, unsigned int> >, llvm::SmallVector<std::__1::pair<clang::IdentifierInfo*, llvm::SmallVector<clang::NamedDecl*, 2u> >, 16u> >::erase(std::__1::pair<clang::IdentifierInfo*, llvm::SmallVector<clang::NamedDecl*, 2u> >*)</div><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">Most of this is because MapVector::erase is O(n), so as a workaround I switched to clear() ing the contained SmallVector in r234655.  But I think there’s a more fundamental issue here, because even with that improvement the whole compile still takes 0.25 - 0.5 seconds, rather than the 0.02 seconds it takes without PCH, or without Modules (ie. only the combination of both is slow).  The trace after removing the MapVector::erase is:</div><div class=""><br class=""></div><div class=""><div class="">Running Time<span style="white-space: pre-wrap;" class=""> </span>Self (ms)<span style="white-space: pre-wrap;" class="">          </span>Symbol Name</div><div class="">246.0ms   84.2%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>             clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Declarator&)</div><div class="">246.0ms   84.2%<span style="white-space: pre-wrap;" class="">   </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>             <span class="Apple-converted-space"> </span>clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>)</div><div class="">245.0ms   83.9%<span style="white-space: pre-wrap;" class="">       </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>               clang::Sema::PushOnScopeChains(clang::NamedDecl*, clang::Scope*, bool)</div><div class="">245.0ms   83.9%<span style="white-space: pre-wrap;" class=""> </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>               <span class="Apple-converted-space"> </span>clang::DeclContext::makeDeclVisibleInContextWithFlags(clang::NamedDecl*, bool, bool)</div><div class="">245.0ms   83.9%<span style="white-space: pre-wrap;" class="">    </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                 clang::DeclContext::buildLookup()</div><div class="">242.0ms   82.8%<span style="white-space: pre-wrap;" class="">       </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                 <span class="Apple-converted-space"> </span>clang::DeclContext::LoadLexicalDeclsFromExternalStorage() const</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">This shouldn't be happening; I think makeDeclVisibleInContextWithFlags is too eager to build the lookup table for a DeclContext. Can you try removing the 'hasExternalVisibleStorage() ||' from it?</div></div></div></div></div></blockquote><div><br class=""></div><div>Didn’t have any noticeable affect. </div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><div class=""><div class="">189.0ms   64.7%<span style="white-space: pre-wrap;" class="">    </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                   non-virtual thunk to clang::ASTReader::FindExternalLexicalDecls(clang::DeclContext const*, bool (*)(clang::Decl::Kind), llvm::SmallVectorImpl<clang::Decl*>&)</div><div class="">189.0ms   64.7%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                   <span class="Apple-converted-space"> </span>clang::serialization::ModuleManager::visitDepthFirst(bool (*)(clang::serialization::ModuleFile&, bool, void*), void*)</div><div class="">189.0ms   64.7%<span style="white-space: pre-wrap;" class=""> </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                     visitDepthFirst(clang::serialization::ModuleFile&, bool (*)(clang::serialization::ModuleFile&, bool, void*), void*, llvm::SmallVectorImpl<bool>&)</div><div class="">189.0ms   64.7%<span style="white-space: pre-wrap;" class="">       </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                     <span class="Apple-converted-space"> </span>visitDepthFirst(clang::serialization::ModuleFile&, bool (*)(clang::serialization::ModuleFile&, bool, void*), void*, llvm::SmallVectorImpl<bool>&)</div><div class="">189.0ms   64.7%<span style="white-space: pre-wrap;" class="">        </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                       visitDepthFirst(clang::serialization::ModuleFile&, bool (*)(clang::serialization::ModuleFile&, bool, void*), void*, llvm::SmallVectorImpl<bool>&)</div><div class="">170.0ms   58.2%<span style="white-space: pre-wrap;" class="">        </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                       <span class="Apple-converted-space"> </span>visitDepthFirst(clang::serialization::ModuleFile&, bool (*)(clang::serialization::ModuleFile&, bool, void*), void*, llvm::SmallVectorImpl<bool>&)</div><div class="">98.0ms   33.5%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                         visitDepthFirst(clang::serialization::ModuleFile&, bool (*)(clang::serialization::ModuleFile&, bool, void*), void*, llvm::SmallVectorImpl<bool>&)</div><div class="">71.0ms   24.3%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                         <span class="Apple-converted-space"> </span>(anonymous namespace)::FindExternalLexicalDeclsVisitor::visit(clang::serialization::ModuleFile&, bool, void*)</div><div class="">27.0ms    9.2%<span style="white-space: pre-wrap;" class="">        </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                         <span class="Apple-converted-space"> </span>visitDepthFirst(clang::serialization::ModuleFile&, bool (*)(clang::serialization::ModuleFile&, bool, void*), void*, llvm::SmallVectorImpl<bool>&)</div><div class="">72.0ms   24.6%<span style="white-space: pre-wrap;" class="">   </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                         (anonymous namespace)::FindExternalLexicalDeclsVisitor::visit(clang::serialization::ModuleFile&, bool, void*)</div><div class="">19.0ms    6.5%<span style="white-space: pre-wrap;" class="">       </span>1.0<span style="white-space: pre-wrap;" class="">        </span><span class="Apple-converted-space"> </span><span style="white-space: pre-wrap;" class="">    </span><span class="Apple-converted-space"> </span>                       <span class="Apple-converted-space"> </span>(anonymous namespace)::FindExternalLexicalDeclsVisitor::visit(clang::serialization::ModuleFile&, bool, void*)</div><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">We still seem to be eagerly loading something that we shouldn’t.  -print-stats gives:</div><div class=""><br class=""></div><div class="">*** AST File Statistics:<br class="">  28/96751 source location entries read (0.028940%)<br class="">  24388/29520 types read (82.615181%)<br class="">  64783/142552 declarations read (45.445171%)<br class="">  29024/90665 identifiers read (32.012352%)<br class="">  1527/19301 macros read (7.911507%)<br class="">  0/10332 selectors read (0.000000%)<br class="">  204/49951 statements read (0.408400%)<br class="">  1527/19301 macros read (7.911507%)<br class="">  1/6984 lexical declcontexts read (0.014318%)<br class="">  0/5973 visible declcontexts read (0.000000%)<br class="">  0/9318 method pool entries read (0.000000%)<br class="">  24171 / 52370 identifier table lookups succeeded (46.154287%)</div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Ben</div></font></span><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><div class="">are we setting <span style="font-family: Menlo;" class="">hasExternalVisibleStorage incorrectly?</span></div><div class=""><br class=""></div><div class=""><div class="">Running Time<span style="white-space: pre-wrap;" class="">        </span>Self<span style="white-space: pre-wrap;" class="">               </span>Symbol Name</div><div class="">341.0ms   97.1%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span> <span class=""> </span>cc1_main(llvm::ArrayRef<char const*>, char const*, void*)</div><div class="">340.0ms   96.8%<span style="white-space: pre-wrap;" class="">    </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>   clang::ExecuteCompilerInvocation(clang::CompilerInstance*)</div><div class="">340.0ms   96.8%<span style="white-space: pre-wrap;" class="">    </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>   <span class=""> </span>clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)</div><div class="">336.0ms   95.7%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>     clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, clang::FrontendInputFile const&)</div><div class="">335.0ms   95.4%<span style="white-space: pre-wrap;" class="">      </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>     <span class=""> </span>clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, bool, bool, void*, bool)</div><div class="">335.0ms   95.4%<span style="white-space: pre-wrap;" class="">        </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>       clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, bool, clang::Preprocessor&, clang::ASTContext&, void*, bool, bool, bool)</div><div class="">335.0ms   95.4%<span style="white-space: pre-wrap;" class=""> </span>1.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>       <span class=""> </span>clang::ASTReader::ReadAST(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, clang::serialization::ModuleKind, clang::SourceLocation, unsigned int)</div><div class="">248.0ms   70.6%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>         clang::ASTReader::InitializeContext()</div><div class="">247.0ms   70.3%<span style="white-space: pre-wrap;" class="">    </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>         <span class=""> </span>clang::ASTReader::GetType(unsigned int)</div><div class="">247.0ms   70.3%<span style="white-space: pre-wrap;" class="">        </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>           clang::ASTReader::readTypeRecord(unsigned int)</div><div class="">247.0ms   70.3%<span style="white-space: pre-wrap;" class="">    </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>           <span class=""> </span>clang::ASTReader::ReadDeclRecord(unsigned int)</div><div class="">247.0ms   70.3%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>             clang::ASTDeclReader::Visit(clang::Decl*)</div><div class="">247.0ms   70.3%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>             <span class=""> </span>clang::declvisitor::Base<clang::declvisitor::make_ptr, clang::ASTDeclReader, void>::Visit(clang::Decl*)</div><div class="">247.0ms   70.3%<span style="white-space: pre-wrap;" class="">    </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>               clang::ASTDeclReader::VisitTypedefNameDecl(clang::TypedefNameDecl*)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class=""> </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>               <span class=""> </span>clang::ASTReader::GetTypeSourceInfo(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">        </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                 clang::ASTReader::GetType(unsigned int)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">      </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                 <span class=""> </span>clang::ASTReader::readTypeRecord(unsigned int)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">     </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                   clang::ASTReader::GetType(unsigned int)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">       </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                   <span class=""> </span>clang::ASTReader::readTypeRecord(unsigned int)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">      </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                     clang::ASTReader::ReadDeclRecord(unsigned int)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class=""> </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                     <span class=""> </span>clang::ASTDeclReader::Visit(clang::Decl*)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">    </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                       clang::declvisitor::Base<clang::declvisitor::make_ptr, clang::ASTDeclReader, void>::Visit(clang::Decl*)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">   </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                       <span class=""> </span>clang::ASTDeclReader::VisitTagDecl(clang::TagDecl*)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">   </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                         void clang::ASTDeclReader::mergeRedeclarable<clang::TagDecl>(clang::Redeclarable<clang::TagDecl>*, clang::ASTDeclReader::RedeclarableResult&, unsigned int)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">      </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                         <span class=""> </span>clang::ASTDeclReader::findExisting(clang::NamedDecl*)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">  </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                           clang::DeclContext::noload_lookup(clang::DeclarationName)</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class=""> </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                           <span class=""> </span>clang::DeclContext::lookup(clang::DeclarationName) const</div><div class="">246.0ms   70.0%<span style="white-space: pre-wrap;" class="">        </span>0.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                             clang::DeclContext::buildLookup()</div><div class="">242.0ms   68.9%<span style="white-space: pre-wrap;" class="">  </span>1.0<span style="white-space: pre-wrap;" class="">        </span><span class=""> </span><span style="white-space: pre-wrap;" class=""> </span><span class=""> </span>                             <span class=""> </span>clang::DeclContext::LoadLexicalDeclsFromExternalStorage() const</div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><span class=""><font color="#888888" class=""><div class="">Ben</div></font></span><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><span class=""><font color="#888888" class="">Ben<br class=""></font></span><div class=""><div class=""><br class="">> On Feb 4, 2015, at 3:37 PM, Richard Smith <<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank" class="">richard-llvm@metafoo.co.uk</a>> wrote:<br class="">><br class="">> Author: rsmith<br class="">> Date: Wed Feb  4 17:37:59 2015<br class="">> New Revision: 228234<br class="">><br class="">> URL:<span class=""> </span><a href="http://llvm.org/viewvc/llvm-project?rev=228234&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=228234&view=rev</a><br class="">> Log:<br class="">> [modules] When using -E, we may try to merge decls despite having no Sema<br class="">> object. In such a case, use the TU's DC for merging global decls rather than<br class="">> giving up when we find there is no TU scope.<br class="">><br class="">> Ultimately, we should probably avoid all loading of decls when preprocessing,<br class="">> but there are other reasonable use cases for loading an AST file with no Sema<br class="">> object for which this is the right thing.<br class="">><br class="">> Added:<br class="">>    cfe/trunk/test/Modules/Inputs/preprocess/<br class="">>    cfe/trunk/test/Modules/Inputs/preprocess/file.h<br class="">>    cfe/trunk/test/Modules/Inputs/preprocess/fwd.h<br class="">>    cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap<br class="">> Modified:<br class="">>    cfe/trunk/include/clang/Frontend/CompilerInstance.h<br class="">>    cfe/trunk/lib/Frontend/CompilerInstance.cpp<br class="">>    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp<br class="">>    cfe/trunk/test/Modules/preprocess.m<br class="">><br class="">> Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h<br class="">> URL:<span class=""> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=228234&r1=228233&r2=228234&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=228234&r1=228233&r2=228234&view=diff</a><br class="">> ==============================================================================<br class="">> --- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)<br class="">> +++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Wed Feb  4 17:37:59 2015<br class="">> @@ -588,7 +588,7 @@ public:<br class="">>   /// Create an external AST source to read a PCH file.<br class="">>   ///<br class="">>   /// \return - The new object on success, or null on failure.<br class="">> -  static ExternalASTSource *createPCHExternalASTSource(<br class="">> +  static IntrusiveRefCntPtr<ASTReader> createPCHExternalASTSource(<br class="">>       StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,<br class="">>       bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,<br class="">>       void *DeserializationListener, bool OwnDeserializationListener,<br class="">><br class="">> Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp<br class="">> URL:<span class=""> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=228234&r1=228233&r2=228234&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=228234&r1=228233&r2=228234&view=diff</a><br class="">> ==============================================================================<br class="">> --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)<br class="">> +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Feb  4 17:37:59 2015<br class="">> @@ -388,32 +388,30 @@ void CompilerInstance::createASTContext(<br class="">> void CompilerInstance::createPCHExternalASTSource(<br class="">>     StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors,<br class="">>     void *DeserializationListener, bool OwnDeserializationListener) {<br class="">> -  IntrusiveRefCntPtr<ExternalASTSource> Source;<br class="">>   bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;<br class="">> -  Source = createPCHExternalASTSource(<br class="">> +  ModuleManager = createPCHExternalASTSource(<br class="">>       Path, getHeaderSearchOpts().Sysroot, DisablePCHValidation,<br class="">>       AllowPCHWithCompilerErrors, getPreprocessor(), getASTContext(),<br class="">>       DeserializationListener, OwnDeserializationListener, Preamble,<br class="">>       getFrontendOpts().UseGlobalModuleIndex);<br class="">> -  ModuleManager = static_cast<ASTReader*>(Source.get());<br class="">> -  getASTContext().setExternalSource(Source);<br class="">> }<br class="">><br class="">> -ExternalASTSource *CompilerInstance::createPCHExternalASTSource(<br class="">> +IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(<br class="">>     StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,<br class="">>     bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,<br class="">>     void *DeserializationListener, bool OwnDeserializationListener,<br class="">>     bool Preamble, bool UseGlobalModuleIndex) {<br class="">>   HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();<br class="">><br class="">> -  std::unique_ptr<ASTReader> Reader;<br class="">> -  Reader.reset(new ASTReader(PP, Context,<br class="">> -                             Sysroot.empty() ? "" : Sysroot.c_str(),<br class="">> -                             DisablePCHValidation,<br class="">> -                             AllowPCHWithCompilerErrors,<br class="">> -                             /*AllowConfigurationMismatch*/false,<br class="">> -                             HSOpts.ModulesValidateSystemHeaders,<br class="">> -                             UseGlobalModuleIndex));<br class="">> +  IntrusiveRefCntPtr<ASTReader> Reader(<br class="">> +      new ASTReader(PP, Context, Sysroot.empty() ? "" : Sysroot.c_str(),<br class="">> +                    DisablePCHValidation, AllowPCHWithCompilerErrors,<br class="">> +                    /*AllowConfigurationMismatch*/ false,<br class="">> +                    HSOpts.ModulesValidateSystemHeaders, UseGlobalModuleIndex));<br class="">> +<br class="">> +  // We need the external source to be set up before we read the AST, because<br class="">> +  // eagerly-deserialized declarations may use it.<br class="">> +  Context.setExternalSource(Reader.get());<br class="">><br class="">>   Reader->setDeserializationListener(<br class="">>       static_cast<ASTDeserializationListener *>(DeserializationListener),<br class="">> @@ -427,7 +425,7 @@ ExternalASTSource *CompilerInstance::cre<br class="">>     // Set the predefines buffer as suggested by the PCH reader. Typically, the<br class="">>     // predefines buffer will be empty.<br class="">>     PP.setPredefines(Reader->getSuggestedPredefines());<br class="">> -    return Reader.release();<br class="">> +    return Reader;<br class="">><br class="">>   case ASTReader::Failure:<br class="">>     // Unrecoverable failure: don't even try to process the input file.<br class="">> @@ -442,6 +440,7 @@ ExternalASTSource *CompilerInstance::cre<br class="">>     break;<br class="">>   }<br class="">><br class="">> +  Context.setExternalSource(nullptr);<br class="">>   return nullptr;<br class="">> }<br class="">><br class="">><br class="">> Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp<br class="">> URL:<span class=""> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=228234&r1=228233&r2=228234&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=228234&r1=228233&r2=228234&view=diff</a><br class="">> ==============================================================================<br class="">> --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)<br class="">> +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Feb  4 17:37:59 2015<br class="">> @@ -2591,6 +2591,11 @@ DeclContext *ASTDeclReader::getPrimaryCo<br class="">>     return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()<br class="">>                                                       : nullptr;<br class="">><br class="">> +  // We can see the TU here only if we have no Sema object. In that case,<br class="">> +  // there's no TU scope to look in, so using the DC alone is sufficient.<br class="">> +  if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))<br class="">> +    return TU;<br class="">> +<br class="">>   return nullptr;<br class="">> }<br class="">><br class="">><br class="">> Added: cfe/trunk/test/Modules/Inputs/preprocess/file.h<br class="">> URL:<span class=""> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/file.h?rev=228234&view=auto" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/file.h?rev=228234&view=auto</a><br class="">> ==============================================================================<br class="">> --- cfe/trunk/test/Modules/Inputs/preprocess/file.h (added)<br class="">> +++ cfe/trunk/test/Modules/Inputs/preprocess/file.h Wed Feb  4 17:37:59 2015<br class="">> @@ -0,0 +1,3 @@<br class="">> +struct __FILE;<br class="">> +#include "fwd.h"<br class="">> +typedef struct __FILE FILE;<br class="">><br class="">> Added: cfe/trunk/test/Modules/Inputs/preprocess/fwd.h<br class="">> URL:<span class=""> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/fwd.h?rev=228234&view=auto" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/fwd.h?rev=228234&view=auto</a><br class="">> ==============================================================================<br class="">> --- cfe/trunk/test/Modules/Inputs/preprocess/fwd.h (added)<br class="">> +++ cfe/trunk/test/Modules/Inputs/preprocess/fwd.h Wed Feb  4 17:37:59 2015<br class="">> @@ -0,0 +1 @@<br class="">> +struct __FILE;<br class="">><br class="">> Added: cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap<br class="">> URL:<span class=""> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap?rev=228234&view=auto" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap?rev=228234&view=auto</a><br class="">> ==============================================================================<br class="">> --- cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap (added)<br class="">> +++ cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap Wed Feb  4 17:37:59 2015<br class="">> @@ -0,0 +1,2 @@<br class="">> +module fwd { header "fwd.h" export * }<br class="">> +module file { header "file.h" export * }<br class="">><br class="">> Modified: cfe/trunk/test/Modules/preprocess.m<br class="">> URL:<span class=""> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess.m?rev=228234&r1=228233&r2=228234&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess.m?rev=228234&r1=228233&r2=228234&view=diff</a><br class="">> ==============================================================================<br class="">> --- cfe/trunk/test/Modules/preprocess.m (original)<br class="">> +++ cfe/trunk/test/Modules/preprocess.m Wed Feb  4 17:37:59 2015<br class="">> @@ -1,9 +1,14 @@<br class="">> // RUN: rm -rf %t<br class="">> -// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -include %S/Inputs/preprocess-prefix.h -E %s | FileCheck -strict-whitespace %s<br class="">> -// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -x objective-c-header -emit-pch %S/Inputs/preprocess-prefix.h -o %t.pch<br class="">> -// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -include-pch %t.pch -E %s | FileCheck -strict-whitespace %s<br class="">> +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -I %S/Inputs/preprocess -include %S/Inputs/preprocess-prefix.h -E %s | FileCheck -strict-whitespace %s<br class="">> +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -I %S/Inputs/preprocess -x objective-c-header -emit-pch %S/Inputs/preprocess-prefix.h -o %t.pch<br class="">> +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -I %S/Inputs/preprocess -include-pch %t.pch -E %s | FileCheck -strict-whitespace %s<br class="">> +//<br class="">> +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -I %S/Inputs/preprocess -x objective-c++ -include %S/Inputs/preprocess-prefix.h -E %s | FileCheck -strict-whitespace %s<br class="">> +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -I %S/Inputs/preprocess -x objective-c++-header -emit-pch %S/Inputs/preprocess-prefix.h -o %t.pch<br class="">> +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -I %S/Inputs/preprocess -x objective-c++ -include-pch %t.pch -E %s | FileCheck -strict-whitespace %s<br class="">> #import "diamond_right.h"<br class="">> #import "diamond_right.h" // to check that imports get their own line<br class="">> +#include "file.h"<br class="">> void test() {<br class="">>   top_left_before();<br class="">>   left_and_right();<br class="">> @@ -15,6 +20,7 @@ void test() {<br class="">><br class="">> // CHECK: @import diamond_right; /* clang -E: implicit import for "{{.*}}diamond_right.h" */{{$}}<br class="">> // CHECK: @import diamond_right; /* clang -E: implicit import for "{{.*}}diamond_right.h" */{{$}}<br class="">> +// CHECK: @import file; /* clang -E: implicit import for "{{.*}}file.h" */{{$}}<br class="">> // CHECK-NEXT: void test() {{{$}}<br class="">> // CHECK-NEXT:    top_left_before();{{$}}<br class="">> // CHECK-NEXT:    left_and_right();{{$}}<br class="">><br class="">><br class="">> _______________________________________________<br class="">> cfe-commits mailing list<br class="">><span class=""> </span><a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank" class="">cfe-commits@cs.uiuc.edu</a><br class="">><span class=""> </span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">cfe-commits mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class="">cfe-commits@cs.uiuc.edu</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class="">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></body></html>