]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: fix ICE on zero-sized arrays [PR110882]
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 3 Aug 2023 13:47:44 +0000 (09:47 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 3 Aug 2023 13:47:44 +0000 (09:47 -0400)
gcc/analyzer/ChangeLog:
PR analyzer/110882
* region.cc (int_size_in_bits): Fail on zero-sized types.

gcc/testsuite/ChangeLog:
PR analyzer/110882
* gcc.dg/analyzer/pr110882.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/region.cc
gcc/testsuite/gcc.dg/analyzer/pr110882.c [new file with mode: 0644]

index 9524739c7a4c459758721fded852a17868b92a26..730dab3d707bb85a87a336936b64f6f461015d75 100644 (file)
@@ -742,7 +742,11 @@ int_size_in_bits (const_tree type, bit_size_t *out)
     }
 
   tree sz = TYPE_SIZE (type);
-  if (sz && tree_fits_uhwi_p (sz))
+  if (sz
+      && tree_fits_uhwi_p (sz)
+      /* If the size is zero, then we may have a zero-sized
+        array; handle such cases by returning false.  */
+      && !integer_zerop (sz))
     {
       *out = TREE_INT_CST_LOW (sz);
       return true;
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr110882.c b/gcc/testsuite/gcc.dg/analyzer/pr110882.c
new file mode 100644 (file)
index 0000000..8002718
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-additional-options "-Wno-analyzer-too-complex" } */
+
+struct csv_row {
+  char *columns[0];
+};
+
+void
+parse_csv_line (int n_columns, const char *columns[])
+{
+  for (int n = 0; n < n_columns; n++) {
+      columns[n] = ((void *)0);
+  }
+}
+
+void parse_csv_data (int n_columns, struct csv_row *entry)
+{
+  parse_csv_line(n_columns, (const char **)entry->columns);
+}