@@ -5182,7 +5182,14 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
51825182static bool isModuleAttributeSet (Module &M, const StringRef &ModAttr) {
51835183 const auto *Attr =
51845184 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag (ModAttr));
5185- return Attr && Attr->getZExtValue ();
5185+ return Attr && Attr->isOne ();
5186+ }
5187+
5188+ // Check if the function attribute is not present and set it.
5189+ static void SetFunctionAttrIfNotSet (Function &F, StringRef FnAttrName,
5190+ StringRef Value) {
5191+ if (!F.hasFnAttribute (FnAttrName))
5192+ F.addFnAttr (FnAttrName, Value);
51865193}
51875194
51885195void llvm::CopyModuleAttrToFunctions (Module &M) {
@@ -5191,10 +5198,10 @@ void llvm::CopyModuleAttrToFunctions(Module &M) {
51915198 return ;
51925199
51935200 StringRef SignTypeValue = " none" ;
5194- if (isModuleAttributeSet (M, " sign-return-address" ))
5195- SignTypeValue = " non-leaf" ;
51965201 if (isModuleAttributeSet (M, " sign-return-address-all" ))
51975202 SignTypeValue = " all" ;
5203+ else if (isModuleAttributeSet (M, " sign-return-address" ))
5204+ SignTypeValue = " non-leaf" ;
51985205
51995206 StringRef BTEValue =
52005207 isModuleAttributeSet (M, " branch-target-enforcement" ) ? " true" : " false" ;
@@ -5209,16 +5216,12 @@ void llvm::CopyModuleAttrToFunctions(Module &M) {
52095216 for (Function &F : M.getFunctionList ()) {
52105217 if (F.isDeclaration ())
52115218 continue ;
5212- auto SetFunctionAttrIfNotSet = [&](StringRef FnAttrName, StringRef Value) {
5213- if (!F.hasFnAttribute (FnAttrName))
5214- F.addFnAttr (FnAttrName, Value);
5215- };
52165219
5217- SetFunctionAttrIfNotSet (" sign-return-address" , SignTypeValue);
5218- SetFunctionAttrIfNotSet (" branch-target-enforcement" , BTEValue);
5219- SetFunctionAttrIfNotSet (" branch-protection-pauth-lr" , BPPLValue);
5220- SetFunctionAttrIfNotSet (" guarded-control-stack" , GCSValue);
5221- SetFunctionAttrIfNotSet (" sign-return-address-key" , SignKeyValue);
5220+ SetFunctionAttrIfNotSet (F, " sign-return-address" , SignTypeValue);
5221+ SetFunctionAttrIfNotSet (F, " branch-target-enforcement" , BTEValue);
5222+ SetFunctionAttrIfNotSet (F, " branch-protection-pauth-lr" , BPPLValue);
5223+ SetFunctionAttrIfNotSet (F, " guarded-control-stack" , GCSValue);
5224+ SetFunctionAttrIfNotSet (F, " sign-return-address-key" , SignKeyValue);
52225225 }
52235226}
52245227
0 commit comments