cat > bug.i << EOF void abort (); int printf (const char *, ...); int puts (const char *s) { abort (); } int main () { printf ("hello, world\n"); return 0; } EOF gcc bug.i -O ./a.out Aborted
Created attachment 6358 [details] testcase (144 bytes)
Invalid as the compiler should assume that there is a C runtime which has the runtime specifics of the C89 standard, if you want the compiler not to optimize the printf to puts use -fno-builtins.
Indeed. The functions in the C library are reserved. If you replace them with your own implementations, you invoke undefined behavior. (Note that a simple implementation of printf might actually check internally whether there are any % signs in the text, and if not pass the string on to puts -- that's certainly a case you will have to allow.) W.
*** Bug 25609 has been marked as a duplicate of this bug. ***