[clang] [clang-tools-extra] [codegen] Emit missing cleanups when an expression contains a branch (PR #80698)
James Y Knight via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 20:29:20 PST 2024
jyknight wrote:
Is there a valid use for having "EHCleanup" that _doesn't_ handle branches across it? That is, do we _ever_ need a cleanup to be called only for an exception thrown, and not otherwise leaving the scope? I'm just wondering if we can simplify things conceptually here and remove an option.
The only case I can think of is, perhaps, constructor's member initializer lists.
That is...we apparently accept the following code...and it does, I suppose, what one might "expect": skips over construction of "b" and "c" and jumps into the middle of the constructor function, from which it returns normally as if the object was fully constructed. Using "return" instead of "goto" works too, also returning "successfully" from the constructor.
```
struct X { X(int); ~X(); };
struct Test {
Test() : a(1), b( ({ goto label; 2; }) ), c(3) { label: f();}
X a, b, c;
};
Test* test() { return new Test(); }
```
But...that really seems like code we should be rejecting as invalid (in which case, there need not be a distinction between cleanup due to exception or branch).
https://github.com/llvm/llvm-project/pull/80698
More information about the cfe-commits
mailing list