Bug 14551 – scope(failure) block causes bloat in nothrow functions
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-05-07T00:21:55Z
Last change time
2023-02-13T14:32:12Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Comments
Comment #0 by andrei — 2015-05-07T00:21:55Z
Consider the example shown in http://goo.gl/EY3o7p. There, simply adding an empty scope(failure) block causes an increase in generated code. However, the function is statically known to not throw so the entire scope(failure) statement can be eliminated in the front-end.
Comment #1 by witold.baryluk+d — 2020-01-17T16:07:34Z
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.
Comment #2 by witold.baryluk+d — 2020-01-17T16:08:50Z