ldc-developers/ldc — Issue #55: Illegal instruction
Author: dsimcha
Created: 2011-12-21 17:52:51+00:00
State: open

// test.d:
void fun(const string[] arr) {
byte[0][string] keep;
foreach(elem; arr) keep[elem] = (byte[0]).init;
}

void main() {
fun(["a", "b"]);
}

$ ldc2 -O test.d && ./test
Illegal instruction

This is caused by the illegal ud2 instruction being emitted at the end of fun. Here's the disassembly of this function:

_D4test3funFxAAyaZv PROC
sub rsp, 24 ; 0000 _ 48: 83. EC, 18
mov qword ptr [rsp+10H], 0 ; 0004 _ 48: C7. 44 24, 10, 00000000
test rdi, rdi ; 000D _ 48: 85. FF
jz ?_001 ; 0010 _ 74, 2A
mov rax, qword ptr [rsi] ; 0012 _ 48: 8B. 06
mov rcx, qword ptr [rsi+8H] ; 0015 _ 48: 8B. 4E, 08
mov qword ptr [rsp+8H], rcx ; 0019 _ 48: 89. 4C 24, 08
mov qword ptr [rsp], rax ; 001E _ 48: 89. 04 24
lea rdi, [rsp+10H] ; 0022 _ 48: 8D. 7C 24, 10
lea rcx, [rsp] ; 0027 _ 48: 8D. 0C 24
mov esi, offset _D12TypeInfo_Aya6__initZ ; 002B _ BE, 00000000(d)
mov edx, 1 ; 0030 _ BA, 00000001
call _aaGetX ; 0035 _ E8, 00000000(rel)
ud2 ; 003A _ 0F 0B

?_001: add rsp, 24 ; 003C _ 48: 83. C4, 18
ret ; 0040 _ C3
_D4test3funFxAAyaZv ENDP