-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[CodeGenPrepare] Fix crash with null PSI #173385
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
base: main
Are you sure you want to change the base?
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-llvm-transforms Author: None (nataliakokoromyti) Changesthis PR fixes a crash in CodeGenPrepare when PSI is null. Full diff: https://github.com/llvm/llvm-project/pull/173385.diff 1 Files Affected:
diff --git a/llvm/test/Transforms/CodeGenPrepare/pr173360-null-psi.ll b/llvm/test/Transforms/CodeGenPrepare/pr173360-null-psi.ll
new file mode 100644
index 0000000000000..53500c0bcb481
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/pr173360-null-psi.ll
@@ -0,0 +1,21 @@
+; NOTE: This test verifies that CodeGenPrepare doesn't crash when PSI is null
+; RUN: opt -passes=codegenprepare < %s -S | FileCheck %s
+;
+; This test case triggered a null pointer dereference in CodeGenPrepare::_run()
+; when ProfileSummaryInfo (PSI) was not available. The pass attempted to call
+; PSI->hasHugeWorkingSetSize() without checking if PSI was null.
+;
+; The fix adds null checks before dereferencing PSI.
+; See: https://github.com/llvm/llvm-project/issues/173360
+
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: @f(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %iv.next.reg2mem = alloca i32, align 4
+; CHECK-NEXT: ret void
+define void @f(ptr %A, i32 %n) {
+entry:
+ %iv.next.reg2mem = alloca i32, align 4
+ ret void
+}
|
|
Where is the fix? Only test file is modified. |
3f6f3ed to
6e2d9e2
Compare
nikic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a test.
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/CodeGen/CodeGenPrepare.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index aa645d87f..ee1ad6de5 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -605,7 +605,8 @@ bool CodeGenPrepare::_run(Function &F) {
/// This optimization identifies DIV instructions that can be
/// profitably bypassed and carried out with a shorter, faster divide.
- if (!OptSize && PSI && !PSI->hasHugeWorkingSetSize() && TLI->isSlowDivBypassed()) {
+ if (!OptSize && PSI && !PSI->hasHugeWorkingSetSize() &&
+ TLI->isSlowDivBypassed()) {
const DenseMap<unsigned int, unsigned int> &BypassWidths =
TLI->getBypassSlowDivWidths();
BasicBlock *BB = &*F.begin();
|
this PR fixes a crash in CodeGenPrepare when PSI is null.
Fixes #173360.