public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/32811]  New: Cannot flag inline assembler code "noreturn"
@ 2007-07-18 17:46 us15 at os dot inf dot tu-dresden dot de
  2007-07-18 18:31 ` [Bug inline-asm/32811] " pinskia at gcc dot gnu dot org
  2010-07-13 23:19 ` adam at consulting dot net dot nz
  0 siblings, 2 replies; 3+ messages in thread
From: us15 at os dot inf dot tu-dresden dot de @ 2007-07-18 17:46 UTC (permalink / raw)
  To: gcc-bugs

For a function declared "noreturn" the compiler cannot verify that inline
assembler code in the function body indeed does not return and therefore
produces the warning "'noreturn' function does return". I would like a
mechanism to tell the compiler that an inline assembler statement makes a
function "noreturn" without the overhead of adding an endless loop at the end
of the function. Something like: asm volatile ("...") __attribute__((noreturn))

An example:

__attribute__((noreturn))
void func()
{
    asm volatile ("1: jmp 1b");
}

int main()
{
    func();
    return 0;
}


-- 
           Summary: Cannot flag inline assembler code "noreturn"
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: us15 at os dot inf dot tu-dresden dot de


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug inline-asm/32811] Cannot flag inline assembler code "noreturn"
  2007-07-18 17:46 [Bug inline-asm/32811] New: Cannot flag inline assembler code "noreturn" us15 at os dot inf dot tu-dresden dot de
@ 2007-07-18 18:31 ` pinskia at gcc dot gnu dot org
  2010-07-13 23:19 ` adam at consulting dot net dot nz
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-18 18:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-07-18 18:31 -------
I think this is expected and maybe not going to be fixed as inline-asm cannot
change the control flow at all.


-- 


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug inline-asm/32811] Cannot flag inline assembler code "noreturn"
  2007-07-18 17:46 [Bug inline-asm/32811] New: Cannot flag inline assembler code "noreturn" us15 at os dot inf dot tu-dresden dot de
  2007-07-18 18:31 ` [Bug inline-asm/32811] " pinskia at gcc dot gnu dot org
@ 2010-07-13 23:19 ` adam at consulting dot net dot nz
  1 sibling, 0 replies; 3+ messages in thread
From: adam at consulting dot net dot nz @ 2010-07-13 23:19 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1782 bytes --]



------- Comment #2 from adam at consulting dot net dot nz  2010-07-13 23:19 -------
This issue needs to be revisited with the advent of asm goto:

__attribute__ ((noreturn)) void noreturn_via_asm_goto() {
 loop:
  asm goto ("jmp %l[loop]\n" : : : : loop);
}

int main() {}

$ gcc-4.5 -std=gnu99 -O3 noreturn.c && objdump -d -m i386:x86-64:intel|less
noreturn.c: In function ‘noreturn_via_asm_goto’:
noreturn.c:4:1: warning: ‘noreturn’ function does return

00000000004004c0 <noreturn_via_asm_goto>:
  4004c0:       eb fe                   jmp    4004c0 <noreturn_via_asm_goto>
  4004c2:       c3                      ret    
  4004c3:       66 66 66 66 2e 0f 1f    nop    WORD PTR cs:[rax+rax*1+0x0]
  4004ca:       84 00 00 00 00 00 

The warning is spurious and the return instruction is not elided. This can
matter with threaded interpreters jumping to/from code with a native code
length equal to a multiple of 16 bytes. In the worse case this extra byte can
double the space consumed by hundreds of tiny functions.

Best approach would be to actually trust the programmer's use of the noreturn
explicit compiler directive in all circumstances. Do not emit a return
instruction when the compiler has been explicitly told that a particular
function does not return. By all means warn that it appears to the compiler
that the code path is going to drop through to the next address in memory.

Thanks,
Adam


-- 

adam at consulting dot net dot nz changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |adam at consulting dot net
                   |                            |dot nz


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-13 23:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-18 17:46 [Bug inline-asm/32811] New: Cannot flag inline assembler code "noreturn" us15 at os dot inf dot tu-dresden dot de
2007-07-18 18:31 ` [Bug inline-asm/32811] " pinskia at gcc dot gnu dot org
2010-07-13 23:19 ` adam at consulting dot net dot nz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).