diff options
| author | Andy Kaylor <akaylor@nvidia.com> | 2025-10-13 17:07:05 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-13 17:07:05 -0700 |
| commit | 645745f9de7ea7bfc63848bf900dc424896a37e9 (patch) | |
| tree | 17b69cbeee7573bb64418eda5c6ef5d0558d3df6 /clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | |
| parent | 472ee437b832270168e3625f5cd1a8df62897896 (diff) | |
[CIR] Add support for global ctor/dtor attributes (#163247)
This adds support for adding the `global_ctor` or `global_dtor`
attribute to the CIR representation of functions defined with
`__attribute__((constructor))` or `__attribute__((destructor))` and
adding them to the `@llvm.global_ctors` or `@llvm.global_dtors` list
during lowering to LLVM IR.
Diffstat (limited to 'clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp')
| -rw-r--r-- | clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 26e0ba9b4e45..f0d73ac87238 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -2598,7 +2598,13 @@ void ConvertCIRToLLVMPass::runOnOperation() { return std::make_pair(ctorAttr.getName(), ctorAttr.getPriority()); }); - assert(!cir::MissingFeatures::opGlobalDtorList()); + // Emit the llvm.global_dtors array. + buildCtorDtorList(module, cir::CIRDialect::getGlobalDtorsAttrName(), + "llvm.global_dtors", [](mlir::Attribute attr) { + auto dtorAttr = mlir::cast<cir::GlobalDtorAttr>(attr); + return std::make_pair(dtorAttr.getName(), + dtorAttr.getPriority()); + }); } mlir::LogicalResult CIRToLLVMBrOpLowering::matchAndRewrite( |
