From 2c2148d8c144d7388abcb7c34b782be647fe81c9 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Wed, 17 Nov 2021 11:51:33 -0700 Subject: Handle folded nonconstant array bounds [PR101702] PR c/101702 - ICE: in handle_argspec_attribute, at c-family/c-attribs.c:3623 gcc/c/ChangeLog: PR c/101702 * c-decl.c (get_parm_array_spec): Strip casts earlier and fold array bounds before deciding if they're constant. gcc/testsuite/ChangeLog: PR c/101702 * gcc.dg/Warray-parameter-11.c: New test. --- gcc/c/c-decl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'gcc/c') diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 186fa16..63d806a 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5866,6 +5866,12 @@ get_parm_array_spec (const struct c_parm *parm, tree attrs) if (pd->u.array.static_p) spec += 's'; + if (!INTEGRAL_TYPE_P (TREE_TYPE (nelts))) + /* Avoid invalid NELTS. */ + return attrs; + + STRIP_NOPS (nelts); + nelts = c_fully_fold (nelts, false, nullptr); if (TREE_CODE (nelts) == INTEGER_CST) { /* Skip all constant bounds except the most significant one. @@ -5883,13 +5889,9 @@ get_parm_array_spec (const struct c_parm *parm, tree attrs) spec += buf; break; } - else if (!INTEGRAL_TYPE_P (TREE_TYPE (nelts))) - /* Avoid invalid NELTS. */ - return attrs; /* Each variable VLA bound is represented by a dollar sign. */ spec += "$"; - STRIP_NOPS (nelts); vbchain = tree_cons (NULL_TREE, nelts, vbchain); } -- cgit v1.1