|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Unit tests for byte_extract/byte_update lowering |
| 4 | +
|
| 5 | + Author: Michael Tautschnig |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <testing-utils/catch.hpp> |
| 10 | + |
| 11 | +#include <solvers/lowering/expr_lowering.h> |
| 12 | + |
| 13 | +#include <util/arith_tools.h> |
| 14 | +#include <util/byte_operators.h> |
| 15 | +#include <util/c_types.h> |
| 16 | +#include <util/expr_util.h> |
| 17 | +#include <util/namespace.h> |
| 18 | +#include <util/simplify_expr.h> |
| 19 | +#include <util/std_types.h> |
| 20 | +#include <util/symbol_table.h> |
| 21 | + |
| 22 | +SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]") |
| 23 | +{ |
| 24 | + const symbol_tablet symbol_table; |
| 25 | + const namespacet ns(symbol_table); |
| 26 | + |
| 27 | + GIVEN("A byte_extract over a POD") |
| 28 | + { |
| 29 | + const exprt deadbeef = from_integer(0xdeadbeef, unsignedbv_typet(32)); |
| 30 | + const byte_extract_exprt be1( |
| 31 | + ID_byte_extract_little_endian, |
| 32 | + deadbeef, |
| 33 | + from_integer(1, index_type()), |
| 34 | + signedbv_typet(8)); |
| 35 | + |
| 36 | + THEN("byte_extract lowering yields the expected value") |
| 37 | + { |
| 38 | + const exprt lower_be1 = lower_byte_extract(be1, ns); |
| 39 | + const exprt lower_be1_s = simplify_expr(lower_be1, ns); |
| 40 | + |
| 41 | + REQUIRE(!has_subexpr(lower_be1, ID_byte_extract_little_endian)); |
| 42 | + REQUIRE(lower_be1.type() == be1.type()); |
| 43 | + REQUIRE(lower_be1_s == from_integer(0xbe, signedbv_typet(8))); |
| 44 | + |
| 45 | + byte_extract_exprt be2 = be1; |
| 46 | + be2.id(ID_byte_extract_big_endian); |
| 47 | + const exprt lower_be2 = lower_byte_extract(be2, ns); |
| 48 | + const exprt lower_be2_s = simplify_expr(lower_be2, ns); |
| 49 | + |
| 50 | + REQUIRE(!has_subexpr(lower_be2, ID_byte_extract_big_endian)); |
| 51 | + REQUIRE(lower_be2.type() == be2.type()); |
| 52 | + REQUIRE(lower_be2_s == from_integer(0xad, signedbv_typet(8))); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +SCENARIO("byte_update_lowering", "[core][solvers][lowering][byte_update]") |
| 58 | +{ |
| 59 | + const symbol_tablet symbol_table; |
| 60 | + const namespacet ns(symbol_table); |
| 61 | + |
| 62 | + GIVEN("A byte_update of a POD") |
| 63 | + { |
| 64 | + const exprt deadbeef = from_integer(0xdeadbeef, unsignedbv_typet(32)); |
| 65 | + const byte_update_exprt bu1( |
| 66 | + ID_byte_update_little_endian, |
| 67 | + deadbeef, |
| 68 | + from_integer(1, index_type()), |
| 69 | + from_integer(0x42, unsignedbv_typet(8))); |
| 70 | + |
| 71 | + THEN("byte_update lowering yields the expected value") |
| 72 | + { |
| 73 | + const exprt lower_bu1 = lower_byte_operators(bu1, ns); |
| 74 | + const exprt lower_bu1_s = simplify_expr(lower_bu1, ns); |
| 75 | + |
| 76 | + REQUIRE(!has_subexpr(lower_bu1, ID_byte_extract_little_endian)); |
| 77 | + REQUIRE(!has_subexpr(lower_bu1, ID_byte_update_little_endian)); |
| 78 | + REQUIRE(lower_bu1.type() == bu1.type()); |
| 79 | + REQUIRE(lower_bu1_s == from_integer(0xdead42ef, unsignedbv_typet(32))); |
| 80 | + |
| 81 | +#if 0 |
| 82 | + // this is currently broken, #2058 will fix it |
| 83 | + byte_update_exprt bu2 = bu1; |
| 84 | + bu2.id(ID_byte_update_big_endian); |
| 85 | + const exprt lower_bu2 = lower_byte_operators(bu2, ns); |
| 86 | + const exprt lower_bu2_s = simplify_expr(lower_bu2, ns); |
| 87 | + |
| 88 | + REQUIRE(!has_subexpr(lower_bu2, ID_byte_extract_big_endian)); |
| 89 | + REQUIRE(!has_subexpr(lower_bu2, ID_byte_update_big_endian)); |
| 90 | + REQUIRE(lower_bu2.type() == bu2.type()); |
| 91 | + REQUIRE(lower_bu2_s == from_integer(0xde42beef, unsignedbv_typet(32))); |
| 92 | +#endif |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments