public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
@ 2003-10-18 4:25 rmerkert at alphatech dot com
2003-10-18 4:29 ` [Bug c++/12668] " pinskia at gcc dot gnu dot org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: rmerkert at alphatech dot com @ 2003-10-18 4:25 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12668
Summary: Strange warnings with -O1 -Wunreachable-code in
3.3.1,3.3.2,3.4
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rmerkert at alphatech dot com
CC: gcc-bugs at gcc dot gnu dot org
The following code produces a strange warning when compiled with
-Wunrechable-code and optimization:
cat > test.c <<EOF
inline void foo (int x)
{
if (x!=0)
x = x + 1;
}
int main ()
{
foo(0);
/* if (0) { foo(1); } */
return 0;
}
EOF
gcc -O1 test.c -Wunreachable-code
The error message I get with both 3.3.1, 3.3.2, 3.4-20031001 is this:
test.c: In function `main':
test.c:4: warning: will never be executed
The message is somewhat misleading. I think it should either say something like:
test.c: In function 'foo':
test.c:4 warning: will never be executed
or
test.c: In function 'main':
test.8: warning: will never be executed
By the way, if compiled with g++, there will be an extra empty line the output:
test.c: In function `main':
test.c:4: warning: will never be executed
and if you uncomment line 10 you'll get 4 warnings with 3.4 and 3 warnings with
3.3 and they are not helpful (gcc-3.3 doesn't even tell me about line 10).
I'm actually not sure I want the warning in this case - I really want the
compiler to tell me that a section of code cannot possibly be reached such as
"while (false) {}"
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
2003-10-18 4:25 [Bug c++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4 rmerkert at alphatech dot com
@ 2003-10-18 4:29 ` pinskia at gcc dot gnu dot org
2003-10-18 13:51 ` rmerkert at alphatech dot com
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-18 4:29 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12668
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2003-10-18 04:25:22
date| |
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-10-18 04:25 -------
-O1 enables inlining so that foo is inlined and the warning is right when x is always 0 because that
line is never executed in the line version.
What is wrong is when you enable line 10, it says that line 2 is never executed twice. It should
never tell you that line 2 is not executed at all (because there is no code assocated with it).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
2003-10-18 4:25 [Bug c++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4 rmerkert at alphatech dot com
2003-10-18 4:29 ` [Bug c++/12668] " pinskia at gcc dot gnu dot org
@ 2003-10-18 13:51 ` rmerkert at alphatech dot com
2003-10-18 14:05 ` rmerkert at alphatech dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rmerkert at alphatech dot com @ 2003-10-18 13:51 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12668
------- Additional Comments From rmerkert at alphatech dot com 2003-10-18 13:24 -------
I still think that the warning is not very helpful. Consider this program instead:
cat > test.c <<EOF
inline void foo (int x)
{
if (x!=0)
x = x + 1;
}
int main ()
{
foo(-1);
foo(0);
foo(1);
foo(2);
return 0;
}
EOF
gcc -O1 test.c -Wunreachable-code
This will give exactly the same warning as before:
main.c: In function `main':
main.c:4: warning: will never be executed
The warning is completely useless. The warning is not even pointing me to the
root cause which is the call to foo(0).
I think that the warning should be something like this:
main.c: In function `main':
main.c:10: warning: call to foo has been optimized away
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
2003-10-18 4:25 [Bug c++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4 rmerkert at alphatech dot com
2003-10-18 4:29 ` [Bug c++/12668] " pinskia at gcc dot gnu dot org
2003-10-18 13:51 ` rmerkert at alphatech dot com
@ 2003-10-18 14:05 ` rmerkert at alphatech dot com
2003-10-18 19:47 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rmerkert at alphatech dot com @ 2003-10-18 14:05 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12668
------- Additional Comments From rmerkert at alphatech dot com 2003-10-18 13:51 -------
One more example, where I don't really want to see warning:
cat > test.cpp <<EOF
#include <iostream>
struct Foo {
inline Foo (int x) : foo(0) {init(x); }
private:
inline void init (int x) {
if (x!=0)
foo = x + 1;
}
int foo;
};
struct Z {
Z (int x) : foo(0),z(x) {}
Foo foo;
int z;
};
int main (int argc, int argv)
{
Z z(argc);
::std::cerr << "Z: " << z.z << ::std::endl;
return 0;
}
EOF
g++ -O1 -Wunreachable-code test.cpp
The warning in this case is:
test.cpp: In function `int main(int, int)':
test.cpp:9: warning: will never be executed
There is no unreachable code in the example - it's just that
by choosing a certain parameter, a path in the program does not
need to be executed. That's not the same as being unreachable, that's
optimizing away things.
I've been getting lots of these warnings when I compile with O1 because of this
kind of situation. I think things are just propagated too far down the line.
What if I had 7 nested inlined functions that turn out to be "unreachable".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
2003-10-18 4:25 [Bug c++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4 rmerkert at alphatech dot com
` (2 preceding siblings ...)
2003-10-18 14:05 ` rmerkert at alphatech dot com
@ 2003-10-18 19:47 ` pinskia at gcc dot gnu dot org
2003-12-06 9:44 ` [Bug optimization/12668] " pinskia at gcc dot gnu dot org
2004-04-08 13:00 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-18 19:47 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12668
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-10-18 18:58 -------
That is the reason why -Wunreachable-code is not turned on by default or included in -W
(-Wextra) or -Wall.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug optimization/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
2003-10-18 4:25 [Bug c++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4 rmerkert at alphatech dot com
` (3 preceding siblings ...)
2003-10-18 19:47 ` pinskia at gcc dot gnu dot org
@ 2003-12-06 9:44 ` pinskia at gcc dot gnu dot org
2004-04-08 13:00 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-06 9:44 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-06 09:44 -------
Invalid as -Wunreachable-code is right no matter which way you look at it (do not use
-Wunreachable-code unless you want to know that placeswhere are unreachable in some cases).
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Component|c++ |optimization
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12668
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug optimization/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
2003-10-18 4:25 [Bug c++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4 rmerkert at alphatech dot com
` (4 preceding siblings ...)
2003-12-06 9:44 ` [Bug optimization/12668] " pinskia at gcc dot gnu dot org
@ 2004-04-08 13:00 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-08 13:00 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-08 13:00 -------
*** Bug 14889 has been marked as a duplicate of this bug. ***
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |jmarronn at rockwellcollins
| |dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12668
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-04-08 13:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-18 4:25 [Bug c++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4 rmerkert at alphatech dot com
2003-10-18 4:29 ` [Bug c++/12668] " pinskia at gcc dot gnu dot org
2003-10-18 13:51 ` rmerkert at alphatech dot com
2003-10-18 14:05 ` rmerkert at alphatech dot com
2003-10-18 19:47 ` pinskia at gcc dot gnu dot org
2003-12-06 9:44 ` [Bug optimization/12668] " pinskia at gcc dot gnu dot org
2004-04-08 13:00 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).