Bug 168300

Summary: Spurious -Wunreachable-code message when using -Wp,-D_FORTIFY_SOURCE=2
Product: [Fedora] Fedora Reporter: Ralf Ertzinger <redhat-bugzilla>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: rawhide   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-09-19 08:23:54 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Compiler test case none

Description Ralf Ertzinger 2005-09-14 17:14:20 UTC
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):
gcc-4.0.1-13


How reproducible:
Always

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

Expected results:
no warnings

Additional info:

Comment 1 Ralf Ertzinger 2005-09-14 17:14:20 UTC
Created attachment 118810 [details]
Compiler test case

Comment 2 Jakub Jelinek 2005-09-19 08:23:54 UTC
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.