[clang] [clang-repl] fix CleanUpPTU by removing decl according to C implicitly FuncitonDecl. (PR #178648)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 9 06:10:23 PST 2026


================
@@ -192,6 +201,32 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl *MostRecentTU) {
         !D->getLangOpts().CPlusPlus)
       S.IdResolver.RemoveDecl(ND);
   }
+
+  // In C, implicit function declarations are not lexically attached to the
+  // current PTU, so they cannot be found in
+  // MostRecentTU->getPrimaryContext()->getLookupPtr(). We must traverse the
+  // entire IdentifierTable to locate them.
+  // FIXME: Is there a more lightweight solution?
+  llvm::SmallVector<NamedDecl *, 2> NamedDeclsToRemove;
+  if (!S.getLangOpts().CPlusPlus) {
+    for (auto &Entry : S.getASTContext().Idents) {
----------------
fogsong233 wrote:

I’ve found another approach. 
Semantically, the extern "C" functions aren't located in the most recent TU, but rather in `getExternCContextDecl()`. I’ve updated the logic to traverse this declaration instead, checking for entries whose lexical context is the most recent TU. This feels much more lightweight.

https://github.com/llvm/llvm-project/pull/178648


More information about the cfe-commits mailing list