From 121b2252de0eed68f2ddf5f09e924a6c35423d47 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Mon, 11 Oct 2021 12:31:02 -0500 Subject: AddGlobalAnnotations for function with or without function body. When AnnotateAttr is on a function, AddGlobalAnnotations is only called in CodeGenModule::EmitGlobalFunctionDefinition which means AnnotateAttr on function declaration without function body will be ignored. The patch will move AddGlobalAnnotations to CodeGenModule::SetFunctionAttributes, so with or without function body, the AnnotateAttr will get code gen for a function. It'll help case when AnnotateAttr is on external function, and the AnnotateAttr will be consumed in IR level. For example, a pass to collect num of uses for functions with __attribute((annotate("count_use"))) after optimizations, As long as there's __attribute((annotate("count_use"))), function with or without function body should be counted. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D111109 Patch by: python3kgae (Xiang Li) --- clang/lib/CodeGen/CodeGenModule.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index d4e3186c10a5..9fa5e9cf1b79 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2195,6 +2195,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, CalleeIdx, PayloadIndices, /* VarArgsArePassed */ false)})); } + + if (FD->hasAttr()) + AddGlobalAnnotations(FD, F); } void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) { @@ -4893,8 +4896,6 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, AddGlobalCtor(Fn, CA->getPriority()); if (const DestructorAttr *DA = D->getAttr()) AddGlobalDtor(Fn, DA->getPriority(), true); - if (D->hasAttr()) - AddGlobalAnnotations(D, Fn); } void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) { -- cgit v1.2.3