www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22087] New: `synchronized scope(exit) <statement>`: statement

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 puremagic.com
          Reporter: kinke 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 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++; }`.

--
Jun 26 2021