From c95056387d89bf866d8b74f570b5dc09a3329efb Mon Sep 17 00:00:00 2001 From: Sharp0802 Date: Tue, 26 Aug 2025 21:29:28 +0900 Subject: [PATCH 1/4] [CIR] Add `annotate` attributes to constructors and destructors --- 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 f7ed716785d4..832342751e6b 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); From ae93098441a1328fe1cfebfff4d92174d50dc802 Mon Sep 17 00:00:00 2001 From: Sharp0802 Date: Wed, 27 Aug 2025 12:07:03 +0900 Subject: [PATCH 2/4] [CIR] Remove unconsumed global annotations --- clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index 8c5226abaa82..d9aa3bc5eb1e 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() { From 8ef29a0741efd66f1808e1f5c5165363e59c27ca Mon Sep 17 00:00:00 2001 From: Sharp0802 Date: Thu, 28 Aug 2025 15:32:41 +0900 Subject: [PATCH 3/4] [CIR] Add tests for annotating constructor and destructor --- clang/test/CIR/CodeGen/attr-annotate-constructor.cpp | 10 ++++++++++ clang/test/CIR/CodeGen/attr-annotate-destructor.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 clang/test/CIR/CodeGen/attr-annotate-constructor.cpp create mode 100644 clang/test/CIR/CodeGen/attr-annotate-destructor.cpp 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..27804fbca619 --- /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 -check-prefix=CIR + +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..6ff0cfff6801 --- /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 -check-prefix=CIR + +class Foo { +public: + [[clang::annotate("test")]] ~Foo() {} +}; +// CHECK: #cir.annotation + +Foo foo; From 292fd8cb964241c58df73d9118f8b9154a46a207 Mon Sep 17 00:00:00 2001 From: Sharp0802 Date: Thu, 28 Aug 2025 19:03:32 +0900 Subject: [PATCH 4/4] [CIR] Remove unknown prefix --- clang/test/CIR/CodeGen/attr-annotate-constructor.cpp | 2 +- clang/test/CIR/CodeGen/attr-annotate-destructor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/CIR/CodeGen/attr-annotate-constructor.cpp b/clang/test/CIR/CodeGen/attr-annotate-constructor.cpp index 27804fbca619..d63e782f8381 100644 --- a/clang/test/CIR/CodeGen/attr-annotate-constructor.cpp +++ b/clang/test/CIR/CodeGen/attr-annotate-constructor.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -emit-cir %s -o %t.cir -// RUN: FileCheck --input-file %t.cir %s -check-prefix=CIR +// RUN: FileCheck --input-file %t.cir %s class Foo { public: diff --git a/clang/test/CIR/CodeGen/attr-annotate-destructor.cpp b/clang/test/CIR/CodeGen/attr-annotate-destructor.cpp index 6ff0cfff6801..53f85393ef63 100644 --- a/clang/test/CIR/CodeGen/attr-annotate-destructor.cpp +++ b/clang/test/CIR/CodeGen/attr-annotate-destructor.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -emit-cir %s -o %t.cir -// RUN: FileCheck --input-file %t.cir %s -check-prefix=CIR +// RUN: FileCheck --input-file %t.cir %s class Foo { public: