[Issue 23472] New: scope(sucess) generate exception handling code.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 9 14:29:10 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23472
Issue ID: 23472
Summary: scope(sucess) generate exception handling code.
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: deadalnix at gmail.com
See sample code:
char inc(string s, ref int i) {
scope(success) i++;
return s[i];
}
void main() {
int i;
inc("string", i);
}
The codegen using LDC is:
char example.inc(immutable(char)[], ref int):
push rbx
mov rbx, rdx
movsxd rcx, dword ptr [rdx]
cmp rdi, rcx
jbe .LBB0_1
mov al, byte ptr [rsi + rcx]
add ecx, 1
mov dword ptr [rbx], ecx
pop rbx
ret
.LBB0_1:
mov r8, rdi
lea rsi, [rip + .L.str]
mov edi, 14
mov edx, 3
call _d_arraybounds_index at PLT
cmp edx, 1
jne .LBB0_7
mov rdi, rax
call _d_eh_enter_catch at PLT
mov rdi, rax
call _d_throw_exception at PLT
.LBB0_7:
add dword ptr [rbx], 1
mov rdi, rax
call _Unwind_Resume at PLT
mov rdi, rax
call _Unwind_Resume at PLT
It contains exception handling code, which shouldn't be required for a
scope(success) statement, and in fact, we can see that the exception is caught
and rethrown immediately.
Checking with GDC and DMD shows that they also contain exception handling code,
so I assume this is being generated by the frontend.
--
More information about the Digitalmars-d-bugs
mailing list