reproduction:
reduced.d
```
static if (is(typeof(new Object())))
void foo()
{
}
```
dmd -c -profile=gc reduced.d
currently breaks building msgpack-d / DCD with profile-gc, which is needed for CI / measuring memory usage in a PR.
Regressed with DMD 2.103.0
alternative reproduction that works with master:
reduced2.d
```
string myToString()
{
}
enum x = myToString ~ "";
```
dmd -c -profile=gc reduced2.d
this one regressed in https://github.com/dlang/dmd/commit/1db1ba87fd23d45f1bffaea07efe7dc8070ffef1
different commit, but the issue is also introduced by template translation here. So it looks like there is some issue further up
blocks the same msgpack-d / DCD project
Comment #3 by razvan.nitu1305 — 2023-05-02T09:23:37Z
(In reply to Jan Jurzitza from comment #1)
> note: the code to reproduce has been fixed with
> https://github.com/dlang/dmd/commit/abb7836dd705be4f3c82e606b31d54dd69276476
> on master, but that did not seem intentional and I'm keeping this open until
> the real regression cause has been identified and can be confirmed fixed by
> this.
>
> Regression was introduced by
> https://github.com/dlang/dmd/commit/276ef2145b2cab876c82845d2d1e943847ea2f3a
Actually, even though the fix was not intentional it is the proper fix.
The underlying issue stems from the fact that the profile gc hook needs to be given a function name so that it outputs where the allocation takes place (allocations that are not inside function bodies are compile time allocations therefore do not require the gc). However, in speculative contexts (such as the ones provided in this bug report) you are not necessarily inside a function body, therefore when the hook is instantiated it tries to pass a function name (taken from a null object). That is why the fix linked here correctly solves this issue by avoiding to lower to the druntime hook if no code is going to be generated.
There probably might be other slips of this sort so please file them as individual bugs (not as comments to this bug report) if you discover them.
I am going to fix the case that is provided in this bug report so please do not link any other manifestations.