public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Sebor <msebor@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5347] Handle folded nonconstant array bounds [PR101702] Date: Wed, 17 Nov 2021 18:53:07 +0000 (GMT) [thread overview] Message-ID: <20211117185307.11C1E3858409@sourceware.org> (raw) https://gcc.gnu.org/g:2c2148d8c144d7388abcb7c34b782be647fe81c9 commit r12-5347-g2c2148d8c144d7388abcb7c34b782be647fe81c9 Author: Martin Sebor <msebor@redhat.com> Date: Wed Nov 17 11:51:33 2021 -0700 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. Diff: --- gcc/c/c-decl.c | 10 ++++++---- gcc/testsuite/gcc.dg/Warray-parameter-11.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 186fa1692c1..63d806a84c9 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); } diff --git a/gcc/testsuite/gcc.dg/Warray-parameter-11.c b/gcc/testsuite/gcc.dg/Warray-parameter-11.c new file mode 100644 index 00000000000..8ca1b55bd28 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-parameter-11.c @@ -0,0 +1,24 @@ +/* PR c/101702 - ICE on invalid function redeclaration + { dg-do compile } + { dg-options "-Wall" } */ + +typedef __INTPTR_TYPE__ intptr_t; + +#define copysign(x, y) __builtin_copysign (x, y) + +void f0 (double[!copysign (~2, 3)]); + +void f1 (double[!copysign (~2, 3)]); +void f1 (double[1]); // { dg-warning "-Warray-parameter" } + +void f2 (int[(int)+1.0]); +void f2 (int[(int)+1.1]); + +/* Also verify that equivalent expressions don't needlessly cause false + positives or negatives. */ +struct S { int a[1]; }; +extern struct S *sp; + +void f3 (int[(intptr_t)((char*)sp->a - (char*)sp)]); +void f3 (int[(intptr_t)((char*)&sp->a[0] - (char*)sp)]); +void f3 (int[(intptr_t)((char*)&sp->a[1] - (char*)sp)]); // { dg-warning "-Warray-parameter" }
reply other threads:[~2021-11-17 18:53 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211117185307.11C1E3858409@sourceware.org \ --to=msebor@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).