Bug 17078 - [3.4 regression] Jump into if(0)-substatement fails
Summary: [3.4 regression] Jump into if(0)-substatement fails
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.1
: P2 critical
Target Milestone: 3.4.2
Assignee: roger
URL:
Keywords: monitored, wrong-code
Depends on:
Blocks:
 
Reported: 2004-08-18 11:05 UTC by Paul Woegerer
Modified: 2004-10-30 21:10 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.3.4 4.0.0
Known to fail: 3.4.0 3.4.1
Last reconfirmed: 2004-08-18 12:00:29


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Woegerer 2004-08-18 11:05:45 UTC
On GCC 3.4.1 the following goto example generates wrong code.

On GCC 3.3.3 the return vale of this example is 1 as it should
be according to ANSI C "... If the first substatement is reached
via a label, the second substatment is not executed ..."
(see 6.6.4.1).

It looks to me that cfg_cleanup or some reachability test is not
taking into account that the if(0)-basic-block is entered via the
label and behaves too optimistic in elimiating it.

int main(int argc, char **argv)
{
  int i = 0;
  goto useless;
  if(0)
    {
      useless:
      i = 1;
    }
  else
    {
      i = 2;
    }
  return i;
}
Comment 1 Volker Reichelt 2004-08-18 12:00:29 UTC
Confirmed.

Remarks:
* This only happens with -O0.
* The return value is not even 0 or 2, but 16.
Comment 2 Paul Woegerer 2004-08-19 07:26:55 UTC
(In reply to comment #1)
> Confirmed.
> 
> Remarks:
> * This only happens with -O0.
> * The return value is not even 0 or 2, but 16.
> 

With -O0 i also get return value 16. But with
-O2, -O3 and -Os i get 164 as return value.

I used GCC 3.4.1 in the following configuration:
Reading specs from /usr/local/gcc-3.4.1-native/lib/gcc/i686-pc-linux-gnu/3.4.1/specs
Configured with: ../gcc-3.4.1/configure --enable-languages=c,c++
--prefix=/usr/local/gcc-3.4.1-native
Thread model: posix
gcc version 3.4.1
Comment 3 Paul Woegerer 2004-08-19 07:54:11 UTC
Subject: Re:  [3.4 regression] Jump into if(
 0) -substatement fails

Morning Tal,

So i was wrong yesterday when i said something is wrong with the header 
files.
Something is wrong with the compiler. Is this bug already reported to GNUs
bugzilla?

Paul

 




"paul dot woegerer at nsc dot com" <gcc-bugzilla@gcc.gnu.org>
08/19/2004 09:26 AM
Please respond to gcc-bugzilla
 
        To:     Paul.Woegerer@nsc.com
        cc: 
        Subject:        [Bug rtl-optimization/17078] [3.4 regression] Jump 
into if(0) -substatement fails



------- Additional Comments From paul dot woegerer at nsc dot com 
2004-08-19 07:26 -------
(In reply to comment #1)
> Confirmed.
> 
> Remarks:
> * This only happens with -O0.
> * The return value is not even 0 or 2, but 16.
> 

With -O0 i also get return value 16. But with
-O2, -O3 and -Os i get 164 as return value.

I used GCC 3.4.1 in the following configuration:
Reading specs from 
/usr/local/gcc-3.4.1-native/lib/gcc/i686-pc-linux-gnu/3.4.1/specs
Configured with: ../gcc-3.4.1/configure --enable-languages=c,c++
--prefix=/usr/local/gcc-3.4.1-native
Thread model: posix
gcc version 3.4.1


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17078

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.




Comment 4 Volker Reichelt 2004-08-19 10:21:42 UTC
> With -O0 i also get return value 16. But with
> -O2, -O3 and -Os i get 164 as return value.

Hmm. With the C frontend I only get wrong numbers with -O0.
With the C++ frontend I get wrong numbers for all optimizations:
-O0 -O1 -O2 -O3 -Os. (I mostly get zeros, but that's not a
contradiction to the 164 mentioned above, since there's probably
some uninitialized memory involved).

Anyway, GCC is at fault here.
Comment 5 Mark Mitchell 2004-08-22 23:50:21 UTC
Roger, this looks to be a bug in expand_unreachable_stmt.

In particular, it looks like the return statement is never expanded because it
is considered unreachable due to the earlier goto.  However, since the
then-clause of the if-statment falls off the bottom, the return-statement
becomes reachable again.  Here, expand_unreachable_if_stmt should be returning
true, but instead returns false.

I've assigned this bug to you.
Comment 6 GCC Commits 2004-08-24 04:02:58 UTC
Subject: Bug 17078

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	sayle@gcc.gnu.org	2004-08-24 04:02:46

Modified files:
	gcc            : ChangeLog c-semantics.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr17078-1.c 

Log message:
	PR rtl-optimization/17078
	* c-semantics.c (expand_unreachable_if_stmt): If the end of the
	specified statement list is reachable, always return a non-NULL
	pointer.  If necessary, return error_mark_node.
	
	* gcc.c-torture/execute/pr17078-1.c: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.589&r2=2.2326.2.590
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.74.4.2&r2=1.74.4.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.256&r2=1.3389.2.257
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr17078-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 7 Andrew Pinski 2004-08-24 04:09:43 UTC
Fixed.
Comment 8 GCC Commits 2004-08-24 04:23:39 UTC
Subject: Bug 17078

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-08-24 04:23:31

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr17078-1.c 

Log message:
	PR rtl-optimization/17078
	* gcc.c-torture/execute/pr17078-1.c: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4177&r2=1.4178
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr17078-1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2