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

            Bug ID: 109395
           Summary: -Wvla-larger-than has no effect when compiling without
                    optimizations
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dev at joren dot ga
  Target Milestone: ---

Let's take the following for an example:

    int bar(int n, int[n]);

    void foo(int n)
    {
        int arr[n];
        for (int i = 0; i < n; ++i) {
            arr[i] = i;
        }
        bar(n, arr);
    }

When compiled with 

    $ gcc -O -Wvla-larger-than=0 -c foo.c

a warning is shown as expected:

    foo.c: In function ‘foo’:
    foo.c:5:9: warning: argument to variable-length array may be too large
[-Wvla-larger-than=]
        5 |     int arr[n];
          |         ^~~

It works with -O, -O1, -O2, -O3, -Os, -Oz, -Ofast

On the other hand, when compiling with -O0, -Og or no -O flag, no warning is
triggered (https://godbolt.org/z/Penjbqojh).

I've tried to find if only a flag implied by optimization is required, but to
no avail.

Reply via email to