[polly] [polly] Add nullptr check to fix #113772 (PR #114206)
Karthika Devi C via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 30 03:57:24 PDT 2024
https://github.com/kartcq created https://github.com/llvm/llvm-project/pull/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 #113772.
>From 205756a5aa3211848c89d66986c7032bb96dc82f Mon Sep 17 00:00:00 2001
From: Karthika Devi C <quic_kartc at quicinc.com>
Date: Tue, 29 Oct 2024 22:05:23 -0700
Subject: [PATCH] [polly] Add nullptr check to fix #113772
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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 #113772.
---
polly/lib/Analysis/ScopDetection.cpp | 2 ++
polly/test/ScopDetect/detect-full-functions.ll | 17 +++++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 polly/test/ScopDetect/detect-full-functions.ll
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 79db3965de023e..73c26578005c35 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -1698,6 +1698,8 @@ bool ScopDetection::hasPossiblyDistributableLoop(
DetectionContext &Context) const {
for (auto *BB : Context.CurRegion.blocks()) {
auto *L = LI.getLoopFor(BB);
+ if (!L)
+ continue;
if (!Context.CurRegion.contains(L))
continue;
if (Context.BoxedLoopsSet.count(L))
diff --git a/polly/test/ScopDetect/detect-full-functions.ll b/polly/test/ScopDetect/detect-full-functions.ll
new file mode 100644
index 00000000000000..178ef32827cab8
--- /dev/null
+++ b/polly/test/ScopDetect/detect-full-functions.ll
@@ -0,0 +1,17 @@
+; RUN: opt %loadNPMPolly '-passes=print<polly-detect>' -polly-process-unprofitable=false -disable-output -polly-detect-full-functions < %s 2>&1 | FileCheck %s
+
+; 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.
+
+; CHECK: Detected Scops in Function foo
+
+define void @foo() {
+ br label %1
+
+1: ; preds = %1, %0
+ br i1 false, label %2, label %1
+
+2: ; preds = %1
+ %3 = load ptr, ptr null, align 8
+ store ptr null, ptr null, align 8
+ ret void
+}
More information about the llvm-commits
mailing list