ldc-developers/ldc

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

avaxar opened this issue · 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);
}

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

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)

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.

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.