public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98536] New: warning  with  -Wvla-parameter for unspecified bound getting specified later
@ 2021-01-05 15:59 muecker at gwdg dot de
  2021-01-05 18:08 ` [Bug c/98536] " msebor at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: muecker at gwdg dot de @ 2021-01-05 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98536
           Summary: warning  with  -Wvla-parameter for unspecified bound
                    getting specified later
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: muecker at gwdg dot de
  Target Milestone: ---

There is a warning in the following case:


void foo(double x[*]);

void foo(double x[3]) { .. }

or

int n;
void foo(double x[n]) { .. }


should be OK as the bound are compatible.
The type just becomes more specific which should be allowed.

In fact, this is the intended use case of '*' which would otherwise be useless.

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

* [Bug c/98536] warning  with  -Wvla-parameter for unspecified bound getting specified later
  2021-01-05 15:59 [Bug c/98536] New: warning with -Wvla-parameter for unspecified bound getting specified later muecker at gwdg dot de
@ 2021-01-05 18:08 ` msebor at gcc dot gnu.org
  2021-01-05 20:13 ` muecker at gwdg dot de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-05 18:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning in both cases (reproduced below) is to encourage specifying the
bounds in declarations and discourage the use of [*].  At some point [*] needs
to be replaced by an actual bound so it might as well be done at the point of
the declaration where it can be used by tools for bounds checking.  I see [*]
as analogous to a function without a prototype.  Both have some uses that can't
be easily achieved by other means but both are dangerous and best avoided.

$ gcc -S -Wall pr98536.c
pr98536.c:2:17: warning: argument 1 of type ‘double[3]’ declared as an ordinary
array [-Wvla-parameter]
    2 | void foo(double x[3]) { }
      |          ~~~~~~~^~~~
pr98536.c:1:17: note: previously declared as a variable length array
‘double[*]’
    1 | void foo(double x[*]);
      |          ~~~~~~~^~~~
pr98536.c:5:17: warning: argument 1 of type ‘double[*]’ declared with 1
unspecified variable bound [-Wvla-parameter]
    5 | void bar(double x[*]);
      |          ~~~~~~~^~~~
pr98536.c:6:17: note: subsequently declared as ‘double[n]’ with 0 unspecified
variable bounds
    6 | void bar(double x[n]) { }
      |          ~~~~~~~^~~~

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

* [Bug c/98536] warning  with  -Wvla-parameter for unspecified bound getting specified later
  2021-01-05 15:59 [Bug c/98536] New: warning with -Wvla-parameter for unspecified bound getting specified later muecker at gwdg dot de
  2021-01-05 18:08 ` [Bug c/98536] " msebor at gcc dot gnu.org
@ 2021-01-05 20:13 ` muecker at gwdg dot de
  2023-08-05 16:10 ` cvs-commit at gcc dot gnu.org
  2023-11-03 19:23 ` uecker at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: muecker at gwdg dot de @ 2021-01-05 20:13 UTC (permalink / raw)
  To: gcc-bugs

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

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

The whole point of '*' is to have a way to not specify the bound. It is a very
explicit way of saying that I can't (or don't want) to specify the bound.

In contrast of not specifying anything, i.e. [], which might be careless
omission. So in the later case, I think the warning makes sense but for '*' it
should not be on by default.

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

* [Bug c/98536] warning  with  -Wvla-parameter for unspecified bound getting specified later
  2021-01-05 15:59 [Bug c/98536] New: warning with -Wvla-parameter for unspecified bound getting specified later muecker at gwdg dot de
  2021-01-05 18:08 ` [Bug c/98536] " msebor at gcc dot gnu.org
  2021-01-05 20:13 ` muecker at gwdg dot de
@ 2023-08-05 16:10 ` cvs-commit at gcc dot gnu.org
  2023-11-03 19:23 ` uecker at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-05 16:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:39f413fc4b6979d194f2f736bd663eb7f5045168

commit r14-3005-g39f413fc4b6979d194f2f736bd663eb7f5045168
Author: Martin Uecker <uecker@tugraz.at>
Date:   Thu Apr 13 19:35:15 2023 +0200

    c: Less warnings for parameters declared as arrays [PR98536]

    To avoid false positivies, tune the warnings for parameters declared
    as arrays with size expressions.  Do not warn when more bounds are
    specified in the declaration than before.

            PR c/98536

    gcc/c-family/:
            * c-warn.cc (warn_parm_array_mismatch): Do not warn if more
            bounds are specified.

    gcc/testsuite:
            * gcc.dg/Wvla-parameter-4.c: Adapt test.
            * gcc.dg/attr-access-2.c: Adapt test.

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

* [Bug c/98536] warning  with  -Wvla-parameter for unspecified bound getting specified later
  2021-01-05 15:59 [Bug c/98536] New: warning with -Wvla-parameter for unspecified bound getting specified later muecker at gwdg dot de
                   ` (2 preceding siblings ...)
  2023-08-05 16:10 ` cvs-commit at gcc dot gnu.org
@ 2023-11-03 19:23 ` uecker at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: uecker at gcc dot gnu.org @ 2023-11-03 19:23 UTC (permalink / raw)
  To: gcc-bugs

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

uecker at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |11.1.0
   Target Milestone|---                         |14.0
                 CC|                            |uecker at gcc dot gnu.org
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from uecker at gcc dot gnu.org ---
Fixed on trunk.

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

end of thread, other threads:[~2023-11-03 19:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 15:59 [Bug c/98536] New: warning with -Wvla-parameter for unspecified bound getting specified later muecker at gwdg dot de
2021-01-05 18:08 ` [Bug c/98536] " msebor at gcc dot gnu.org
2021-01-05 20:13 ` muecker at gwdg dot de
2023-08-05 16:10 ` cvs-commit at gcc dot gnu.org
2023-11-03 19:23 ` uecker 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).