From a205695de4dce3c839dedbb78dd67e2a7758947a Mon Sep 17 00:00:00 2001 From: tynasello <63558019+tynasello@users.noreply.github.com> Date: Mon, 8 Sep 2025 16:48:23 -0400 Subject: [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). --- clang/lib/CodeGen/CodeGenModule.cpp | 12 ++++++++++-- 1 file changed, 10 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 c0cfc24f0287..87d2cd4ce468 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()) - AddGlobalCtor(Fn, CA->getPriority()); + AddGlobalCtor(Fn, GetPriority(CA)); if (const DestructorAttr *DA = D->getAttr()) - AddGlobalDtor(Fn, DA->getPriority(), true); + AddGlobalDtor(Fn, GetPriority(DA), true); if (getLangOpts().OpenMP && D->hasAttr()) getOpenMPRuntime().emitDeclareTargetFunction(D, GV); } -- cgit v1.2.3