https://bugs.llvm.org/show_bug.cgi?id=50801
Bug ID: 50801
Summary: missing sign extension when converting int to long
long
Product: new-bugs
Version: 12.0
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedb...@nondot.org
Reporter: n...@fluxnic.net
CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org
Given the following code:
int bar(long long x);
int foo(int x)
{
if (x < 0 || x >= 1024) return -1;
return bar(x);
}
Invoking clang with -O2 produces this for arm:
foo:
mov r1, #0
cmp r1, r0, lsr #10
mvnne r0, #0
bxne lr
mov r1, #0
b bar
And the following for i386:
foo:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
cmpl $1023, %eax # imm = 0x3FF
jbe .LBB0_1
movl $-1, %eax
popl %ebp
retl
.LBB0_1:
pushl $0
pushl %eax
calll bar
addl $8, %esp
popl %ebp
retl
Notice that in both cases the argument to bar() is not sign extended as it
ought to be.
The same can be observed on aarch64 by replacing "long long" with "__int128":
foo: // @foo
cmp w0, #1023 // =1023
b.ls .LBB0_2
mov w0, #-1
ret
.LBB0_2:
mov w0, w0
mov x1, xzr
b bar
And similarly for x86_64.
A slight simplification in the conditional e.g. removing the "x < 0" part is
enough for this issue to disappear.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs