immutable struct S {
immutable int x;
}
void countTo2(immutable S a) {
if (a.x < 2)
countTo2(S(a.x + 1));
}
extern(C) void _start() {}
extern(C) int test() {
immutable S a = S(0);
immutable S b = a;
countTo2(a);
return a.x - b.x;
}
a and b are immutable and b = a, so the difference should be 0. But in an optimized WASM build, apparently a changes after countTo2(a). (And it was passed by value too.)
Tested with LDC 1.33.0-git-aa64fad.
I can't see any obvious bug in our unoptimized IR. I suspect a wasm-specific LLVM issue wrt. the byval IR attribute; the optimizer 'optimizes' the function to a return 2.
a.d:
test.js:
Now run:
The output is:
a
andb
are immutable andb = a
, so the difference should be 0. But in an optimized WASM build, apparentlya
changes aftercountTo2(a)
. (And it was passed by value too.) Tested with LDC1.33.0-git-aa64fad
.