/* When a function has been defined using the 'noreturn' attribute, * there is no reason to save the callee-saved registers, mainly * because the function is not going to return to the caller. * * This can save a few bytes of code generation for embedded-type * applications which may use 'noreturn' functions to restart, for * example, by jumping to a different address rather than returning to * the caller. * * gcc information: * * Using built-in specs. * Target: x86_64-redhat-linux * * Configured with: ../configure --prefix=/usr --mandir=/usr/share/man * --infodir=/usr/share/info --enable-shared * --enable-threads=posix --enable-checking=release * --with-system-zlib --enable-__cxa_atexit * --disable-libunwind-exceptions --enable-libgcj-multifile * --enable-languages=c,c++,objc,obj-c++,java,fortran,ada * --enable-java-awt=gtk --disable-dssi --enable-plugin * --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre * --with-cpu=generic --host=x86_64-redhat-linux * Thread model: posix * gcc version 4.1.2 20071124 (Red Hat 4.1.2-42) * * compilation & disassembly information: * * gcc -c -O3 -o noreturn.o noreturn.c * objdump --disassemble --reloc noreturn.o * * Notice in the disassembly of 'return_to_caller' that the * registers pushed in the preamble are restored before * returning. But, in the 'no_return_to_caller', they are not * restored; since they are no restored, there is no reason to * even save them. */ #include <stdlib.h>
extern unsigned array[1024][1024][1024]; extern unsigned value(int i, int j, int k); #define LOOP_BODY \ do { \ unsigned i, j, k; \ for (i = 1024; i > 0; --i) { \ for (j = 1024; j > 0; --j) { \ for (k = 1024; k > 0; --k) { \ array[i - 1][j - 1][k - 1] = value(i, j, k); \ } \ } \ } \ } while (0) void return_to_caller(int a, int b, int c, int d) { LOOP_BODY; } void __attribute__((noreturn)) no_return_to_caller(int a, int b, int c, int d) { LOOP_BODY; while (1); } -- Summary: gcc 4.2.1 and above: No need to save called-saved registers in 'noreturn' function Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: thutt at vmware dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38534