Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Instruction does not dominate all uses' wrt. ternary expressions using array literals #4570

Open
kinke opened this issue Jan 29, 2024 · 1 comment

Comments

@kinke
Copy link
Member

kinke commented Jan 29, 2024

struct S {
    ~this() {}
}

int foo(S[] ss...) { return 0; }

void bar(bool a) {
    const r = a ? foo(S()) : foo(S());
}

The frontend lowers the ternary to (a) ? foo([(S())][]) : foo([(S())][]).

@kinke
Copy link
Member Author

kinke commented Jan 30, 2024

This is probably going to be tricky to solve. The problem is that we have two S[1] static array allocas for the implicit array literals, one for each branch, but the compiler generates temporaries for the S elements, and those have a custom dtor expression, so that they are only destructed if that branch was taken (i.e., the first S temporary gets a a && tmp1.~this() edtor, the 2nd one a a || tmp2.~this()).

What we do is emplace the element temporaries into the static array directly. The lvalues of the temporaries are thus GEPs into the static array allocas, not allocas directly (which would definitely dominate all uses). And those GEPs are created in the respective branches only, so don't dominate all uses in the cleanups (even though the dtor call would be disabled anyway if that branch wasn't taken).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant