ldc icon indicating copy to clipboard operation
ldc copied to clipboard

`core.atomic.atomicStore` and `core.atomic.atomicLoad` calls itself recursively

Open avaxar opened this issue 1 year ago • 4 comments

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);
}

avaxar avatar Jul 12 '24 11:07 avaxar

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 = ….

kinke avatar Jul 12 '24 11:07 kinke

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)

JohanEngelen avatar Jul 13 '24 09:07 JohanEngelen

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.

kinke avatar Jul 13 '24 15:07 kinke

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.

JohanEngelen avatar Jul 14 '24 00:07 JohanEngelen