Bug 15346 – Calling interface methods on out contracts causes segfaults
Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-11-16T18:18:00Z
Last change time
2015-12-06T04:41:30Z
Assigned to
nobody
Creator
initrd.gz
Comments
Comment #0 by initrd.gz — 2015-11-16T18:18:18Z
One of my projects started mysteriously throwing segfaults. I managed to narrow it down to a line in one of my interface's out contracts that compared the result with a value returned by a property method defined on the interface. Even doing `debug stderr.writeln(this);` threw a segfault; GDB says its from the `_d_interface_cast` function.
The full code is too big to post here, but I think I narrowed it down:
import std.stdio;
interface A {
int* aField() @property pure;
int foo()
out(v) {
debug stderr.writeln(this.aField);
}
}
class F : A{
this() {}
int myField;
int* aField() @property pure { return &myField; }
int foo() {
debug stderr.writeln(this.aField);
return 0;
}
}
void main() {
auto f = new F();
f.foo();
}
I expect that this function would print the same address twice; it prints out `aField`, a simple function that returns a pointer to a class member, once in a function body and once in the interface's out contract. Running it with `rdmd -debug test.d` results in the following output:
7F21F379F010
6
The first address differs with each run (as expected with memory addresses) but the second line is consistently a 6. Moving the out contract to the implementation of foo method in class F results in the correct output (the same address printed twice).
I suspect that the pointer adjustment that happens with `this` in an out contract is being done incorrectly, but I don't have the skills to diagnose it further.
Using dmd v2.069.1 on x64 XUbuntu
Comment #1 by lt.infiltrator — 2015-11-18T23:08:41Z
This sounds like #14779. Do you want to grab master from git and test whether that fixes your error?
Comment #2 by lt.infiltrator — 2015-11-18T23:10:07Z
Issue 14779, for it to get linkified properly, I think.
Comment #3 by initrd.gz — 2015-12-04T15:12:47Z
Still happens on DMD 2.069.2. I haven't gotten around to downloading master and compiling it yet; I don't know if I'll have time for that.