diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-11-19 20:02:41 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-11-19 20:09:55 +0100 |
commit | 8156cfaa4c45f1249bbdda29d04b4fef84b7eafe (patch) | |
tree | 37610149c21e123d64615c72769a1a9a69b89697 /gcc/c/c-decl.c | |
parent | ae48b74ca0c0ba33d396a6ebad7a1c0a6dadb1f7 (diff) | |
download | gcc-8156cfaa4c45f1249bbdda29d04b4fef84b7eafe.zip gcc-8156cfaa4c45f1249bbdda29d04b4fef84b7eafe.tar.gz gcc-8156cfaa4c45f1249bbdda29d04b4fef84b7eafe.tar.bz2 |
c, tree: Fix ICE from get_parm_array_spec [PR97860]
The C and C++ FEs handle zero sized arrays differently, C uses
NULL TYPE_MAX_VALUE on non-NULL TYPE_DOMAIN on complete ARRAY_TYPEs
with bitsize_zero_node TYPE_SIZE, while C++ FE likes to set
TYPE_MAX_VALUE to the largest value (and min to the lowest).
Martin has used array_type_nelts in get_parm_array_spec where the
function on the C form of [0] arrays returns error_mark_node and the code
crashes soon afterwards. The following patch teaches array_type_nelts about
this (e.g. dwarf2out already handles that as [0]). While it will change
what is_empty_type returns for certain types (e.g. struct S { int a[0]; };),
as those types occupy zero bits in C, it should make an ABI difference.
So, the tree.c change makes the c-decl.c code handle the [0] arrays
like any other constant extents, and the c-decl.c change just makes sure
that if we'd run into error_mark_node e.g. from the VLA expressions, we
don't crash on those.
2020-11-19 Jakub Jelinek <jakub@redhat.com>
PR c/97860
* tree.c (array_type_nelts): For complete arrays with zero min
and NULL max and zero size return -1.
* c-decl.c (get_parm_array_spec): Bail out of nelts is
error_operand_p.
* gcc.dg/pr97860.c: New test.
Diffstat (limited to 'gcc/c/c-decl.c')
-rw-r--r-- | gcc/c/c-decl.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index d348e39..1b02240 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5775,6 +5775,8 @@ get_parm_array_spec (const struct c_parm *parm, tree attrs) type = TREE_TYPE (type)) { tree nelts = array_type_nelts (type); + if (error_operand_p (nelts)) + return attrs; if (TREE_CODE (nelts) != INTEGER_CST) { /* Each variable VLA bound is represented by the dollar |