https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78098
--- Comment #11 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Martin Liška from comment #10)
> (In reply to H.J. Lu from comment #9)
> > (In reply to Richard Biener from comment #6)
> > > Why would we be not able to tailcall in an interupt handler?
> >
> > We need to verify that the only instruction in an interrupt handler
> > is a tail call to another interrupt handler. On the other hand,
> > this interrupt handler isn't really needed at all.
>
> That can be vefief by fact that the symbol should have only one call (tail
> call) and set node->icf_merged == true.
My current change:
@ -28014,7 +28026,19 @@ ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
if (fndecl
&& (lookup_attribute ("interrupt",
TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))))
- error ("interrupt service routine can't be called directly");
+ {
+ if (lookup_attribute ("interrupt",
+ TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl))))
+ {
+ error ("interrupt service routine %q+D can't be called directly",
+ fndecl);
+ inform (input_location,
+ "is interrupt service routine %q+D equivalent to %q+D?",
+ fndecl, cfun->decl);
+ }
+ else
+ error ("interrupt service routine can't be called directly");
+ }
}
else
fndecl = NULL_TREE;
gives
/export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -Os -m32 -mno-sse -mno-mmx
-mno-80387 -S -o foo1.s foo1.i
foo1.i: In function ‘foo1’:
foo1.i:10:33: error: interrupt service routine ‘foo2’ can't be called directly
__attribute__((interrupt)) void foo2 (void *p)
^~~~
foo1.i:4:6: note: is interrupt service routine ‘foo2’ equivalent to ‘foo1’?
void foo1 (void *p)
^~~~
Makefile:34: recipe for target 'foo1.s' failed
make: *** [foo1.s] Error 1
[hjl@gnu-6 pr78098]$
Since foo1 == foo2, there is no reason for foo2 at all. It reduces
the code size, which is very important in embedded environment.