Bug 20187 - [3.4 Regression] wrong code for ((unsigned char)(unsigned long long)((a?a:1)&(a*b)))?0:1)
Summary: [3.4 Regression] wrong code for ((unsigned char)(unsigned long long)((a?a:1)&...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 3.4.5
Assignee: Richard Sandiford
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-02-24 12:05 UTC by heinrich.brand
Modified: 2005-07-28 16:35 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux
Target: i686-pc-linux
Build: i686-pc-linux
Known to work: 4.0.0 4.1.0 2.95.3
Known to fail: 3.4.0 3.0.4 3.3.3
Last reconfirmed: 2005-07-28 10:55:11


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description heinrich.brand 2005-02-24 12:05:08 UTC
Function test has value 0. Should have value 1;

#include <stdio.h>
int a=0x101;
int b=0x100;

int test(){
 return (
  ((unsigned char)(unsigned long long) ( (a?a:1) & (a*b) ))
  ?  0 : 1 );
}

int main(void){
 if((unsigned char)(unsigned long long) (a&(a*b)))return 2;
 if( test() ){
        printf("successful\n"); return 0;
 } else { 
        printf("failed\n"); return 1;
 } 
} 

Related to Bug 19606? 

GNU CPP version 2.95.2 19991024 (release) (sparc) successful
GNU C version 3.3.3 (sparc-sun-solaris2.8)  failed

GNU CPP version 3.2 (cpplib) (i386 Linux/ELF) failed 
GNU C version 3.3.2 (i686-pc-linux-gnu) failed
GNU C version 3.3.5 (i686-pc-linux-gnu) failed
GNU C version 3.4.3 (i686-pc-linux-gnu) failed
Comment 1 Andrew Pinski 2005-07-01 19:39:19 UTC
Confirmed, only a regression on the 3.4 branch.
Comment 2 Richard Sandiford 2005-07-28 10:55:10 UTC
This is another symptom of the same bug as PR19283.  I'm testing
a backport of that patch.
Comment 3 GCC Commits 2005-07-28 16:27:31 UTC
Subject: Bug 20187

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rsandifo@gcc.gnu.org	2005-07-28 16:27:22

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

Log message:
	PR c/20187
	* gcc.c-torture/execute/pr20187-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5842&r2=1.5843
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr20187-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 GCC Commits 2005-07-28 16:30:59 UTC
Subject: Bug 20187

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	rsandifo@gcc.gnu.org	2005-07-28 16:30:51

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

Log message:
	PR c/20187
	* gcc.c-torture/execute/pr20187-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.306&r2=1.5084.2.307
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr20187-1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 5 GCC Commits 2005-07-28 16:34:54 UTC
Subject: Bug 20187

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	rsandifo@gcc.gnu.org	2005-07-28 16:34:42

Modified files:
	gcc            : ChangeLog fold-const.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr20187-1.c 

Log message:
	PR c/20187
	* fold-const.c (fold): When shortening comparisons of widened operands,
	check whether the tree returned by get_unwidened really is wider.

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.886&r2=2.2326.2.887
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.322.2.17&r2=1.322.2.18
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.412&r2=1.3389.2.413
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr20187-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1

Comment 6 Richard Sandiford 2005-07-28 16:35:47 UTC
Patch applied to 3.4 branch.  Testcase also applied to 4.0 and mainline
(where it already passes).