Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,9 +1656,11 @@ void CIRGenModule::emitGlobalDefinition(GlobalDecl gd, mlir::Operation *op) {
if (const auto *method = dyn_cast<CXXMethodDecl>(d)) {
// Make sure to emit the definition(s) before we emit the thunks. This is
// necessary for the generation of certain thunks.
if (isa<CXXConstructorDecl>(method) || isa<CXXDestructorDecl>(method))
if (isa<CXXConstructorDecl>(method) || isa<CXXDestructorDecl>(method)) {
if (fd->getAttr<AnnotateAttr>())
deferredAnnotations[getMangledName(gd)] = cast<ValueDecl>(d);
Copy link
Member

@bcardosolopes bcardosolopes Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you need to add this here? It might just work as is. EmitGlobal both in OG and in the incubator handles it generically for FunctionDecl

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the same feeling, thats why I was asking the question above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I'm just pointing out how this work (as an answer to your question) via a rhetoric question. @Sharp0802 please remove this bit, if that doesn't do the job, you need to debug and find out what you are missing elsewhere.

ABI->emitCXXStructor(gd);
else if (fd->isMultiVersion())
} else if (fd->isMultiVersion())
llvm_unreachable("NYI");
else
emitGlobalFunctionDefinition(gd, op);
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ void LoweringPreparePass::runOnOperation() {
buildCXXGlobalInitFunc();
buildGlobalCtorDtorList();
buildGlobalAnnotationValues();

theModule->removeAttr(cir::CIRDialect::getGlobalAnnotationsAttrName());
}

std::unique_ptr<Pass> mlir::createLoweringPreparePass() {
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CIR/CodeGen/attr-annotate-constructor.cpp
Original file line number Diff line number Diff line change
@@ -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<name = "test", args = []>

Foo foo;
10 changes: 10 additions & 0 deletions clang/test/CIR/CodeGen/attr-annotate-destructor.cpp
Original file line number Diff line number Diff line change
@@ -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<name = "test", args = []>

Foo foo;
Loading