[llvm] Fix dangling IPOAmendableCB function_ref. (PR #120698)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 20 00:46:31 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Haojian Wu (hokein)

<details>
<summary>Changes</summary>

A temporary lambda is assigned to a llvm::function_ref, this lambda is destroyed at the end of the full expression, any use of the function_ref afterwards is undefined behavior.

---
Full diff: https://github.com/llvm/llvm-project/pull/120698.diff


2 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp (+2-1) 
- (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+2-1) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index 21f9c50c352563..227a49fcc1a491 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -1352,9 +1352,10 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
         return !AMDGPU::isEntryFunctionCC(Callee.getCallingConv()) &&
                (NumAssumedCallees <= IndirectCallSpecializationThreshold);
       };
-  AC.IPOAmendableCB = [](const Function &F) {
+  auto IPOAmendableCB = [](const Function &F) {
     return F.getCallingConv() == CallingConv::AMDGPU_KERNEL;
   };
+  AC.IPOAmendableCB = IPOAmendableCB;
 
   Attributor A(Functions, InfoCache, AC);
 
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index b40ab357670b86..ee4e4a85d5a0e0 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -5809,9 +5809,10 @@ PreservedAnalyses OpenMPOptPass::run(Module &M, ModuleAnalysisManager &AM) {
   AC.OREGetter = OREGetter;
   AC.PassName = DEBUG_TYPE;
   AC.InitializationCallback = OpenMPOpt::registerAAsForFunction;
-  AC.IPOAmendableCB = [](const Function &F) {
+  auto IPOAmendableCB = [](const Function &F) {
     return F.hasFnAttribute("kernel");
   };
+  AC.IPOAmendableCB = IPOAmendableCB;
 
   Attributor A(Functions, InfoCache, AC);
 

``````````

</details>


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


More information about the llvm-commits mailing list