Use-after-scope bug in Phobos unittest, how to fix?

Johan j at j.nl
Mon May 15 19:36:27 UTC 2023


On Monday, 15 May 2023 at 19:27:00 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> Just to confirm something, you're saying we can't use alloca 
> when optimizing with ldc?

No.

> Because this is what that code essentially is doing (which 
> could be perfectly fine for @system to do).

The code is not calling `alloca`. It is defining a local variable 
in some inner scope, then exits that scope, then accesses the 
out-of-scope variable through a pointer.
It is irrelevant how local variable memory is allocated (could be 
"stack" or "heap" or some other mechanism, which are 
implementation details that may differ and are irrelevant to the 
UB).

-Johan



More information about the Digitalmars-d mailing list