[Bug c/68637] Array of function pointers with attribute leads to wrong code

hjl.tools at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Dec 2 16:26:00 GMT 2015


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

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
Run-time test:

[hjl@gnu-6 pr68637]$ cat x.i
extern void (*bar[]) (int, int) __attribute__ ((regparm (2)));

void
foo (void)
{
  bar[0] (1, 2);
}
[hjl@gnu-6 pr68637]$ cat main.i
static void 
__attribute__ ((regparm (2)))
bar0 (int i, int j)
{
  if (i != 1 || j != 2)
    __builtin_abort ();
}

typedef void (*func_t) (int, int) __attribute__ ((regparm (2)));

func_t bar[] =
{
  bar0,
};

extern void foo (void);

int
main ()
{
  foo ();
  return 0;
}
[hjl@gnu-6 pr68637]$ make CC=gcc x
gcc -O2 -m32 -S -o x.s x.i
x.i:1:1: warning: ‘regparm’ attribute only applies to function types
[-Wattributes]
 extern void (*bar[]) (int, int) __attribute__ ((regparm (2)));
 ^
gcc -O2 -m32 -S -o main.s main.i
gcc -O2 -m32 -o x x.s main.s
[hjl@gnu-6 pr68637]$ ./x
Aborted
[hjl@gnu-6 pr68637]$


More information about the Gcc-bugs mailing list