D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15346 - Calling interface methods on out contracts causes segfaults
Summary: Calling interface methods on out contracts causes segfaults
Status: RESOLVED DUPLICATE of issue 7517
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-16 18:18 UTC by Alex Parrill
Modified: 2015-12-06 04:41 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Alex Parrill 2015-11-16 18:18:18 UTC
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 Infiltrator 2015-11-18 23:08:41 UTC
This sounds like #14779.  Do you want to grab master from git and test whether that fixes your error?
Comment 2 Infiltrator 2015-11-18 23:10:07 UTC
Issue 14779, for it to get linkified properly, I think.
Comment 3 Alex Parrill 2015-12-04 15:12:47 UTC
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.
Comment 4 Kenji Hara 2015-12-06 04:41:30 UTC
It's a dup of issue 7517. PR#4794 for that also fixes it.

https://github.com/D-Programming-Language/dmd/pull/4794

*** This issue has been marked as a duplicate of issue 7517 ***