[Issue 22087] New: `synchronized scope(exit) <statement>`: statement is skipped
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 27 01:08:49 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22087
Issue ID: 22087
Summary: `synchronized scope(exit) <statement>`: statement is
skipped
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: kinke at gmx.net
The following utterly fails - `i++` isn't executed:
```
int i;
void foo() {
synchronized scope(exit) i++;
}
void main() {
foo();
assert(i == 1);
}
```
The generated asm is terrible - there are 2 (!) additions *after* ret:
```
void onlineapp.foo():
push RBP
mov RBP,RSP
sub RSP,010h
mov qword ptr -8[RBP],0
mov RDI,shared(void*)
onlineapp.foo().__critsec2 at GOTPCREL[RIP]
call _d_criticalenter2 at PLT32
mov RAX,shared(void*)
onlineapp.foo().__critsec2 at GOTPCREL[RIP]
mov RDI,[RAX]
call _d_criticalexit at PLT32
leave
ret
add [RAX],AL
add [RAX],AL
```
---
What works is an explicit block: `synchronized { scope(exit) i++; }`.
--
More information about the Digitalmars-d-bugs
mailing list