[committed] analyzer: fix ICE on zero-sized arrays [PR110882]
Checks
Commit Message
Successfully bootstrapped and regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r14-2955-gc62f93d1e0383d.
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.
---
gcc/analyzer/region.cc | 6 +++++-
gcc/testsuite/gcc.dg/analyzer/pr110882.c | 18 ++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr110882.c
@@ -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;
new file mode 100644
@@ -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);
+}