https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61739
Bug ID: 61739
Summary: __builtin_printf optimization conflicts with POSIX
semantics
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: bugdal at aerifal dot cx
Created attachment 33086
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33086&action=edit
test case
Per POSIX,
"All functions that reference (FILE *) objects, except those with names ending
in _unlocked, shall behave as if they use flockfile() and funlockfile()
internally to obtain ownership of these (FILE *) objects."
Source:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/flockfile.html
GCC's transformation that eliminates printf("") causes this requirement to be
ignored; the calling thread is allowed to proceed even if a lock on stdout held
by another thread should block printf.
The included test-case demonstrates the issue. It should deadlock, and indeed
it does with -fno-builtin. But with the default settings, the program
terminates normally.
Additional thoughts on the above POSIX requirement are on a blog post I wrote a
while back, http://ewontfix.com/8/