From 4f39afe45b2f83c04e8f17ce58add28731803592 Mon Sep 17 00:00:00 2001 From: Sharp0802 Date: Fri, 20 Jun 2025 23:05:12 +0900 Subject: [PATCH 1/2] [CIR] Apply annotation to CXXConstructorDecl and CXXDestructorDecl too --- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 09d2609cd7b3..5aa7bd568e41 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -1648,9 +1648,11 @@ void CIRGenModule::emitGlobalDefinition(GlobalDecl gd, mlir::Operation *op) { if (const auto *method = dyn_cast(d)) { // Make sure to emit the definition(s) before we emit the thunks. This is // necessary for the generation of certain thunks. - if (isa(method) || isa(method)) + if (isa(method) || isa(method)) { + if (d->getAttr()) + deferredAnnotations[getMangledName(gd)] = cast(d); ABI->emitCXXStructor(gd); - else if (fd->isMultiVersion()) + } else if (fd->isMultiVersion()) llvm_unreachable("NYI"); else emitGlobalFunctionDefinition(gd, op); From 67e6ac3525ffff8e95fdefd8d4cc0861a8234c8c Mon Sep 17 00:00:00 2001 From: Sharp0802 Date: Fri, 20 Jun 2025 23:06:00 +0900 Subject: [PATCH 2/2] [CIR] Remove duplicated annotation definition --- clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp | 4 ++++ clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index b9b1bb774401..756416302bf1 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp @@ -1610,6 +1610,10 @@ void LoweringPreparePass::runOnOperation() { buildCXXGlobalInitFunc(); buildGlobalCtorDtorList(); buildGlobalAnnotationValues(); + + if (theModule && theModule->hasAttr("cir.global_annotations")) { + theModule->removeAttr("cir.global_annotations"); + } } std::unique_ptr mlir::createLoweringPreparePass() { diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 9e4c916882d3..7959dee97f37 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -2190,6 +2190,11 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite( cir::FuncOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const { + mlir::ModuleOp module = op->getParentOfType(); + if (module->hasAttr("cir.global_annotations")) { + op->removeAttr("annotations"); + } + auto fnType = op.getFunctionType(); auto isDsoLocal = op.getDsoLocal(); mlir::TypeConverter::SignatureConversion signatureConversion(