[llvm] Fix dangling IPOAmendableCB function_ref. (PR #120698)
Haojian Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 20 00:45:57 PST 2024
https://github.com/hokein created https://github.com/llvm/llvm-project/pull/120698
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.
>From fe5bb87f26507d5c467db246ce1ae56553ddd1df Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Fri, 20 Dec 2024 09:42:56 +0100
Subject: [PATCH] Fix dangling IPOAmendableCB function_ref.
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.
---
llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp | 3 ++-
llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
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);
More information about the llvm-commits
mailing list