← Back to index
|
Original Bugzilla link
Bug 23743 – wrong code with `foreach`, `ubyte`, `>=`, ternary operator
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2023-02-26T12:42:52Z
Last change time
2023-03-01T21:57:45Z
Keywords
backend, pull, wrong-code
Assigned to
No Owner
Creator
ag0aep6g
Comments
Comment #0
by ag0aep6g — 2023-02-26T12:42:52Z
void main() { ubyte[] a = [1]; foreach (x; a) { ubyte v = x >= 1 ? 255 : 0; assert(v == 255); /* fails; should pass */ } } dmd2.102.1, Windows, -m64: fail dmd2.102.1, Windows, -m32: pass dmd2.102.1, Windows, -m32mscoff: pass run.dlang.io, all dmd versions (2.062, ..., 2.101.2): fail run.dlang.io, ldc: pass
Comment #1
by dkorpel — 2023-02-26T15:03:12Z
Reduced to avoid `foreach` lowering: ``` void main() { ubyte[] a = [1u]; ulong i = 0; for (;;) { ubyte x = a[i]; ubyte v = x >= 1 ? 255 : 0; assert(cast(int)v == 255); } } ```
Comment #2
by dkorpel — 2023-02-26T16:27:47Z
Related: issue 11565 and issue 12164 It looks like it generates `NEG DH` to set the `v` to 255, but it should be setting the RSI register.
Comment #3
by dlang-bot — 2023-02-26T16:28:44Z
@dkorpel created dlang/dmd pull request #14919 "Fix 23743 - wrong code with `foreach`, `ubyte`, `>=`, ternary operator" fixing this issue: - Fix 23743 - wrong code with `foreach`, `ubyte`, `>=`, ternary operator
https://github.com/dlang/dmd/pull/14919
Comment #4
by dlang-bot — 2023-03-01T11:58:28Z
dlang/dmd pull request #14919 "Fix 23743 - wrong code with `foreach`, `ubyte`, `>=`, ternary operator" was merged into stable: - 40c3200a2017ad55669c797d09f1358a82ace75c by Dennis Korpel: Fix 23743 - wrong code with `foreach`, `ubyte`, `>=`, ternary operator
https://github.com/dlang/dmd/pull/14919
Comment #5
by dlang-bot — 2023-03-01T21:57:45Z
dlang/dmd pull request #14938 "merge stable" was merged into master: - f8cfdcd7ca96eb445cfda1b752904b34347aa1f4 by Dennis Korpel: Fix 23743 - wrong code with `foreach`, `ubyte`, `>=`, ternary operator
https://github.com/dlang/dmd/pull/14938