https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/204054
This was superseded by `InitializingPtrs` when implementing `dynamic_cast`, so we can now remove `InitializingBlocks`. >From c3a603f8615489369b67e501920cdaa914c9e41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Tue, 16 Jun 2026 07:01:53 +0200 Subject: [PATCH] [clang][bytecode] Remove InterpState::InitializingBlocks --- clang/lib/AST/ByteCode/Interp.cpp | 15 +++++---------- clang/lib/AST/ByteCode/Interp.h | 4 ++-- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 2 +- clang/lib/AST/ByteCode/InterpState.h | 9 +++++++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 201499ea6e027..954e4e2cddb8d 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -580,7 +580,7 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { // The This pointer is writable in constructors and destructors, // even if isConst() returns true. - if (llvm::is_contained(S.InitializingBlocks, Ptr.block())) + if (S.initializingBlock(Ptr.block())) return true; if (!S.checkingPotentialConstantExpression()) { @@ -619,7 +619,7 @@ static bool CheckVolatile(InterpState &S, CodePtr OpPC, const Pointer &Ptr, return Invalid(S, OpPC); // Volatile object can be written-to and read if they are being constructed. - if (llvm::is_contained(S.InitializingBlocks, Ptr.block())) + if (S.initializingBlock(Ptr.block())) return true; // The reason why Ptr is volatile might be further up the hierarchy. @@ -1841,10 +1841,8 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func, if (Func->isDestructor() && !CheckDestructor(S, OpPC, ThisPtr)) return false; - if (Func->isConstructor() || Func->isDestructor()) { + if (Func->isConstructor() || Func->isDestructor()) S.InitializingPtrs.push_back(ThisPtr.view()); - S.InitializingBlocks.push_back(ThisPtr.block()); - } } if (!Func->isFullyCompiled()) @@ -1870,10 +1868,8 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func, InterpStateCCOverride CCOverride(S, Func->isImmediate()); bool Success = Interpret(S); // Remove initializing block again. - if (Func->isConstructor() || Func->isDestructor()) { - S.InitializingBlocks.pop_back(); + if (Func->isConstructor() || Func->isDestructor()) S.InitializingPtrs.pop_back(); - } if (!Success) { InterpFrame::free(NewFrame); @@ -2139,8 +2135,7 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, const auto *InitialFunction = cast<CXXMethodDecl>(Callee); const CXXMethodDecl *Overrider; - if (StaticDecl != DynamicDecl && - !llvm::is_contained(S.InitializingBlocks, ThisPtr.block())) { + if (StaticDecl != DynamicDecl && !S.initializingBlock(ThisPtr.block())) { if (!DynamicDecl->isDerivedFrom(StaticDecl)) return false; Overrider = S.getContext().getOverridingFunction(DynamicDecl, StaticDecl, diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index a062d43e23906..ad807816aa904 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -3665,12 +3665,12 @@ inline bool StartSpeculation(InterpState &S, CodePtr OpPC) { inline bool StartInit(InterpState &S, CodePtr OpPC) { const Pointer &Ptr = S.Stk.peek<Pointer>(); - S.InitializingBlocks.push_back(Ptr.block()); + S.InitializingPtrs.push_back(Ptr.view()); return true; } inline bool EndInit(InterpState &S, CodePtr OpPC) { - S.InitializingBlocks.pop_back(); + S.InitializingPtrs.pop_back(); return true; } diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 5076d27766e25..55907bf11506b 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -2580,7 +2580,7 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC, } // Check if we're currently running an initializer. - if (llvm::is_contained(S.InitializingBlocks, Ptr.block())) + if (S.initializingBlock(Ptr.block())) return Error(2); if (S.EvaluatingDecl && Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl) return Error(2); diff --git a/clang/lib/AST/ByteCode/InterpState.h b/clang/lib/AST/ByteCode/InterpState.h index 345a12b49c867..3f27345ea774d 100644 --- a/clang/lib/AST/ByteCode/InterpState.h +++ b/clang/lib/AST/ByteCode/InterpState.h @@ -125,6 +125,13 @@ class InterpState final : public State, public SourceMapper { /// diagnoses and returns \c false. bool noteStep(CodePtr OpPC); + bool initializingBlock(const Block *B) const { + for (PtrView V : InitializingPtrs) + if (V.block() == B) + return true; + return false; + } + private: friend class EvaluationResult; friend class InterpStateCCOverride; @@ -174,8 +181,6 @@ class InterpState final : public State, public SourceMapper { /// List of blocks we're currently running either constructors or destructors /// for. - llvm::SmallVector<const Block *> InitializingBlocks; - // FIXME: We clearly dont' need two lists here, just one is enough. llvm::SmallVector<PtrView> InitializingPtrs; }; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
