-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Miscompile in code with indirect gotos #102351
Labels
Comments
Original C code extern int printf(const char *fmt, ...);
int main() {
void* bytecode[2];
bytecode[0] = &&VM__OP_1;
bytecode[1] = &&VM__TERMINATE;
int state = 0;
int index = 0;
while (1) {
switch (state) {
case 0:
goto *bytecode[index];
case 1:
// NOTE: THIS IS ONLY REACHABLE VIA INDIRECT GOTOS
VM__OP_1:
state = 2;
break;
case 2:
printf("OP_1:(instruction=%d)\n", index);
index++;
goto *bytecode[index];
}
}
VM__TERMINATE:
printf("TERMINATE:(instruction=%d)\n", index);
return 0;
} #76295 makes the miscompile go away(https://godbolt.org/z/d9bGnhhv6) but I think simplifycfg still has the bug. |
Looks like TryToSimplifyUncondBranchFromEmptyBlock is not handling indirectbr predecessors correctly: the indirectbr's successor list is rewritten so it has a successor that isn't address-taken. That edge is then proven impossible, so the indirectbr is completely eliminated. |
hiraditya
added a commit
that referenced
this issue
Sep 11, 2024
hiraditya
added a commit
that referenced
this issue
Nov 26, 2024
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this issue
Dec 2, 2024
The bug was introduced by llvm#68473 Fixes: llvm#102351 (cherry picked from commit 3c9022c)
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this issue
Dec 2, 2024
Remove check for PHI in pred as pointed out in llvm#103688 Reduced the testcase to remove redundant phi in pred Fixes: llvm#102351 (cherry picked from commit 39601a6)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The simplifycfg pass (incorrectly?) optimizes one of the case statements.
$ opt -passes=simplifycfg orig.ll -S -o out.ll
The text was updated successfully, but these errors were encountered: