Skip to content

Commit

Permalink
[clang-repl] fix cleanup context in CleanUpPTU()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
p4vook committed Dec 15, 2023
1 parent 97c3ed6 commit 677ebce
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion clang/lib/Interpreter/IncrementalParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,17 @@ std::unique_ptr<llvm::Module> IncrementalParser::GenModule() {
void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
TranslationUnitDecl *MostRecentTU = PTU.TUPart;
TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();
if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) {
if (!FirstTU) {
return;
}

SmallVector<DeclContext *> contexts;
FirstTU->collectAllContexts(contexts);
if (contexts.empty()) {
return;
}

if (StoredDeclsMap *Map = contexts.back()->getLookupPtr()) {
for (auto I = Map->begin(); I != Map->end(); ++I) {
StoredDeclsList &List = I->second;
DeclContextLookupResult R = List.getLookupResult();
Expand Down

0 comments on commit 677ebce

Please sign in to comment.