[clang] WIP: fix assert in hasInitWithSideEffects (PR #146468)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 30 21:33:36 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Henrik G. Olsson (hnrklssn)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/146468.diff
1 Files Affected:
- (modified) clang/lib/AST/Decl.cpp (+3-9)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/146468
More information about the cfe-commits
mailing list