Bug 168300 - Spurious -Wunreachable-code message when using -Wp,-D_FORTIFY_SOURCE=2
Spurious -Wunreachable-code message when using -Wp,-D_FORTIFY_SOURCE=2
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2005-09-14 13:14 EDT by Ralf Ertzinger
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-09-19 04:23:54 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Compiler test case (511 bytes, text/plain)
2005-09-14 13:14 EDT, Ralf Ertzinger
no flags Details

  None (edit)
Description Ralf Ertzinger 2005-09-14 13:14:20 EDT
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):

How reproducible:

Steps to Reproduce:
1. Compile attached code with command line above
Actual results:
"will never be executed" warnings

Expected results:
no warnings

Additional info:
Comment 1 Ralf Ertzinger 2005-09-14 13:14:20 EDT
Created attachment 118810 [details]
Compiler test case
Comment 2 Jakub Jelinek 2005-09-19 04:23:54 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.