]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR middle-end/100250 - ICE related to -Wmaybe-uninitialized
authorMartin Sebor <msebor@redhat.com>
Thu, 29 Apr 2021 01:11:34 +0000 (19:11 -0600)
committerMartin Sebor <msebor@redhat.com>
Thu, 29 Apr 2021 01:11:34 +0000 (19:11 -0600)
gcc/ChangeLog:

PR middle-end/100250
* attribs.c (attr_access::array_as_string): Avoid dereferencing
a pointer when it's null.

gcc/testsuite/ChangeLog:

PR middle-end/100250
* gcc.dg/uninit-pr100250.c: New test.

gcc/attribs.c
gcc/testsuite/gcc.dg/uninit-pr100250.c [new file with mode: 0644]

index 3ffa1b6bc815f26618112f7f805a2ec8474eab1f..ebc0783c4395c667a4237ba5d6e06a2c37b60f1f 100644 (file)
@@ -2388,7 +2388,8 @@ attr_access::array_as_string (tree type) const
          const char *p = end;
          for ( ; p != str && *p-- != ']'; );
          if (*p == '$')
-           index_type = build_index_type (TREE_VALUE (size));
+           /* SIZE may have been cleared.  Use it with care.  */
+           index_type = build_index_type (size ? TREE_VALUE (size) : size);
        }
       else if (minsize)
        index_type = build_index_type (size_int (minsize - 1));
diff --git a/gcc/testsuite/gcc.dg/uninit-pr100250.c b/gcc/testsuite/gcc.dg/uninit-pr100250.c
new file mode 100644 (file)
index 0000000..8e7a787
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR middle-end/100250 - ICE related to -Wmaybe-uninitialized
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+extern void f (int D, const int[D], const int[D]);
+
+void g (int D, const int a[D], const int b[D], const int c[D], const int d[D])
+{
+  int c2[D];
+
+  for (int i = 0; i < D; i++) {
+
+    if (a[i] >= D) __builtin_abort ();
+    if (b[i] != d[a[i]]) __builtin_abort ();
+
+    c2[a[i]] = c[i];
+  }
+
+  f (D, d, c2);
+}
+
+void h (int D, const int d[D])
+{
+  int a[D];
+  int b[D];
+  int c[D];
+
+  g (D, a, b, c, d);          // { dg-warning "-Wmaybe-uninitialized" }
+}