Skip to content

Commit fe5bb87

Browse files
committed
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.
1 parent eace826 commit fe5bb87

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,10 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
13521352
return !AMDGPU::isEntryFunctionCC(Callee.getCallingConv()) &&
13531353
(NumAssumedCallees <= IndirectCallSpecializationThreshold);
13541354
};
1355-
AC.IPOAmendableCB = [](const Function &F) {
1355+
auto IPOAmendableCB = [](const Function &F) {
13561356
return F.getCallingConv() == CallingConv::AMDGPU_KERNEL;
13571357
};
1358+
AC.IPOAmendableCB = IPOAmendableCB;
13581359

13591360
Attributor A(Functions, InfoCache, AC);
13601361

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5809,9 +5809,10 @@ PreservedAnalyses OpenMPOptPass::run(Module &M, ModuleAnalysisManager &AM) {
58095809
AC.OREGetter = OREGetter;
58105810
AC.PassName = DEBUG_TYPE;
58115811
AC.InitializationCallback = OpenMPOpt::registerAAsForFunction;
5812-
AC.IPOAmendableCB = [](const Function &F) {
5812+
auto IPOAmendableCB = [](const Function &F) {
58135813
return F.hasFnAttribute("kernel");
58145814
};
5815+
AC.IPOAmendableCB = IPOAmendableCB;
58155816

58165817
Attributor A(Functions, InfoCache, AC);
58175818

0 commit comments

Comments
 (0)