Bug 14227 – Incorrect passed a delegate as argument with null value.

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-02-26T19:41:00Z
Last change time
2016-03-25T07:43:10Z
Keywords
wrong-code
Assigned to
nobody
Creator
alexey.poryadin

Comments

Comment #0 by alexey.poryadin — 2015-02-26T19:41:51Z
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 by alexey.poryadin — 2015-02-26T19:47:03Z
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 by safety0ff.bugz — 2015-02-26T20:30:12Z
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 by yebblies — 2016-03-25T07:43:10Z
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.