Skip to content

Commit 677ebce

Browse files
committed
[clang-repl] fix cleanup context in CleanUpPTU()
Get the last context returned by collectAllContexts() instead of just the primary context. This fixes cleanup in nested namespaces: instead of cleaning up all the namespace hierarchy it cleans up just the innermost namespace.
1 parent 97c3ed6 commit 677ebce

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

clang/lib/Interpreter/IncrementalParser.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,17 @@ std::unique_ptr<llvm::Module> IncrementalParser::GenModule() {
374374
void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
375375
TranslationUnitDecl *MostRecentTU = PTU.TUPart;
376376
TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();
377-
if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) {
377+
if (!FirstTU) {
378+
return;
379+
}
380+
381+
SmallVector<DeclContext *> contexts;
382+
FirstTU->collectAllContexts(contexts);
383+
if (contexts.empty()) {
384+
return;
385+
}
386+
387+
if (StoredDeclsMap *Map = contexts.back()->getLookupPtr()) {
378388
for (auto I = Map->begin(); I != Map->end(); ++I) {
379389
StoredDeclsList &List = I->second;
380390
DeclContextLookupResult R = List.getLookupResult();

0 commit comments

Comments
 (0)