segfault in ldc release only - looks like some kind of optimization bug?
aliak
something at something.com
Tue Jul 23 00:30:48 UTC 2019
Hi,
so I had this weird bug that was driving me crazy and only
segfaulted with ldc in release build - (I'm using ldc 1.16.0).
This is the code that segfaults. All parts seem to be necessary
for it to happen, or at least I think so. I've gone in circles
minimizing so I've probably missed something. But this seems to
be it:
import std;
struct W(T) {
T value;
ref inout(T) front() inout { return value; }
}
auto ref get(T)(W!T value) {
return value.front;
}
struct S {
string a;
}
void main() {
S[string] aa;
aa = ["one" : S("a")];
auto b = W!S(aa["one"]).get;
writeln(b);
}
Running with ldc and -O3 crashes: "ldc2 -O3 -run source.d"
Some things I've noticed:
- if you remove the call to .get and use .value directly, the
crash goes
- if you remove the inout specifier on front(), the crash goes
- if you remove the ref specifier on front(), the crash goes
- if you don't call writeln(b), the crash goes
- if you don't use the s returned by the aa, the crash goes
- if you *add* a return qualifier on the "front" function, the
crash goes away
(what is that return thing btw and when do you use it?)
Any ideas?
More information about the Digitalmars-d-learn
mailing list