aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Interpreter/IncrementalParser.cpp
diff options
context:
space:
mode:
authorVassil Vassilev <v.g.vassilev@gmail.com>2024-05-21 20:21:32 +0300
committerGitHub <noreply@github.com>2024-05-21 20:21:32 +0300
commit253c28fa829cee0104c2fc59ed1a958980b5138c (patch)
tree8c541029dd0542e925c614e42ffd541a6329120d /clang/lib/Interpreter/IncrementalParser.cpp
parent98f105a1304e8d3fd0a0234d1d488ed513833df8 (diff)
downloadllvm-253c28fa829cee0104c2fc59ed1a958980b5138c.zip
llvm-253c28fa829cee0104c2fc59ed1a958980b5138c.tar.gz
llvm-253c28fa829cee0104c2fc59ed1a958980b5138c.tar.bz2
[clang-repl] Extend the C support. (#89804)
The IdResolver chain is the main way for C to implement lookup rules. Every new partial translation unit caused clang to exit the top-most scope which in turn cleaned up the IdResolver chain. That was not an issue for C++ because its lookup is implemented on the level of declaration contexts. This patch keeps the IdResolver chain across partial translation units maintaining proper C-style lookup infrastructure.
Diffstat (limited to 'clang/lib/Interpreter/IncrementalParser.cpp')
-rw-r--r--clang/lib/Interpreter/IncrementalParser.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp
index ef90fe9..5bc8385 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -387,8 +387,7 @@ 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 (StoredDeclsMap *Map = MostRecentTU->getPrimaryContext()->getLookupPtr()) {
for (auto &&[Key, List] : *Map) {
DeclContextLookupResult R = List.getLookupResult();
std::vector<NamedDecl *> NamedDeclsToRemove;
@@ -407,6 +406,16 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
}
}
}
+
+ // FIXME: We should de-allocate MostRecentTU
+ for (Decl *D : MostRecentTU->decls()) {
+ auto *ND = dyn_cast<NamedDecl>(D);
+ if (!ND)
+ continue;
+ // Check if we need to clean up the IdResolver chain.
+ if (ND->getDeclName().getFETokenInfo())
+ getCI()->getSema().IdResolver.RemoveDecl(ND);
+ }
}
llvm::StringRef IncrementalParser::GetMangledName(GlobalDecl GD) const {