[Bug c/97548] New: bogus -Wvla-parameter on a bound expression involving a parameter

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Oct 23 15:14:04 GMT 2020


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.


More information about the Gcc-bugs mailing list