Bug 168300 - Spurious -Wunreachable-code message when using -Wp,-D_FORTIFY_SOURCE=2
Summary: Spurious -Wunreachable-code message when using -Wp,-D_FORTIFY_SOURCE=2
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2005-09-14 17:14 UTC by Ralf Ertzinger
Modified: 2007-11-30 22:11 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-09-19 08:23:54 UTC
Type: ---
Embargoed:


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

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.



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