Bug 15574 - inappropriate optimization of printf()
Summary: inappropriate optimization of printf()
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.4
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-21 19:22 UTC by Serge Belyshev
Modified: 2019-06-14 17:52 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
testcase (144 bytes) (109 bytes, text/plain)
2004-05-21 19:22 UTC, Serge Belyshev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Belyshev 2004-05-21 19:22:12 UTC
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
Comment 1 Serge Belyshev 2004-05-21 19:22:56 UTC
Created attachment 6358 [details]
testcase (144 bytes)
Comment 2 Andrew Pinski 2004-05-21 19:27:07 UTC
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.
Comment 3 Wolfgang Bangerth 2004-05-21 19:34:41 UTC
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. 
Comment 4 Andrew Pinski 2005-12-30 23:05:42 UTC
*** Bug 25609 has been marked as a duplicate of this bug. ***