Bug 42384 - attribute((warning(""))) should warn on function addresses
Summary: attribute((warning(""))) should warn on function addresses
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.3.4
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2009-12-15 21:16 UTC by Eric Blake
Modified: 2021-08-29 22:53 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Blake 2009-12-15 21:16:20 UTC
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
$