I'm struggling to understand dwarf EH, and figure it's a good idea to try and
make it binary compatible with what gdc does, or at least not gratuitously
different. If I use gdc to compile this:
void foo1() {
abc();
try {
def();
}
catch(DD t) {
ghi(t);
}
catch(CC t) {
ghi(t);
}
catch {
mno();
}
jkl();
}
the code generated looks like this:
_D3eh54foo1FZv:
push RBP
mov RBP,RSP
sub RSP,010h
call abc
call def
L12: call jkl
jmp short L86
cmp RDX,2
je L59
cmp RDX,3
je L7F
cmp RDX,1
je L33
mov RDI,RAX
call _Unwind_Resume
L33: sub RAX,8
mov RAX,[RAX]
mov ESI,offset _D3eh52DD7__ClassZ
mov RDI,RAX
call _d_dynamic_cast
mov -8[RBP],RAX
mov RAX,-8[RBP]
mov RDI,RAX
call ghi
jmp short L12
L59: sub RAX,8
mov RAX,[RAX]
mov ESI,offset _D3eh52CC7__ClassZ
mov RDI,RAX
call _d_dynamic_cast
mov -010h[RBP],RAX
mov RAX,-010h[RBP]
mov RDI,RAX
call ghi
jmp short L12
L7F: call mno
jmp short L12
L86: leave
ret
The calls to _d_dynamic cast appear to be redundant - shouldn't the value in RDX
be sufficient? And why is there a 'default' call to _Unwind_Resume if RDX isn't
an expected value? Shouldn't the personality routine simply not jump to the
landing pad if none of the catch types are satisfied?