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

core.atomic.atomicStore and core.atomic.atomicLoad calls itself recursively #4701

Open
avaxar opened this issue Jul 12, 2024 · 4 comments
Open

Comments

@avaxar
Copy link

avaxar commented Jul 12, 2024

Migrating issue 21893 from the D bug tracker to here, as it specifically pertains to LDC. The suggested changes provided in the issue necessitates making explicit function references in druntime/core/atomic.d. However, as this issue only occurs on LDC (whereas, it works fine with DMD and GDC), I suspect that LDC might be at fault in incorrectly dereferencing the overloads.

Minimally reproducable example

import std.stdio;
import core.atomic;

shared string test = "Hello";

void main() {
    writeln(test);
    atomicStore(test, "Goodbye"); // This induces a stack-overflow
    writeln(test);
}
@kinke
Copy link
Member

kinke commented Jul 12, 2024

This isn't a stack overflow. The problem is the alignment - for a 128-bit type, make sure to use align(16) shared string test = ….

@JohanEngelen
Copy link
Member

This isn't a stack overflow. The problem is the alignment - for a 128-bit type, make sure to use align(16) shared string test = ….

Then that's still a bug in our druntime, I find. (should do a static assert on the alignment of the type)

@kinke
Copy link
Member

kinke commented Jul 13, 2024

We can't do a static assert of the type, slices are surely a pretty common type, and never aligned sufficiently. We could add a runtime assertion though, that's done in other places too.

@JohanEngelen
Copy link
Member

We can't do a static assert of the type, slices are surely a pretty common type, and never aligned sufficiently.

It's possible to do a static assert on the T.alignof == 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants