https://github.com/hnrklssn created https://github.com/llvm/llvm-project/pull/146468
This fixes another instance of `Assertion failed: (NumCurrentElementsDeserializing == 0 && "should not be called while already deserializing")`. I ran into it while importing clang modules from Swift, but I haven't been able to reproduce it in a test case yet. The error seems to be that an initializer expression can be deserialized and contain a call to a function whose function body is not yet deserialized. When `evaluateValue()` is called the constexpr evaluation triggers deserialization of the function body. rdar://154717930 >From 49b4689efc05945b031d0990f2b70428cb370715 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" <h_ols...@apple.com> Date: Mon, 30 Jun 2025 21:26:19 -0700 Subject: [PATCH] WIP: fix assert in hasInitWithSideEffects --- clang/lib/AST/Decl.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 5cdf75d71e4d7..5e91566e87f74 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2444,20 +2444,14 @@ bool VarDecl::hasInitWithSideEffects() const { if (!hasInit()) return false; - // Check if we can get the initializer without deserializing - const Expr *E = nullptr; + // Check if we can get the initializer directly without an external source if (auto *S = dyn_cast<Stmt *>(Init)) { - E = cast<Expr>(S); - } else { - E = cast_or_null<Expr>(getEvaluatedStmt()->Value.getWithoutDeserializing()); - } - - if (E) + const Expr *E = cast<Expr>(S); return E->HasSideEffects(getASTContext()) && // We can get a value-dependent initializer during error recovery. (E->isValueDependent() || !evaluateValue()); + } - assert(getEvaluatedStmt()->Value.isOffset()); // ASTReader tracks this without having to deserialize the initializer if (auto Source = getASTContext().getExternalSource()) return Source->hasInitializerWithSideEffects(this); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits