Bug 18921

Summary: [4.0 Regression] wrong code with operator "?"
Product: gcc Reporter: Serge Belyshev <belyshev>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: critical CC: gcc-bugs
Priority: P2 Keywords: wrong-code
Version: 4.0.0   
Target Milestone: 4.0.0   
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

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.