aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/c-decl.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr97860.c11
-rw-r--r--gcc/tree.c12
3 files changed, 24 insertions, 1 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
diff --git a/gcc/testsuite/gcc.dg/pr97860.c b/gcc/testsuite/gcc.dg/pr97860.c
new file mode 100644
index 0000000..04c0f19
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97860.c
@@ -0,0 +1,11 @@
+/* PR c/97860 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+foo (int n)
+{
+ typedef int T[0];
+ typedef T V[n];
+ void bar (V);
+}
diff --git a/gcc/tree.c b/gcc/tree.c
index 0043855..531fe96 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -3483,7 +3483,17 @@ array_type_nelts (const_tree type)
/* TYPE_MAX_VALUE may not be set if the array has unknown length. */
if (!max)
- return error_mark_node;
+ {
+ /* zero sized arrays are represented from C FE as complete types with
+ NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
+ them as min 0, max -1. */
+ if (COMPLETE_TYPE_P (type)
+ && integer_zerop (TYPE_SIZE (type))
+ && integer_zerop (min))
+ return build_int_cst (TREE_TYPE (min), -1);
+
+ return error_mark_node;
+ }
return (integer_zerop (min)
? max