[llvm-branch-commits] [clang] [CIR][LoweringPrepare] Emit guard variables for static local initialization (PR #179828)
Andy Kaylor via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Feb 11 17:46:24 PST 2026
================
@@ -112,11 +188,119 @@ struct LoweringPreparePass
llvm::StringMap<uint32_t> dynamicInitializerNames;
llvm::SmallVector<cir::FuncOp> dynamicInitializers;
+ /// Tracks guard variables for static locals.
+ llvm::DenseMap<const clang::VarDecl *, cir::GlobalOp> staticLocalDeclGuardMap;
+
/// List of ctors and their priorities to be called before main()
llvm::SmallVector<std::pair<std::string, uint32_t>, 4> globalCtorList;
/// List of dtors and their priorities to be called when unloading module.
llvm::SmallVector<std::pair<std::string, uint32_t>, 4> globalDtorList;
+ /// Returns true if the target uses ARM-style guard variables for static
+ /// local initialization (32-bit guard, check bit 0 only).
+ bool useARMGuardVarABI() const {
+ switch (astCtx->getCXXABIKind()) {
+ case clang::TargetCXXABI::GenericARM:
+ case clang::TargetCXXABI::iOS:
+ case clang::TargetCXXABI::WatchOS:
+ case clang::TargetCXXABI::GenericAArch64:
+ case clang::TargetCXXABI::WebAssembly:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /// Emit the guarded initialization for a static local variable.
+ /// This handles the if/else structure after the guard byte check,
+ /// following OG's ItaniumCXXABI::EmitGuardedInit skeleton.
+ void emitCXXGuardedInitIf(CIRBaseBuilderTy &builder, cir::GlobalOp globalOp,
----------------
andykaylor wrote:
Yeah, I'd be OK with moving all of it in a future PR.
https://github.com/llvm/llvm-project/pull/179828
More information about the llvm-branch-commits
mailing list