-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[RegAlloc] Fix use-after-free in RegAllocBase::cleanupFailedVReg
#151435
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
Merged
shiltian
merged 3 commits into
main
from
users/shiltian/fix-use-after-free-after-cleanup
Aug 1, 2025
Merged
[RegAlloc] Fix use-after-free in RegAllocBase::cleanupFailedVReg
#151435
shiltian
merged 3 commits into
main
from
users/shiltian/fix-use-after-free-after-cleanup
Aug 1, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
Member
|
@llvm/pr-subscribers-backend-amdgpu Author: Shilei Tian (shiltian) ChangesSince #128400 already mentions it's not clear about the necessity of removing intervals from regunits, this PR avoids the issue by simply skipping that step. Fixes SWDEV-527146. Full diff: https://github.com/llvm/llvm-project/pull/151435.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/RegAllocBase.cpp b/llvm/lib/CodeGen/RegAllocBase.cpp
index 69b92917399fd..2400a1feea26e 100644
--- a/llvm/lib/CodeGen/RegAllocBase.cpp
+++ b/llvm/lib/CodeGen/RegAllocBase.cpp
@@ -178,10 +178,8 @@ void RegAllocBase::cleanupFailedVReg(Register FailedReg, MCRegister PhysReg,
for (MCRegAliasIterator Aliases(PhysReg, TRI, true); Aliases.isValid();
++Aliases) {
for (MachineOperand &MO : MRI->reg_operands(*Aliases)) {
- if (MO.readsReg()) {
+ if (MO.readsReg())
MO.setIsUndef(true);
- LIS->removeAllRegUnitsForPhysReg(MO.getReg());
- }
}
}
}
diff --git a/llvm/test/CodeGen/AMDGPU/use-after-free-after-cleanup-failed-vreg.ll b/llvm/test/CodeGen/AMDGPU/use-after-free-after-cleanup-failed-vreg.ll
new file mode 100644
index 0000000000000..03477e0c95523
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/use-after-free-after-cleanup-failed-vreg.ll
@@ -0,0 +1,15 @@
+; RUN: not llc -mcpu=gfx1100 -mtriple=amdgcn-amd-amdhsa -stress-regalloc=4 %s 2>&1 | FileCheck %s
+
+; CHECK: ran out of registers during register allocation in function 'f'
+
+define <16 x half> @f(i1 %LGV2, <16 x half> %0) {
+BB:
+ br i1 %LGV2, label %SW_C3, label %SW_C
+
+SW_C: ; preds = %BB
+ %B1 = fmul <16 x half> %0, zeroinitializer
+ ret <16 x half> %B1
+
+SW_C3: ; preds = %BB
+ ret <16 x half> <half 0xH0000, half undef, half undef, half undef, half undef, half undef, half undef, half undef, half undef, half undef, half undef, half undef, half undef, half undef, half undef, half undef>
+}
|
|
✅ With the latest revision this PR passed the undef deprecator. |
Since #128400 already mentions it's not clear about the necessity of removing intervals from regunits, this PR avoids the issue by simply skipping that step. Fixes SWDEV-527146.
ce76323 to
4f1c8bc
Compare
arsenm
reviewed
Jul 31, 2025
llvm/test/CodeGen/AMDGPU/use-after-free-after-cleanup-failed-vreg.ll
Outdated
Show resolved
Hide resolved
llvm/test/CodeGen/AMDGPU/use-after-free-after-cleanup-failed-vreg.ll
Outdated
Show resolved
Hide resolved
llvm/test/CodeGen/AMDGPU/use-after-free-after-cleanup-failed-vreg.ll
Outdated
Show resolved
Hide resolved
llvm/test/CodeGen/AMDGPU/use-after-free-after-cleanup-failed-vreg.ll
Outdated
Show resolved
Hide resolved
llvm/test/CodeGen/AMDGPU/use-after-free-after-cleanup-failed-vreg.ll
Outdated
Show resolved
Hide resolved
arsenm
approved these changes
Aug 1, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

#128400 introduced a use-after-free bug in
RegAllocBase::cleanupFailedVRegwhen removing intervals from regunits. The issue is from theInterferenceCacheinRAGreedy, which holdsLiveRange*. The currentInterferenceCacheAPIs make it difficult to update it, and there isn't a straightforward way to do that.Since #128400 already mentions it's not clear about the necessity of removing intervals from regunits, this PR avoids the issue by simply skipping that step.
Fixes SWDEV-527146.