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

GH-98831: Update generate_cases.py: register inst, opcode_metadata.h #100735

Merged
merged 15 commits into from
Jan 5, 2023
Merged
Prev Previous commit
Next Next commit
add sanity check for opcode metadata
  • Loading branch information
iritkatriel committed Jan 4, 2023
commit 404053b44578b10471e67093760cb056884e4d88
22 changes: 22 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8670,6 +8670,27 @@ no_redundant_jumps(cfg_builder *g) {
return true;
}

static bool
opcode_metadata_is_sane(cfg_builder *g) {
for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
for (int i = 0; i < b->b_iused; i++) {
struct instr *instr = &b->b_instr[i];
int opcode = instr->i_opcode;
assert(opcode <= MAX_REAL_OPCODE);
int pushed = _PyOpcode_opcode_metadata[opcode].n_pushed;
int popped = _PyOpcode_opcode_metadata[opcode].n_popped;
assert((pushed < 0) == (popped < 0));
if (pushed >= 0) {
int effect = stack_effect(opcode, instr->i_oparg, -1);
if (effect != pushed - popped) {
return false;
}
}
}
}
return true;
}

static bool
no_empty_basic_blocks(cfg_builder *g) {
for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
Expand Down Expand Up @@ -8853,6 +8874,7 @@ assemble(struct compiler *c, int addNone)
}

assert(no_redundant_jumps(g));
assert(opcode_metadata_is_sane(g));

/* Can't modify the bytecode after computing jump offsets. */
assemble_jump_offsets(g->g_entryblock);
Expand Down