[Issue 24406] New: wrong signess of comparison with -O and byte-casted char
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 23 10:08:08 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24406
Issue ID: 24406
Summary: wrong signess of comparison with -O and byte-casted
char
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: a.horodniceanu at proton.me
Reduced from
https://github.com/Pure-D/serve-d/blob/master/lsp/source/served/lsp/textdocumentmanager.d#L1309:
```
void main () {
char c = (() => cast(char)47)(); // c == '/'
assert(cast(byte)c >= -0x40);
}
```
```
$ dmd -O -run main.d
core.exception.AssertError at main.d(3): Assertion failure
----------------
??:? _d_assertp [0x55635be3f818]
??:? _Dmain [0x55635be3f76b]
```
$ dmd -run main.d
<no error>
```
Tested against master.
The code generated is:
```
0x0000555555597748 <+0>: push %rbp
0x0000555555597749 <+1>: mov %rsp,%rbp
0x000055555559774c <+4>: rex.W call *0x4b7fd(%rip) #
0x5555555e2f50
0x0000555555597753 <+11>: cmp $0xc0,%al
0x0000555555597755 <+13>: jb 0x55555559775b <_Dmain+19>
0x0000555555597757 <+15>: xor %eax,%eax
0x0000555555597759 <+17>: pop %rbp
0x000055555559775a <+18>: ret
0x000055555559775b <+19>: mov $0x3,%esi
0x0000555555597760 <+24>: lea 0x398b9(%rip),%rdi #
0x5555555d1020 <_TMP0>
0x0000555555597767 <+31>: call 0x5555555977d0 <_d_assertp>
0x000055555559776c <+36>: pop %rbp
0x000055555559776d <+37>: ret
```
The problem is with `jb 0x55555559775b <_Dmain+19>` since the comparison should
be signed.
--
More information about the Digitalmars-d-bugs
mailing list