[clang] [clang CodeGen] Restrict return statements nested in return statements. (PR #94282)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 4 07:42:09 PDT 2024


higher-performance wrote:

**Please** don't do this, it's an incredibly heavy hammer for something so narrow. If you really must add a diagnosis, please make it a warning instead of an outright error. It breaks people's working code that was never suffering from this problem to begin with. There's no need to reject all the cases of nested returns just to address #91761. That case is much narrower than what you're banning.

Furthermore, I believe this is a misdiagnosis of the real issue. The issue isn't really the destructors. The issue is `break` inside *nested* aggregate RVOs; i.e. the non-tree-like (non-"LIFO") control flow. Even if every type were POD, you'd still have a problem: the inner `return`'s RVO would overwrite the first field initializer from the outer `return` in the return slot, permanently losing it. Which is entirely still workable! The fundamental problem comes up when the use of `break;` then decides "nope, just kidding, cancel this inner `return` -- I'm actually going to rely on the thing I just overwrote". That's just asking for the impossible.

So, I think what you want to diagnose is "breaking inside a nested aggregate-init RVO", or something to that effect. If you can't diagnose that fully accurately, please 100% make this a warning -- not an error.

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


More information about the cfe-commits mailing list