Bug 12113 - [tree-ssa] wrong result for comparison
Summary: [tree-ssa] wrong result for comparison
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: tree-ssa
: P1 critical
Target Milestone: tree-ssa
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-08-31 00:48 UTC by eyal
Modified: 2003-09-28 16:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-08-31 01:43:11


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description eyal 2003-08-31 00:48:56 UTC
[where can I see the definition of the avove triplet items?]

In the following program, the second printf() should print 'if=1'
but prints 'if=0'.

Compile options "-v -g -O0"

The problem was first seen about a week ago in cvs. Full details in
the run log below.

==================================================
eyal@e7:~$ cat /home/eyal/zz.c
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

static void
test (char *q)
{
        printf ("'%c'\n",         ((char)((*((char *)(q)+(0+24))) & 0x0ff)));
        printf ("if=%d\n", 'I' == ((char)((*((char *)(q)+(0+24))) & 0x0ff)));
}

int main ()
{
        char    *s = "012345678901234567890123I567890";

        test (s);

        return (0);
}
==================================================
eyal@e7:~$ uname -a
Linux e7 2.4.22 #1 Tue Aug 26 08:12:56 EST 2003 i686 unknown
==================================================
eyal@e7:~$ /usr/local/gcc-mudflap/bin/i686-pc-linux-gnu-gcc-3.5-tree-ssa -v -g
-O0 -Wall -o /home/eyal/zz /home/eyal/zz.c
Reading specs from
/data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/specs
Configured with: ../gcc/configure --prefix=/usr/local/gcc-mudflap
--enable-languages=c
Thread model: posix
gcc version 3.5-tree-ssa 20030829 (merged 20030817)
 /data2/usr/local/gcc-mudflap-20030829-203101/bin/../libexec/gcc/i686-pc-linux-gnu/3.5-tree-ssa/cc1 -quiet -v -iprefix /data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/ /home/eyal/zz.c -quiet -dumpbase zz.c -mtune=pentiumpro -auxbase zz -g -O0 -Wall -version -o /tmp/cc1uYL6H.s
ignoring nonexistent directory
"/data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/../../../../i686-pc-linux-gnu/include"
ignoring duplicate directory
"/usr/local/gcc-mudflap/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/include"
ignoring nonexistent directory
"/usr/local/gcc-mudflap/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/include
 /usr/local/include
 /usr/local/gcc-mudflap/include
 /usr/include
End of search list.
GNU C version 3.5-tree-ssa 20030829 (merged 20030817) (i686-pc-linux-gnu)
        compiled by GNU C version 3.5-tree-ssa 20030829 (merged 20030817).
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64574
 as -V -Qy -o /tmp/ccKFH6io.o /tmp/cc1uYL6H.s
GNU assembler version 2.12.90.0.1 (i386-linux) using BFD version 2.12.90.0.1
20020307 Debian/GNU Linux
 /data2/usr/local/gcc-mudflap-20030829-203101/bin/../libexec/gcc/i686-pc-linux-gnu/3.5-tree-ssa/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o /home/eyal/zz /usr/lib/crt1.o /usr/lib/crti.o /data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/crtbegin.o -L/data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa -L/data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc -L/usr/local/gcc-mudflap/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa -L/data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/../../.. -L/usr/local/gcc-mudflap/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/../../.. /tmp/ccKFH6io.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /data2/usr/local/gcc-mudflap-20030829-203101/bin/../lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/crtend.o /usr/lib/crtn.o
============================================
eyal@e7:~$ /home/eyal/zz
'I'
if=0
============================================
Comment 1 Andrew Pinski 2003-08-31 01:43:11 UTC
Triples are defined like i686-..., target is the t

It happens in 20030822 but not in 20030814.
It looks like it is a fold_const problem as it is already changed into a 0 before it changes into 
generic/gimplified.
Comment 2 eyal 2003-09-03 22:17:45 UTC
The expression
    (char)(q[24] & 0x0ff)
is the minimum that triggers the problem. The original problem used a non
constant string.
Comment 3 Steven Bosscher 2003-09-07 14:46:36 UTC
Hmm weird,

If I compile this code,

int main (void)
{
  char *s = "012345678901234567890123I567890";
  printf ("%c\n", (char)(s[24] & 0x000000ff));
  if ('I' ==  (char)(s[24] & 0x0ff))
    return (0);
  else
    abort ();
}

then my .t02.optimized dump looks like this,
                                                                                
;; Function main (main)
;; enabled by -tree-original
                                                                                
                                                                                
{
   char* s = ("012345678901234567890123I567890");
   printf(("%c\n"), (*(s + 24) & '\xffffffff'));
   if (0)
      return <return-value> = 0;
   else
       abort();
                                                                                
}

Note the difference between the two printf lines. 

Also weird that the first s[24] expr is not folded but the second is...

Comment 4 Steven Bosscher 2003-09-07 15:55:14 UTC
After a mini-merge for fold-const.c from mainline, I get:

;; Function main (main)
;; enabled by -tree-original


{
   char* s = ("012345678901234567890123I567890");
   printf(("%c\n"), (*(s + 24) & '\xffffffff'));
   if ((*(s + 24) & '\xffffffff') == 'I')
      return <return-value> = 0;
   else
       abort();
}


This still looks funny to me, but at least it works.  Why can't we deduce that
s[24] == 'I' and why do we change '0x0ff' to '0xffffffff'???
Comment 5 Andrew Pinski 2003-09-28 06:37:09 UTC
There was recently a merge with the mainline, can you try this again?
Comment 6 eyal 2003-09-28 14:21:44 UTC
The small test program now works OK. I am starting a full regression test of my
system.
Comment 7 Andrew Pinski 2003-09-28 16:12:04 UTC
Fixed by merge so closing.  Will apply a test case for this.