public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/47812] New: [x32] __builtin_strlen is miscompiled at -O2
@ 2011-02-19 0:56 hjl.tools at gmail dot com
2011-02-19 7:47 ` [Bug target/47812] " xinliangli at gmail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: hjl.tools at gmail dot com @ 2011-02-19 0:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47812
Summary: [x32] __builtin_strlen is miscompiled at -O2
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: hjl.tools@gmail.com
CC: ubizjak@gmail.com
On x32 branch, I got
[hjl@gnu-6 strcat-1]$ cat tester.c
char one[50] = "ijk";
int
main (void)
{
return __builtin_strlen (one) != 3;
}
[hjl@gnu-6 strcat-1]$ make tester.s
/usr/gcc-4.6.0-x32/bin/gcc -mx32 -g -O2 -S tester.c -o tester.s
[hjl@gnu-6 strcat-1]$ cat tester.s
.file "tester.c"
.text
.Ltext0:
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB0:
.file 1 "tester.c"
.loc 1 4 0
.cfi_startproc
.loc 1 5 0
movl $one, %edx
.L2:
movl (%rdx), %eax
addq $4, %rdx
leal -16843009(%eax), %ecx
notl %eax
andl %eax, %ecx
andl $-2139062144, %ecx
je .L2
.loc 1 6 0
movl $1, %eax
ret
.cfi_endproc
This always returns 1 instead of 0.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/47812] [x32] __builtin_strlen is miscompiled at -O2
2011-02-19 0:56 [Bug target/47812] New: [x32] __builtin_strlen is miscompiled at -O2 hjl.tools at gmail dot com
@ 2011-02-19 7:47 ` xinliangli at gmail dot com
2011-02-19 7:47 ` xinliangli at gmail dot com
2011-02-19 14:53 ` hjl.tools at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: xinliangli at gmail dot com @ 2011-02-19 7:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47812
davidxl <xinliangli at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xinliangli at gmail dot com
--- Comment #1 from davidxl <xinliangli at gmail dot com> 2011-02-19 07:05:47 UTC ---
There is a bug in the expand phase. Pseudo reg 59 is not initialized which
leads to an initialization to 0 by the init-reg pass. combine pass then happily
simply the comparison result with 1 which is returned.
The bad case with x32 where reg:SI 64 is initialized instead of 59:
insn 25 24 0 (parallel [
(set (reg:DI 64)
(minus:DI (reg:DI 64)
(reg:DI 62)))
(clobber (reg:CC 17 flags))
]) pr47812.c:5 -1
(nil))
;; return D.2771_2;
(insn 29 25 30 (set (reg:CCZ 17 flags)
(compare:CCZ (reg:SI 59 [ D.2772 ])
(const_int 3 [0x3]))) pr47812.c:5 -1
(nil))
The good case x86_64:
(insn 24 23 0 (parallel [
(set (reg:DI 59 [ D.2772 ])
(minus:DI (reg:DI 59 [ D.2772 ])
(reg:DI 62)))
(clobber (reg:CC 17 flags))
]) pr47812.c:5 -1
(nil))
;; return D.2771_2;
(insn 26 24 27 (set (reg:CCZ 17 flags)
(compare:CCZ (reg:DI 59 [ D.2772 ])
(const_int 3 [0x3]))) pr47812.c:5 -1
(nil))
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/47812] [x32] __builtin_strlen is miscompiled at -O2
2011-02-19 0:56 [Bug target/47812] New: [x32] __builtin_strlen is miscompiled at -O2 hjl.tools at gmail dot com
2011-02-19 7:47 ` [Bug target/47812] " xinliangli at gmail dot com
@ 2011-02-19 7:47 ` xinliangli at gmail dot com
2011-02-19 14:53 ` hjl.tools at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: xinliangli at gmail dot com @ 2011-02-19 7:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47812
--- Comment #2 from davidxl <xinliangli at gmail dot com> 2011-02-19 07:44:03 UTC ---
In ix86_expand_strlen:
if (GET_MODE (out) != Pmode)
out = convert_to_mode (Pmode, out, 1);
Here out is REG:SI 59 -- the result register for strlen. After conversion, new
reg:DI 64 is created. There are two problems here:
1) the result is now 64, but the caller 'expand_builtin_strlen' still uses reg
59
2) the conversion itself generates an uninitialized use.
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/47812] [x32] __builtin_strlen is miscompiled at -O2
2011-02-19 0:56 [Bug target/47812] New: [x32] __builtin_strlen is miscompiled at -O2 hjl.tools at gmail dot com
2011-02-19 7:47 ` [Bug target/47812] " xinliangli at gmail dot com
2011-02-19 7:47 ` xinliangli at gmail dot com
@ 2011-02-19 14:53 ` hjl.tools at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: hjl.tools at gmail dot com @ 2011-02-19 14:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47812
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> 2011-02-19 14:22:45 UTC ---
(In reply to comment #2)
> In ix86_expand_strlen:
>
> if (GET_MODE (out) != Pmode)
> out = convert_to_mode (Pmode, out, 1);
>
>
> Here out is REG:SI 59 -- the result register for strlen. After conversion, new
> reg:DI 64 is created. There are two problems here:
>
> 1) the result is now 64, but the caller 'expand_builtin_strlen' still uses reg
> 59
> 2) the conversion itself generates an uninitialized use.
>
Thanks for the analysis. This is a dup of PR47364. I have a patch.
*** This bug has been marked as a duplicate of bug 47364 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-02-19 14:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-19 0:56 [Bug target/47812] New: [x32] __builtin_strlen is miscompiled at -O2 hjl.tools at gmail dot com
2011-02-19 7:47 ` [Bug target/47812] " xinliangli at gmail dot com
2011-02-19 7:47 ` xinliangli at gmail dot com
2011-02-19 14:53 ` hjl.tools at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).