[clang] [AST] Iterate redecls starting from the canonical one in getRawCommentsForAnyRedecl() (PR #108475)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 19 07:10:11 PDT 2024


================
@@ -440,14 +440,23 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl(
 
   // Any redeclarations of D that we haven't checked for comments yet?
   // We can't use DenseMap::iterator directly since it'd get invalid.
-  auto LastCheckedRedecl = [this, CanonicalD]() -> const Decl * {
-    return CommentlessRedeclChains.lookup(CanonicalD);
-  }();
+  const Decl *LastCheckedRedecl = CommentlessRedeclChains.lookup(CanonicalD);
+  bool CanUseCommentlessCache = false;
+  if (LastCheckedRedecl) {
+    for (auto *Redecl : CanonicalD->redecls()) {
+      if (Redecl == D) {
+        CanUseCommentlessCache = true;
+        break;
+      }
+      if (Redecl == LastCheckedRedecl)
+        break;
+    }
+  }
----------------
AaronBallman wrote:

I was thinking something similar -- let `LastCheckedRedecl == nullptr` be the test for `CanUseCommentlessCache` instead of using a dedicated variable for that.

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


More information about the cfe-commits mailing list