[clang] Mark CXX module initializer with PACBTI attributes (PR #133716)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 31 12:21:19 PDT 2025


================
@@ -818,6 +818,12 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
     Fn->addFnAttr("device-init");
   }
 
+  if (getTarget().isBranchProtectionSupportedArch(
+          getTarget().getTargetOpts().CPU)) {
+    TargetInfo::BranchProtectionInfo BPI(getLangOpts());
+    getTargetCodeGenInfo().setBranchProtectionFnAttributes(BPI, (*Fn));
----------------
efriedma-quic wrote:

This does not look like the right place for this code; we have a bunch of different functions for setting attributes, we shouldn't be bypassing all of them to directly juggle branch protection specifically for initializing global variables.

Maybe AArch64TargetCodeGenInfo::setTargetAttributes needs to be changed so it works even if there isn't a FunctionDecl?

https://github.com/llvm/llvm-project/pull/133716


More information about the cfe-commits mailing list