[clang] [codegen] Emit missing cleanups for stmt-expr and coro suspensions [take-2] (PR #85398)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 27 10:40:42 PDT 2024


efriedma-quic wrote:

> > Instead of Expr::mayBranchOut, I'd prefer to just unconditionally create the alloca, then delete it later if it turns out we didn't actually need to emit the branch.
> 
> I had earlier tried tracking instructions auxiliary to a particular cleanup in #83224 ([src](https://github.com/llvm/llvm-project/pull/83224/files#diff-9cdaea6a793ed2892bfcd6b431e933a49ebb25caa2bd1d630cd1ca823281092aR263-R286)). This gets ugly very quickly and adds quite some complexity to the cleanup addition and emission code. For example, more instructions could be added if the cleanup is conditional.

You could simplify that code significantly, I think: instead of adding every instruction to the list, just add the alloca, then recursively delete all instructions that use the alloca.

> As far as compile-time is concerned, this involves revisiting the complete expression exactly one more time.

You can end up visiting more than once if an array init contains another array init.

https://github.com/llvm/llvm-project/pull/85398


More information about the cfe-commits mailing list