diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index d80f8b70964e..d514f54738c7 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -1656,9 +1656,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 (fd->getAttr()) + deferredAnnotations[getMangledName(gd)] = cast(d); ABI->emitCXXStructor(gd); - else if (fd->isMultiVersion()) + } else if (fd->isMultiVersion()) llvm_unreachable("NYI"); else emitGlobalFunctionDefinition(gd, op); diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index d582849e033f..762de4381969 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp @@ -1653,6 +1653,8 @@ void LoweringPreparePass::runOnOperation() { buildCXXGlobalInitFunc(); buildGlobalCtorDtorList(); buildGlobalAnnotationValues(); + + theModule->removeAttr(cir::CIRDialect::getGlobalAnnotationsAttrName()); } std::unique_ptr mlir::createLoweringPreparePass() { diff --git a/clang/test/CIR/CodeGen/attr-annotate-constructor.cpp b/clang/test/CIR/CodeGen/attr-annotate-constructor.cpp new file mode 100644 index 000000000000..d63e782f8381 --- /dev/null +++ b/clang/test/CIR/CodeGen/attr-annotate-constructor.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file %t.cir %s + +class Foo { +public: + [[clang::annotate("test")]] Foo() {} +}; +// CHECK: #cir.annotation + +Foo foo; diff --git a/clang/test/CIR/CodeGen/attr-annotate-destructor.cpp b/clang/test/CIR/CodeGen/attr-annotate-destructor.cpp new file mode 100644 index 000000000000..53f85393ef63 --- /dev/null +++ b/clang/test/CIR/CodeGen/attr-annotate-destructor.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file %t.cir %s + +class Foo { +public: + [[clang::annotate("test")]] ~Foo() {} +}; +// CHECK: #cir.annotation + +Foo foo;