aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/ASTWriter.cpp
diff options
context:
space:
mode:
authorHenrik G. Olsson <hnrklssn@gmail.com>2025-07-03 15:37:55 -0700
committerGitHub <noreply@github.com>2025-07-03 15:37:55 -0700
commit2910c24638fcbc3dec02be072e6026d01012d946 (patch)
treee11a429e6afc5c40e2ee6f1537737d4b3abe1d74 /clang/lib/Serialization/ASTWriter.cpp
parent9bfb347ea0a0a260eb505921dfc0cb824a6ced5d (diff)
downloadllvm-2910c24638fcbc3dec02be072e6026d01012d946.zip
llvm-2910c24638fcbc3dec02be072e6026d01012d946.tar.gz
llvm-2910c24638fcbc3dec02be072e6026d01012d946.tar.bz2
[Modules] Record side effect info in EvaluatedStmt (#146468)
All deserialized VarDecl initializers are EvaluatedStmt, but not all EvaluatedStmt initializers are from a PCH. Calling `VarDecl::hasInitWithSideEffects` can trigger constant evaluation, but it's hard to know ahead of time whether that will trigger deserialization - even if the initializer is fully deserialized, it may contain a call to a constructor whose body is not deserialized. By caching the result of `VarDecl::hasInitWithSideEffects` and populating that cache during deserialization we can guarantee that calling it won't trigger deserialization regardless of the state of the initializer. This also reduces memory usage by removing the `InitSideEffectVars` set in `ASTReader`. rdar://154717930
Diffstat (limited to 'clang/lib/Serialization/ASTWriter.cpp')
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 874b24b..2bd9ae5 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -7320,6 +7320,10 @@ void ASTRecordWriter::AddVarDeclInit(const VarDecl *VD) {
uint64_t Val = 1;
if (EvaluatedStmt *ES = VD->getEvaluatedStmt()) {
+ // This may trigger evaluation, so run it first
+ if (VD->hasInitWithSideEffects())
+ Val |= 16;
+ assert(ES->CheckedForSideEffects);
Val |= (ES->HasConstantInitialization ? 2 : 0);
Val |= (ES->HasConstantDestruction ? 4 : 0);
APValue *Evaluated = VD->getEvaluatedValue();