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

Better C++ compatibility and fixes to conditional branch/switch handling #10

Merged
merged 7 commits into from
Nov 1, 2024
Prev Previous commit
Next Next commit
Fix Phi node handling after executing OpBranchConditional, OpSwitch i…
…nstructions
  • Loading branch information
mtehver committed Apr 18, 2022
commit a2a8534785453ad5791db968f34273afd50c446b
12 changes: 9 additions & 3 deletions src/opcode_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1929,10 +1929,13 @@ void spvm_execute_OpBranchConditional(spvm_word word_count, spvm_state_t state)
spvm_word true_branch = SPVM_READ_WORD(state->code_current);
spvm_word false_branch = SPVM_READ_WORD(state->code_current);

if (state->results[cond].members[0].value.b)
if (state->results[cond].members[0].value.b) {
state->code_current = state->results[true_branch].source_location;
else
state->function_stack_cfg[state->function_stack_current] = true_branch;
} else {
state->code_current = state->results[false_branch].source_location;
state->function_stack_cfg[state->function_stack_current] = false_branch;
}

state->did_jump = 1;
}
Expand All @@ -1952,13 +1955,16 @@ void spvm_execute_OpSwitch(spvm_word word_count, spvm_state_t state)

if (val == lit) {
state->code_current = state->results[lbl].source_location;
state->function_stack_cfg[state->function_stack_current] = lbl;
found = 1;
break;
}
}

if (!found)
if (!found) {
state->code_current = state->results[def_lbl].source_location;
state->function_stack_cfg[state->function_stack_current] = def_lbl;
}

state->did_jump = 1;
}
Expand Down