Bug 22087 – `synchronized scope(exit) <statement>`: statement is skipped

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-27T01:08:49Z
Last change time
2024-12-13T19:17:21Z
Assigned to
No Owner
Creator
kinke
Moved to GitHub: dmd#19955 →

Comments

Comment #0 by kinke — 2021-06-27T01:08:49Z
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@GOTPCREL[RIP] call _d_criticalenter2@PLT32 mov RAX,shared(void*) onlineapp.foo().__critsec2@GOTPCREL[RIP] mov RDI,[RAX] call _d_criticalexit@PLT32 leave ret add [RAX],AL add [RAX],AL ``` --- What works is an explicit block: `synchronized { scope(exit) i++; }`.
Comment #1 by robert.schadek — 2024-12-13T19:17:21Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19955 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB