Right now, use of attribute((warning)) only triggers a warning when
encountering a direct call of a labeled function (line 13 in the example below)
or simple indirection that can trivially be reduced to a direct call (line 17).
 But there is a hole: any time the address of a function is not immediately
used for a function call, the warning is lost.  It would be nice if a warning
were instead issued at any place where the address of a function is taken (and
not further optimized out of the program), thus causing additional warnings on
lines 14 and 15 in the example.  After all, the resulting function calls in
lines 14 and 16 are no safer than any of the other calls in the example.

$ cat foo.c
static int oops (int) __attribute__ ((__warning__ ("message")));

static int
oops (int x)
{
  return x;
}

int
main (int argc, char **argv)
{
  int (*func) (int);
  oops (1);
  (func = &oops) (1);
  func = oops;
  func (1);
  (&oops) (1);
  return 0;
}
$ gcc -o foo foo.c
foo.c: In function ‘main’:
foo.c:13: warning: call to ‘oops’ declared with attribute warning: message
foo.c:17: warning: call to ‘oops’ declared with attribute warning: message
$


-- 
           Summary: attribute((warning(""))) should warn on function
                    addresses
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ebb9 at byu dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42384

Reply via email to