public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter
@ 2020-10-23 15:14 msebor at gcc dot gnu.org
  2020-11-24  0:33 ` [Bug c/97548] " msebor at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-10-23 15:14 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
@ 2020-11-24  0:33 ` msebor at gcc dot gnu.org
  2021-01-05 15:51 ` muecker at gwdg dot de
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-11-24  0:33 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-11-24

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
  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
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: muecker at gwdg dot de @ 2021-01-05 15:51 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Uecker <muecker at gwdg dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |muecker at gwdg dot de

--- Comment #1 from Martin Uecker <muecker at gwdg dot de> ---

I get many false positives for this reason. So if the logic cannot understand
these expressions, it should bail out ad not warn (or only for some higher
warning levels) to avoid these false positives.

Also it is often useful to have these complex expressions for bounds in
mathematical code, especially with multiple array parameters which have
different lengths but depend on the same variable.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
  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
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-02  1:03 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
      Known to fail|                            |11.1.0
   Target Milestone|---                         |11.2

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-July/574310.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-15 16:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:98f1f9f38c45218c06200feb1939c9433a2ab6ca

commit r12-2329-g98f1f9f38c45218c06200feb1939c9433a2ab6ca
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu Jul 15 10:11:23 2021 -0600

    Avoid -Wvla-parameter for nontrivial bounds [PR97548].

    Resolves:
    PR c/101289 - bogus -Wvla-paramater warning when using const for vla param
    PR c/97548 -  bogus -Wvla-parameter on a bound expression involving a
parameter

    gcc/c-family/ChangeLog:

            PR c/101289
            PR c/97548
            * c-warn.c (warn_parm_array_mismatch): Use OEP_DECL_NAME.

    gcc/c/ChangeLog:

            PR c/101289
            PR c/97548
            * c-decl.c (get_parm_array_spec): Strip nops.

    gcc/ChangeLog:

            PR c/101289
            PR c/97548
            * fold-const.c (operand_compare::operand_equal_p): Handle
OEP_DECL_NAME.
            (operand_compare::verify_hash_value): Same.
            * tree-core.h (OEP_DECL_NAME): New.

    gcc/testsuite/ChangeLog:

            * gcc.dg/Wvla-parameter-12.c: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-15 16:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed for GCC 12.0.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] [11 Regression] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-07-15 16:25 ` msebor at gcc dot gnu.org
@ 2021-07-23 19:16 ` msebor at gcc dot gnu.org
  2021-07-23 19:41 ` msebor at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-23 19:16 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|bogus -Wvla-parameter on a  |[11 Regression] bogus
                   |bound expression involving  |-Wvla-parameter on a bound
                   |a parameter                 |expression involving a
                   |                            |parameter

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC 10 doesn't warn (it doesn't provide -Wvla-parameter) so it's a regression.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] [11 Regression] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-23 19:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
The fix isn't very robust since it only handles redeclarations with VLA
parameters that involve bounds that have the same name but not nontrivial
expressions involving different names, like in this case:

$ cat pr97548-c6.c && gcc -S -Wall pr97548-c6.c
void g (int k, int [k + 1]);
void g (int m, int [m + 1]) { }   // bogus warning
pr97548-c6.c:2:16: warning: argument 2 of type ‘int[m + 1]’ declared with
mismatched bound ‘m + 1’ [-Wvla-parameter]
    2 | void g (int m, int [m + 1]) { }   // bogus warning
      |                ^~~~~~~~~~~
pr97548-c6.c:1:16: note: previously declared as ‘int[k + 1]’ with bound ‘k + 1’
    1 | void g (int k, int [k + 1]);
      |                ^~~~~~~~~~~

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] [11 Regression] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-28  7:05 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.2                        |11.3

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.2 is being released, retargeting bugs to GCC 11.3

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] [11 Regression] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-16 22:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Martin Sebor
<msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:7d3f53c595e1766ca0494e5f56f33b0ce49b3bb4

commit r11-9396-g7d3f53c595e1766ca0494e5f56f33b0ce49b3bb4
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu Jul 15 10:11:23 2021 -0600

    Avoid -Wvla-parameter for nontrivial bounds [PR97548].

    Resolves:
    PR c/101289 - bogus -Wvla-paramater warning when using const for vla param
    PR c/97548 -  bogus -Wvla-parameter on a bound expression involving a
parameter

    gcc/c-family/ChangeLog:

            PR c/101289
            PR c/97548
            * c-warn.c (warn_parm_array_mismatch): Use OEP_DECL_NAME.

    gcc/c/ChangeLog:

            PR c/101289
            PR c/97548
            * c-decl.c (get_parm_array_spec): Strip nops.

    gcc/ChangeLog:

            PR c/101289
            PR c/97548
            * fold-const.c (operand_compare::operand_equal_p): Handle
OEP_DECL_NAME.
            (operand_compare::verify_hash_value): Same.
            * tree-core.h (OEP_DECL_NAME): New.

    gcc/testsuite/ChangeLog:

            * gcc.dg/Wvla-parameter-12.c: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/97548] [11 Regression] bogus -Wvla-parameter on a bound expression involving a parameter
  2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2021-12-16 22:47 ` cvs-commit at gcc dot gnu.org
@ 2022-03-17 19:45 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-03-17 19:45 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #9 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-03-17 19:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23 15:14 [Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter msebor at gcc dot gnu.org
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

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).