Skip to content

Commit c3d101d

Browse files
committed
---
yaml --- r: 83311 b: refs/heads/variant-submodule c: e690c5f h: refs/heads/develop i: 83309: c764708 83307: 4ebdcd6 83303: 324bfc7 83295: 6b5139e
1 parent 2936db0 commit c3d101d

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ refs/heads/unwind-counters4: 57aedaa3fe3995b30ba69c96c9f04df79f8e8ff8
131131
refs/heads/value-set-make-member: 0f8404cb460f55d43bc253e12f1bde7fd7ed4d37
132132
refs/heads/value-set-member-fix: 2c87bd4c0d9e1954e2de6af0118fa1ef296ae548
133133
"refs/heads/value_set_fi_hacks": 3d243543adb4ff450596e7994e2fa1d590ec1e1b
134-
refs/heads/variant-submodule: 9a26a63c03d4adcd7dff59e8435f116b10285fa4
134+
refs/heads/variant-submodule: e690c5f9662b14211c6e30c955b4e844800d3d99
135135
refs/heads/windows-console-streambuf: b984ac7bd772da956bb5656f0072d85b3fdbbf34
136136
refs/tags/cbmc-5.10: 097cf712f57d59cff9c53a9fb7b9b81be1245f93
137137
refs/tags/cbmc-5.11: 90d0de91b0918c9e5d5ed250cae62241ae38392a

branches/variant-submodule/unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SRC += analyses/ai/ai.cpp \
3636
analyses/variable-sensitivity/value_set_abstract_object/merge.cpp \
3737
analyses/variable-sensitivity/value_set_abstract_object/widening_merge.cpp \
3838
analyses/variable-sensitivity/variable_sensitivity_test_helpers.cpp \
39+
ansi-c/expr2c.cpp \
3940
ansi-c/max_malloc_size.cpp \
4041
ansi-c/type2name.cpp \
4142
big-int/big-int.cpp \
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*******************************************************************\
2+
3+
Module: Unit test for expr2c
4+
5+
Author: Diffblue
6+
7+
\*******************************************************************/
8+
9+
#include <ansi-c/expr2c.h>
10+
#include <testing-utils/use_catch.h>
11+
#include <util/arith_tools.h>
12+
#include <util/bitvector_expr.h>
13+
#include <util/bitvector_types.h>
14+
#include <util/config.h>
15+
#include <util/namespace.h>
16+
#include <util/symbol_table.h>
17+
18+
TEST_CASE("rol_2_c_conversion_unsigned", "[core][ansi-c][expr2c]")
19+
{
20+
auto lhs = from_integer(31, unsignedbv_typet(32));
21+
auto rhs = from_integer(3, unsignedbv_typet(32));
22+
auto rol = shift_exprt(lhs, ID_rol, rhs);
23+
CHECK(
24+
expr2c(rol, namespacet{symbol_tablet{}}) ==
25+
"31 << 3 % 32 | 31 >> 32 - 3 % 32");
26+
}
27+
28+
TEST_CASE("rol_2_c_conversion_signed", "[core][ansi-c][expr2c]")
29+
{
30+
// The config lines are necessary since when we do casting from signed
31+
// to unsigned in the rol/ror bit twiddling we need to output a
32+
// suitable cast type (e.g. "unsigned int" and not
33+
// "unsigned __CPROVER_bitvector").
34+
config.ansi_c.mode = configt::ansi_ct::flavourt::GCC;
35+
config.ansi_c.set_arch_spec_i386();
36+
auto lhs = from_integer(31, signedbv_typet(8));
37+
auto rhs = from_integer(3, signedbv_typet(8));
38+
auto rol = shift_exprt(lhs, ID_rol, rhs);
39+
CHECK(
40+
expr2c(rol, namespacet{symbol_tablet{}}) ==
41+
"(unsigned char)31 << 3 % 8 | (unsigned char)31 >> 8 - 3 % 8");
42+
}
43+
44+
TEST_CASE("ror_2_c_conversion_unsigned", "[core][ansi-c][expr2c]")
45+
{
46+
auto lhs = from_integer(31, unsignedbv_typet(32));
47+
auto rhs = from_integer(3, unsignedbv_typet(32));
48+
auto ror = shift_exprt(lhs, ID_ror, rhs);
49+
CHECK(
50+
expr2c(ror, namespacet{symbol_tablet{}}) ==
51+
"31 >> 3 % 32 | 31 << 32 - 3 % 32");
52+
}
53+
54+
TEST_CASE("ror_2_c_conversion_signed", "[core][ansi-c][expr2c]")
55+
{
56+
// The config lines are necessary since when we do casting from signed
57+
// to unsigned in the rol/ror bit twiddling we need to output a
58+
// suitable cast type (e.g. "unsigned int" and not
59+
// "unsigned __CPROVER_bitvector").
60+
config.ansi_c.mode = configt::ansi_ct::flavourt::GCC;
61+
config.ansi_c.set_arch_spec_i386();
62+
auto lhs = from_integer(31, integer_bitvector_typet(ID_signedbv, 32));
63+
auto rhs = from_integer(3, integer_bitvector_typet(ID_signedbv, 32));
64+
auto ror = shift_exprt(lhs, ID_ror, rhs);
65+
CHECK(
66+
expr2c(ror, namespacet{symbol_tablet{}}) ==
67+
"(unsigned int)31 >> 3 % 32 | (unsigned int)31 << 32 - 3 % 32");
68+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
testing-utils
22
ansi-c
3+
util

0 commit comments

Comments
 (0)