Red Hat Bugzilla – Bug 168300
Spurious -Wunreachable-code message when using -Wp,-D_FORTIFY_SOURCE=2
Last modified: 2007-11-30 17:11:13 EST
Description of problem:
The source code attached to this bug gives the following warning
if compiled with
gcc -O2 -c -Wp,-D_FORTIFY_SOURCE=2 -Wunreachable-code -o test.o test.c
test.c: In function âtestâ:
test.c:26: warning: will never be executed
I think this is bogus, if the malloc() succeeds the strcpy() in this
line will be executed.
Dropping -Wp,-D_FORTIFY_SOURCE=2 or -O2 from the compiler command line
makes the message go away.
Replacing the single strcasecmp in the source with strcmp makes
a lot more "will never be executed" warnings pop up.
Please note that the source attached is a stripped-down
version of a longer piece of code where the operations
actually make some kind of sense :)
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Compile attached code with command line above
"will never be executed" warnings
Created attachment 118810 [details]
Compiler test case
That's not spurious, there is really unreachable code, but that's correct.
I'd say _FORTIFY_SOURCE and -Wunreachable-code warning are mutual exclusive
choices, similarly to using debugging code etc. See -Wunreachable-code's
description in man gcc or info gcc, particularly:
This option is not made part of `-Wall' because in a debugging
version of a program there is often substantial code which checks
correct functioning of the program and is, hopefully, unreachable
because the program does work. Another common use of unreachable
code is to provide behavior which is selectable at compile-time.