-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Fix dangling IPOAmendableCB function_ref. #120698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-amdgpu Author: Haojian Wu (hokein) ChangesA 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:
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);
|
@llvm/pr-subscribers-llvm-transforms Author: Haojian Wu (hokein) ChangesA 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:
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);
|
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.
fe5bb87
to
92735cc
Compare
LG |
This can enable clang to detect dangling assignment issues, see #120698.
The
IPOAmendableCB
's type isllvm::function_ref
, it is error-prone to write code (e.g.llvm-project/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Line 5812 in 5656cbc
IPOAmendableCB
object, which is a use-after-free issue.This patch changes the
IPOAmendableCB
tostd::function
, to avoid the dangling issue.