diff options
author | David Malcolm <dmalcolm@redhat.com> | 2023-08-03 09:47:44 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2023-08-03 09:47:44 -0400 |
commit | c62f93d1e0383def445d4ef2b812468cb7cdaf05 (patch) | |
tree | 3ca1d6738b3287675ffdc6cd9951b6f09a007b4f | |
parent | a9b6043983b2ebd9d5c0f72043b17110b54f1910 (diff) | |
download | gcc-c62f93d1e0383def445d4ef2b812468cb7cdaf05.zip gcc-c62f93d1e0383def445d4ef2b812468cb7cdaf05.tar.gz gcc-c62f93d1e0383def445d4ef2b812468cb7cdaf05.tar.bz2 |
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.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
-rw-r--r-- | gcc/analyzer/region.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/analyzer/pr110882.c | 18 |
2 files changed, 23 insertions, 1 deletions
diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc index 9524739..730dab3 100644 --- a/gcc/analyzer/region.cc +++ b/gcc/analyzer/region.cc @@ -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 index 0000000..8002718 --- /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); +} |