From c59a46583bfe5de9a64208fcd9a7ef22586624aa Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 16 Mar 2024 06:21:22 -0500 Subject: [PATCH] Revert https://github.com/rizinorg/rizin/commit/722e5c0a624136b7a07cd4d2ee42e54d3c5fc0c6 It is dictated by BAP theory that the jumps come last. --- librz/il/il_validate.c | 5 +++++ test/unit/test_il_validate.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/librz/il/il_validate.c b/librz/il/il_validate.c index 8b62e644a1f..f191a0dabfa 100644 --- a/librz/il/il_validate.c +++ b/librz/il/il_validate.c @@ -980,6 +980,11 @@ VALIDATOR_EFFECT(seq) { VALIDATOR_DESCEND_EFFECT(args->x, &tx, ctx, {}); RzILTypeEffect ty; VALIDATOR_DESCEND_EFFECT(args->y, &ty, ctx, {}); + // Code after a jmp/goto makes no sense because the jmp naturally jumps somewhere else already. + // Intuitively, this could be considered just dead code and valid, but because it is not practically useful, + // we reject such code completely for now, which gives us more freedom if in the future we do want to define + // semantics for code after ctrl in some way. + VALIDATOR_ASSERT(!(tx & RZ_IL_TYPE_EFFECT_CTRL) || !ty, "Encountered further effects after a ctrl effect in seq op."); *type_out = tx | ty; return true; } diff --git a/test/unit/test_il_validate.c b/test/unit/test_il_validate.c index 9e0bb432112..d0b455952f3 100644 --- a/test/unit/test_il_validate.c +++ b/test/unit/test_il_validate.c @@ -869,6 +869,12 @@ static bool test_il_validate_effect_seq() { mu_assert_null(report, "no report"); rz_il_op_effect_free(op); + op = rz_il_op_new_seq(rz_il_op_new_jmp(rz_il_op_new_bitv_from_ut64(24, 0x100)), rz_il_op_new_set("x", true, rz_il_op_new_b0())); + val = rz_il_validate_effect(op, ctx, NULL, &t, &report); + mu_assert_false(val, "invalid"); + mu_assert_streq_free(report, "Encountered further effects after a ctrl effect in seq op.", "report"); + rz_il_op_effect_free(op); + op = rz_il_op_new_seq(rz_il_op_new_jmp(rz_il_op_new_bitv_from_ut64(24, 0x100)), rz_il_op_new_nop()); val = rz_il_validate_effect(op, ctx, NULL, &t, &report); mu_assert_true(val, "valid");