[clang] Fix clang reject valid C++ code after d999ce0302f06d250f6d496b56a5a5f (PR #94471)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 5 12:11:47 PDT 2024


https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/94471

>From 8457c4aa1758d10188da5978d30d2d1ed505e01e Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Wed, 5 Jun 2024 15:46:56 +0200
Subject: [PATCH 1/3] Fix clang reject valid C++ code after
 d999ce0302f06d250f6d496b56a5a5f2dc331e61

The incremental processing mode doesn't seem to work well for C++.
---
 clang/lib/Sema/SemaDecl.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a6734ef8c30aa..4b9b735f1cfb4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2288,7 +2288,8 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
     // Partial translation units that are created in incremental processing must
     // not clean up the IdResolver because PTUs should take into account the
     // declarations that came from previous PTUs.
-    if (!PP.isIncrementalProcessingEnabled() || getLangOpts().ObjC)
+    if (!PP.isIncrementalProcessingEnabled() || getLangOpts().ObjC ||
+        getLangOpts().CPlusPlus)
       IdResolver.RemoveDecl(D);
 
     // Warn on it if we are shadowing a declaration.

>From 5d3e60cc5839fece4f3f8d8d158ae562d7604580 Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Wed, 5 Jun 2024 20:34:30 +0200
Subject: [PATCH 2/3] Fix more

---
 clang/lib/Interpreter/IncrementalParser.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp
index 5bc8385d874a1..bbc6d3addb085 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -413,7 +413,9 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
     if (!ND)
       continue;
     // Check if we need to clean up the IdResolver chain.
-    if (ND->getDeclName().getFETokenInfo())
+    if (ND->getDeclName().getFETokenInfo() &&
+        CI->getPreprocessor().isIncrementalProcessingEnabled() &&
+        !D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
       getCI()->getSema().IdResolver.RemoveDecl(ND);
   }
 }

>From 59b94757009ceae2a7fe685afd42d933b18cf3dc Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Wed, 5 Jun 2024 21:11:25 +0200
Subject: [PATCH 3/3] address review comment.

---
 clang/lib/Interpreter/IncrementalParser.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp
index bbc6d3addb085..f709875379d7b 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -414,7 +414,6 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
       continue;
     // Check if we need to clean up the IdResolver chain.
     if (ND->getDeclName().getFETokenInfo() &&
-        CI->getPreprocessor().isIncrementalProcessingEnabled() &&
         !D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
       getCI()->getSema().IdResolver.RemoveDecl(ND);
   }



More information about the cfe-commits mailing list