Bug 18921 - [4.0 Regression] wrong code with operator "?"
Summary: [4.0 Regression] wrong code with operator "?"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-12-10 11:18 UTC by Serge Belyshev
Modified: 2004-12-11 15:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.5 3.4.4
Known to fail: 4.0.0
Last reconfirmed: 2004-12-10 11:55:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Belyshev 2004-12-10 11:18:23 UTC
this program aborts if compiled with any options:
----------------------------------------------------------------------------------------
extern void abort (void);

int foo (int k)
{
  unsigned char j = 0;
  (k ? 0 : j++) == -1;
  return j;
}

int main ()
{
  if (!foo (0))
    abort ();
  return 0;
}
----------------------------------------------------------------------------------------
Comment 1 Andrew Pinski 2004-12-10 13:35:08 UTC
We are getting rid of "  (k ? 0 : j++) == -1;" for some reason even though it has side effects.
Comment 2 GCC Commits 2004-12-11 13:46:52 UTC
Subject: Bug 18921

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-12-11 13:46:37

Modified files:
	gcc            : ChangeLog fold-const.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: pr18921-1.c 

Log message:
	PR middle-end/18921
	* fold-const.c (fold_unwidened_comparison): Use omit_one_operand
	instead of constant_boolean_node as arg0 may have side-effects.
	
	* gcc.dg/pr18921-1.c: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6780&r2=2.6781
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&r1=1.483&r2=1.484
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4738&r2=1.4739
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18921-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 3 Serge Belyshev 2004-12-11 15:40:26 UTC
Fixed.