Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarrification for bad codegen on postfix operators #4141

Open
dlangBugzillaToGithub opened this issue May 17, 2024 · 0 comments
Open

Clarrification for bad codegen on postfix operators #4141

dlangBugzillaToGithub opened this issue May 17, 2024 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

Richard (Rikki) Andrew Cattermole reported this on 2024-05-17T14:59:01Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24554

Description

Johan Engelen asked me on the ldc bug ticket to create a ticket to find out what the specification means.

All three compilers have differing behavior.

DMD: https://github.com/ldc-developers/ldc/issues/4651

GDC: https://forum.dlang.org/post/[email protected]

ldc fe 2.107 as per run.dlang.org

```d
void main()
{
    int d = 42;
    bool o = d > d++;
}
```

```
define i32 @_Dmain({ i64, ptr } %unnamed) #0 {
  %d = alloca i32, align 4                        ; [#uses = 4, size/byte = 4]
  %o = alloca i8, align 1                         ; [#uses = 1, size/byte = 1]
  store i32 42, ptr %d, align 4
  %1 = load i32, ptr %d, align 4                  ; [#uses = 2]
  %2 = add i32 %1, 1                              ; [#uses = 1]
  store i32 %2, ptr %d, align 4
  %3 = load i32, ptr %d, align 4                  ; [#uses = 1]
  %4 = icmp sgt i32 %3, %1                        ; [#uses = 1]
  %5 = zext i1 %4 to i8                           ; [#uses = 1]
  store i8 %5, ptr %o, align 1
  ret i32 0
}
```

Note; the icmp is after the add, which it shouldn't be.

Source: https://twitter.com/marcos_don/status/1787629240550150361
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant