public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter
Date: Fri, 23 Oct 2020 15:14:04 +0000	[thread overview]
Message-ID: <bug-97548-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97548

            Bug ID: 97548
           Summary: bogus -Wvla-parameter on a bound expression involving
                    a parameter
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

>From https://gcc.gnu.org/pipermail/gcc/2020-October/234036.html:

The warning on the redeclaration of g() is a false positive.

$ cat a.c && gcc -S -Wall a.c 
int n;

void f (int, int [n + 1]);
void f (int, int [n + 1]);     // ok

void g (int k, int [k + 1]);
void g (int k, int [k + 1]);   // bogus warning
a.c:7:16: warning: argument 2 of type ‘int[k + 1]’ declared with mismatched
bound ‘k + 1’ [-Wvla-parameter]
    7 | void g (int k, int [k + 1]);   // bogus warning
      |                ^~~~~~~~~~~
a.c:6:16: note: previously declared as ‘int[k + 1]’ with bound ‘k + 1’
    6 | void g (int k, int [k + 1]);
      |                ^~~~~~~~~~~

The warning code relies on operand_equal_p() to match the bounds.  The function
fails to match the bound expressions because the PARM_DECL referenced in each
is distinct.  The code in operand_compare::operand_equal_p() that fails to
match them is:

    case tcc_declaration:
      /* Consider __builtin_sqrt equal to sqrt.  */
      return (TREE_CODE (arg0) == FUNCTION_DECL
              && fndecl_built_in_p (arg0) && fndecl_built_in_p (arg1)
              && DECL_BUILT_IN_CLASS (arg0) == DECL_BUILT_IN_CLASS (arg1)
              && (DECL_UNCHECKED_FUNCTION_CODE (arg0)
                  == DECL_UNCHECKED_FUNCTION_CODE (arg1)));

The matching between two expressions will never be perfect but it should work
for the basic cases.

             reply	other threads:[~2020-10-23 15:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23 15:14 msebor at gcc dot gnu.org [this message]
2020-11-24  0:33 ` [Bug c/97548] " msebor at gcc dot gnu.org
2021-01-05 15:51 ` muecker at gwdg dot de
2021-07-02  1:03 ` msebor at gcc dot gnu.org
2021-07-15 16:23 ` cvs-commit at gcc dot gnu.org
2021-07-15 16:25 ` msebor at gcc dot gnu.org
2021-07-23 19:16 ` [Bug c/97548] [11 Regression] " msebor at gcc dot gnu.org
2021-07-23 19:41 ` msebor at gcc dot gnu.org
2021-07-28  7:05 ` rguenth at gcc dot gnu.org
2021-12-16 22:47 ` cvs-commit at gcc dot gnu.org
2022-03-17 19:45 ` msebor at gcc dot gnu.org

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=bug-97548-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: link
Be 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).