Bug 47155 - [4.6 Regression] ccp caused miscompilation
Summary: [4.6 Regression] ccp caused miscompilation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-01-03 03:01 UTC by John Regehr
Modified: 2011-01-03 21:12 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2011-01-03 09:13:19


Attachments
gcc46-pr47155.patch (644 bytes, patch)
2011-01-03 09:31 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2011-01-03 03:01:29 UTC
[regehr@gamow tmp438]$ current-gcc -O0 small.c -o small
[regehr@gamow tmp438]$ ./small
1
[regehr@gamow tmp438]$ current-gcc -O1 small.c -o small
[regehr@gamow tmp438]$ ./small
0
[regehr@gamow tmp438]$ current-gcc -v
Using built-in specs.
COLLECT_GCC=current-gcc
COLLECT_LTO_WRAPPER=/uusoc/exports/scratch/regehr/z/compiler-install/gcc-r168402-install/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --with-libelf=/usr/local --enable-lto --prefix=/home/regehr/z/compiler-install/gcc-r168402-install --program-prefix=r168402- --enable-languages=c,c++
Thread model: posix
gcc version 4.6.0 20110102 (experimental) (GCC) 
[regehr@gamow tmp438]$ cat small.c


static unsigned int g_1;
static signed char g_2 = 0x81;

int printf(const char *format, ...);

static unsigned char foo(unsigned char p1, unsigned char p2)
{
    return p1 * p2;
}

int main (void)
{
    int l_5[2];
    int i;
    for (i = 0; i < 2; i++)
        l_5[i] = 1;
    g_1 = g_2 <= foo(-6, l_5[0]);

    printf("%u\n", g_1);
    return 0;
}
Comment 1 Jakub Jelinek 2011-01-03 09:13:19 UTC
Indeed, caused by my PR47140 patch.
Comment 2 Jakub Jelinek 2011-01-03 09:31:27 UTC
Created attachment 22884 [details]
gcc46-pr47155.patch

Untested fix.
Comment 3 Jakub Jelinek 2011-01-03 21:01:18 UTC
Author: jakub
Date: Mon Jan  3 21:01:14 2011
New Revision: 168440

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168440
Log:
	PR tree-optimization/47155
	* tree-ssa-ccp.c (bit_value_binop_1): Use r1type instead of type
	when computing uns.

	* gcc.c-torture/execute/pr47155.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr47155.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-ccp.c
Comment 4 Jakub Jelinek 2011-01-03 21:12:02 UTC
Fixed.