public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-8747] analyzer: fix ICE on zero-sized arrays [PR110882]
@ 2024-05-09 17:11 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2024-05-09 17:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a0b13d0860848dd5f2876897ada1e22e4e681e91

commit r13-8747-ga0b13d0860848dd5f2876897ada1e22e4e681e91
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Thu May 9 13:09:28 2024 -0400

    analyzer: fix ICE on zero-sized arrays [PR110882]
    
    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.
    
    (cherry picked from commit r14-2955-gc62f93d1e0383d)
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/region.cc                   |  6 +++++-
 gcc/testsuite/gcc.dg/analyzer/pr110882.c | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc
index f982ce67509e..c1bfecabd158 100644
--- a/gcc/analyzer/region.cc
+++ b/gcc/analyzer/region.cc
@@ -395,7 +395,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
index 000000000000..80027184053e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr110882.c
@@ -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);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-09 17:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-09 17:11 [gcc r13-8747] analyzer: fix ICE on zero-sized arrays [PR110882] David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).