https://github.com/hahnjo created 
https://github.com/llvm/llvm-project/pull/219189

`ExternalASTSource::incrementGeneration` returns the `OldGeneration`, which 
must be taken into account in case it is delegated to the topmost external 
source.

This obsoletes a long-standing downstream patch in Cling that was previously 
submitted in https://reviews.llvm.org/D39714.

>From a520ad10573f35dfca27b42847c589d8d9511f88 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <[email protected]>
Date: Thu, 27 Aug 2026 13:11:37 +0200
Subject: [PATCH] [clang][AST] Fix generation with multiple external sources

ExternalASTSource::incrementGeneration returns the OldGeneration,
which must be taken into account in case it is delegated to the
topmost external source.

This obsoletes a long-standing downstream patch in Cling that was
previously submitted in https://reviews.llvm.org/D39714.
---
 clang/lib/AST/ExternalASTSource.cpp | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/clang/lib/AST/ExternalASTSource.cpp 
b/clang/lib/AST/ExternalASTSource.cpp
index e8c1004089713..1888ffd6bd27c 100644
--- a/clang/lib/AST/ExternalASTSource.cpp
+++ b/clang/lib/AST/ExternalASTSource.cpp
@@ -118,19 +118,20 @@ void ExternalASTSource::FindExternalLexicalDecls(
 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
 
 uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
-  uint32_t OldGeneration = CurrentGeneration;
-
   // Make sure the generation of the topmost external source for the context is
   // incremented. That might not be us.
   auto *P = C.getExternalSource();
-  if (P && P != this)
+  if (P && P != this) {
+    // The call itself returns the OldGeneration of the topmost external 
source.
     CurrentGeneration = P->incrementGeneration(C);
-  else {
-    // FIXME: Only bump the generation counter if the current generation number
-    // has been observed?
-    if (!++CurrentGeneration)
-      llvm::reportFatalUsageError("generation counter overflowed");
   }
 
+  uint32_t OldGeneration = CurrentGeneration;
+
+  // FIXME: Only bump the generation counter if the current generation number
+  // has been observed?
+  if (!++CurrentGeneration)
+    llvm::reportFatalUsageError("generation counter overflowed");
+
   return OldGeneration;
 }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to