Skip to content

Commit 4cb7170

Browse files
authored
[polly] Add nullptr check to fix llvm#113772 (llvm#114206)
The patch adds a nullptr check before accessing the loop blocks in 'hasPossiblyDistributableLoop' function. The existing check for the loop’s containment in the region does not capture nullptr cases when the region covers the entire function. Therefore, it’s better to exit if the basic block isn’t part of any loop Fixes llvm#113772.
1 parent 7ec26b2 commit 4cb7170

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

polly/lib/Analysis/ScopDetection.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,8 @@ bool ScopDetection::hasPossiblyDistributableLoop(
16981698
DetectionContext &Context) const {
16991699
for (auto *BB : Context.CurRegion.blocks()) {
17001700
auto *L = LI.getLoopFor(BB);
1701+
if (!L)
1702+
continue;
17011703
if (!Context.CurRegion.contains(L))
17021704
continue;
17031705
if (Context.BoxedLoopsSet.count(L))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: opt %loadNPMPolly '-passes=print<polly-detect>' -polly-process-unprofitable=false -disable-output -polly-detect-full-functions < %s 2>&1 | FileCheck %s
2+
3+
; Verify if a simple function with basic block not part of loop doesn't crash with polly-process-unprofitable=false and polly-detect-full-functions flags.
4+
5+
; CHECK: Detected Scops in Function foo
6+
7+
define void @foo() {
8+
br label %1
9+
10+
1: ; preds = %1, %0
11+
br i1 false, label %2, label %1
12+
13+
2: ; preds = %1
14+
%3 = load ptr, ptr null, align 8
15+
store ptr null, ptr null, align 8
16+
ret void
17+
}

0 commit comments

Comments
 (0)