aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorLewis Hyatt <lhyatt@gmail.com>2024-12-26 10:58:57 -0500
committerLewis Hyatt <lhyatt@gcc.gnu.org>2024-12-29 21:12:25 -0500
commit83e291014fff0b3ce1baedf59292390726d67335 (patch)
tree75f17d5978f964dc85b4e4e8265a324a4e3446ef /gcc
parent4bbf650e4bb63b424a2846045934368db1aa7d7e (diff)
downloadgcc-83e291014fff0b3ce1baedf59292390726d67335.zip
gcc-83e291014fff0b3ce1baedf59292390726d67335.tar.gz
gcc-83e291014fff0b3ce1baedf59292390726d67335.tar.bz2
tree-optimization: Fix ICE in tree-parloops.cc reduction_phi() [PR118205]
Prior to r15-6001, reduction_phi() could be called with the PHI parameter not actually being a gphi*. The search through reduction_list would fail and return NULL. r15-6001 added a requirement that PHI actually be a gphi*, but did not add a check for this. The PR shows an example where the check is needed; fix by explicitly returning NULL in this case. gcc/ChangeLog: PR tree-optimization/118205 * tree-parloops.cc (reduction_phi): Return NULL if PHI parameter is not a phi node. gcc/testsuite/ChangeLog: PR tree-optimization/118205 * c-c++-common/pr118205.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/c-c++-common/pr118205.c25
-rw-r--r--gcc/tree-parloops.cc2
2 files changed, 26 insertions, 1 deletions
diff --git a/gcc/testsuite/c-c++-common/pr118205.c b/gcc/testsuite/c-c++-common/pr118205.c
new file mode 100644
index 0000000..c98f8d8
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr118205.c
@@ -0,0 +1,25 @@
+/* PR tree-optimization/118205 */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target fgraphite } */
+/* { dg-require-effective-target pthread } */
+/* { dg-options "-O -floop-parallelize-all -ftree-parallelize-loops=2" } */
+
+int x;
+void g(int);
+int f() {
+ unsigned res = 0;
+ int arr[] = {};
+ int y = 0;
+ for (unsigned int i = 1; i; i++)
+ {
+ for (int n = 0; n < 2; n++)
+ {
+ g(arr[i]);
+ res = y > x ? y : x;
+ y = res;
+ }
+ g(arr[i]);
+ }
+ return res;
+}
diff --git a/gcc/tree-parloops.cc b/gcc/tree-parloops.cc
index 8427c28..4218329 100644
--- a/gcc/tree-parloops.cc
+++ b/gcc/tree-parloops.cc
@@ -948,7 +948,7 @@ reduction_phi (reduction_info_table_type *reduction_list, gimple *phi)
{
struct reduction_info tmpred, *red;
- if (reduction_list->is_empty () || phi == NULL)
+ if (reduction_list->is_empty () || phi == NULL || !is_a <gphi *> (phi))
return NULL;
if (gimple_uid (phi) == (unsigned int)-1