[Issue 14551] scope(failure) block causes bloat in nothrow functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 17 16:07:34 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=14551

Witold Baryluk <witold.baryluk+d at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |witold.baryluk+d at gmail.com

--- Comment #1 from Witold Baryluk <witold.baryluk+d at gmail.com> ---
http://asm.dlang.org/ looks to be down.

Would be nice to know actual example.

At least in gdc, I did found that `scope(failure)` in `nothrow` functions (or
even without manually indicating them as such) compiles to zero code, and is
eliminated to nothing.

However it doesn't warn about dead code, which IMHO it should.

Example:

```
int i = 0;

size_t f(string x) nothrow {
  scope(failure) i = 1;
  return 2 + x.length * x.length;
}

int main(string[] args) {
  return cast(int)f(args[1]);
}
```

Compiles with `gdc-9 -fno-bounds-check -O2 -Wall` to:


```
0000000000001230 <_Dmain>:
    1230:       48 8b 46 10             mov    0x10(%rsi),%rax
    1234:       48 0f af c0             imul   %rax,%rax
    1238:       48 83 c0 02             add    $0x2,%rax
    123c:       c3                      retq   
    123d:       0f 1f 00                nopl   (%rax)
```

Wow.

--


More information about the Digitalmars-d-bugs mailing list