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

            Bug ID: 86244
           Summary: misleading use of "may be too large" in
                    -Walloca-larger-than and -Wvla-larger-than warnings
                    involving ranges
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

While testing some changes to -Walloca-larger-than and -Wvla-larger-than I
noticed that the messages issued by the warnings are somewhat misleading in
cases when the alloca/VLA argument is in a range whose lower bound exceeds the
specified threshold.  The message uses the phrase "may be too large" even
though the argument definitely is too large.

For comparison, the test case below shows the different format and wording of
the three diagnostics.  It would be nice to make them all consistent (maybe
even by using the same function to issue them).

$ cat d.c && gcc -S -O2 -Wall -Walloc-size-larger-than=1 -Walloca-larger-than=1
-Wvla-larger-than=1 d.c
void f (void*);

void g (unsigned n)
{
  if (n < 5 || 7 < n)
    n = 5;

  void *p = __builtin_malloc (n);   // warning: n exceeds object size (good)
  f (p);
}

void h (unsigned n)
{
  n = 5;

  void *p = __builtin_alloca (n);   // warning: n is too large (good)
  f (p);
}


void i (unsigned n)
{
  if (n < 5 || 7 < n)
    n = 5;

  char a[n];   // warning: n may be too large even though it definitely is
  f (a);
}
d.c: In function ‘g’:
d.c:8:13: warning: argument 1 range [5, 7] exceeds maximum object size 1
[-Walloc-size-larger-than=]
   void *p = __builtin_malloc (n);   // warning: n exceeds object size (good)
             ^~~~~~~~~~~~~~~~~~~~
d.c:8:13: note: in a call to built-in allocation function ‘__builtin_malloc’
d.c: In function ‘h’:
d.c:16:13: warning: argument to ‘alloca’ is too large [-Walloca-larger-than=]
   void *p = __builtin_alloca (n);   // warning: n is too large (good)
             ^~~~~~~~~~~~~~~~~~~~
d.c:16:13: note: limit is 1 bytes, but argument is 5
d.c: In function ‘i’:
d.c:26:8: warning: argument to variable-length array may be too large
[-Wvla-larger-than=]
   char a[n];   // warning: n may be too large even though it definitely is
        ^
d.c:26:8: note: limit is 1 bytes, but argument may be as large as 7

Reply via email to