aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authortynasello <63558019+tynasello@users.noreply.github.com>2025-09-08 16:48:23 -0400
committerGitHub <noreply@github.com>2025-09-08 20:48:23 +0000
commita205695de4dce3c839dedbb78dd67e2a7758947a (patch)
treec6793eb31a29e94c7ed05b500237ef12f7bc8d15 /clang/lib/CodeGen/CodeGenModule.cpp
parent0fb2f524f8bc7a945fb1795e70ebe80adc08e237 (diff)
downloadllvm-a205695de4dce3c839dedbb78dd67e2a7758947a.zip
llvm-a205695de4dce3c839dedbb78dd67e2a7758947a.tar.gz
llvm-a205695de4dce3c839dedbb78dd67e2a7758947a.tar.bz2
[Clang] Add template argument support for {con,de}structor attributes. (#151400)
Fixes: https://github.com/llvm/llvm-project/issues/67154 {Con, De}structor attributes in Clang only work with integer priorities (inconsistent with GCC). This commit adds support to these attributes for template arguments. Built off of contributions from [abrachet](https://github.com/abrachet) in [#67376](https://github.com/llvm/llvm-project/pull/67376).
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index c0cfc24..87d2cd4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6376,10 +6376,18 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
SetLLVMFunctionAttributesForDefinition(D, Fn);
+ auto GetPriority = [this](const auto *Attr) -> int {
+ Expr *E = Attr->getPriority();
+ if (E) {
+ return E->EvaluateKnownConstInt(this->getContext()).getExtValue();
+ }
+ return Attr->DefaultPriority;
+ };
+
if (const ConstructorAttr *CA = D->getAttr<ConstructorAttr>())
- AddGlobalCtor(Fn, CA->getPriority());
+ AddGlobalCtor(Fn, GetPriority(CA));
if (const DestructorAttr *DA = D->getAttr<DestructorAttr>())
- AddGlobalDtor(Fn, DA->getPriority(), true);
+ AddGlobalDtor(Fn, GetPriority(DA), true);
if (getLangOpts().OpenMP && D->hasAttr<OMPDeclareTargetDeclAttr>())
getOpenMPRuntime().emitDeclareTargetFunction(D, GV);
}