[Issue 22277] removing strongly pure function calls is an incorrect optimization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 28 14:21:30 UTC 2021


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

Ate Eskola <Ajieskola at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Ajieskola at gmail.com
           Severity|normal                      |critical

--- Comment #10 from Ate Eskola <Ajieskola at gmail.com> ---
I think the compiler is allowed to elide a `free` call implemented like that.
First, you're compiling in release mode, debug statements are supposed to be
skipped even if the function is called. Second, `debug` statements are not
considered to be side effects that require executing the function - that's what
allows them to reside in `pure`!. They are required to be executed only if the
surrounding scope is executed.

But the `panic` and `assertPositive` functions ought to be executed. If you had
consecutive calls to `assertPositive` with the same argument, the compiler is
free to remove the tailing calls, but not the first one. And that ought to
happen regardless of the return value type.

Increasing severity, as this thing may silently add bugs to the compiled code.

--


More information about the Digitalmars-d-bugs mailing list