[Bug middle-end/78837] New: missing -Walloca-larger-than on a call in a ternary expression

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Dec 16 22:01:00 GMT 2016


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

            Bug ID: 78837
           Summary: missing -Walloca-larger-than on a call in a ternary
                    expression
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Both -Walloca-larger-than and -Walloc-larger-than fail to diagnose calls where
the called function is the result of a ternary operator, as in (n < 123 ?
alloca : malloc)(n): 

$ cat d.c && gcc -O2 -S -Walloca-larger-than=10 -Walloc-size-larger-than=10 d.c
void f0 (void*);

void f1 (unsigned n)
{
  void *p;

  if (n < 32)
    n = 32;

  if (n < 123)
    p = __builtin_alloca (n);
  else
    p = __builtin_malloc (n);

  f0 (p);
}

void f2 (unsigned n)
{
  if (n < 32)
    n = 32;

  void *p = (123 < n ? __builtin_malloc: __builtin_alloca)(n);   // missing
warning
  f0 (p);
}
d.c: In function ‘f1’:
d.c:11:7: warning: argument to ‘alloca’ may be too large
[-Walloca-larger-than=]
     p = __builtin_alloca (n);
     ~~^~~~~~~~~~~~~~~~~~~~~~
d.c:11:7: note: limit is 10 bytes, but argument may be as large as 122
d.c:13:7: warning: argument 1 range [32, 4294967295] exceeds maximum object
size 10 [-Walloc-size-larger-than=]
     p = __builtin_malloc (n);
     ~~^~~~~~~~~~~~~~~~~~~~~~
d.c:13:7: note: in a call to built-in allocation function ‘__builtin_malloc’


More information about the Gcc-bugs mailing list