D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14227 - Incorrect passed a delegate as argument with null value.
Summary: Incorrect passed a delegate as argument with null value.
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 major
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2015-02-26 19:41 UTC by Alexey Poryadin
Modified: 2016-03-25 07:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Alexey Poryadin 2015-02-26 19:41:51 UTC
import std.stdio;

class Class
{
	void set(int a, double b, void delegate(int revents) callback)
	{
		writefln("(callback !is null) %s", (callback !is null));
	}
}

void main()
{
	auto c = new Class;
	c.set(1, 1, null); // prints: (callback !is null) true
	c.set(1, 1, null); // prints: (callback !is null) false
}
-----
Very strange. It dependent on previous argument number and types. For example if they both has type int, it work correct.

DMD64 D Compiler v2.066.1
Linux desktop 3.13.0-45-generic #74-Ubuntu SMP Tue Jan 13 19:36:28 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Comment 1 Alexey Poryadin 2015-02-26 19:47:03 UTC
Starting program: /work/research/test 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, test.Class.set() (this=0x7ffff7ed8ff0, callback=..., b=1, a=1) at /work/research/test.d:7
7			writefln("(callback !is null) %s", (callback !is null));
(gdb) print callback
$1 = {ctxptr = 0x0, funcptr = 0x3ff0000000000000}
(gdb)
-------
This is debug output that I took.
Comment 2 safety0ff.bugz 2015-02-26 20:30:12 UTC
This seems to be a heisenbug in the backend.
It disappears when optimizations are enabled.
Looking at the assembly, the compiler doesn't clear RDX for the first call to test.Class.set, but does for the second call, resulting in garbage in RDX for the first call.

Still occurs with recent git version.
Comment 3 yebblies 2016-03-25 07:43:10 UTC
I can't reproduce this.  I suspect it was a duplicate of one of the many 64-bit ABI bugs fixed in the last couple of years.