Skip to content

Commit f331ecc

Browse files
[cbmc2esbmc] overflow_result-+ and object_size subt are now operators
1 parent 19b45e2 commit f331ecc

File tree

1 file changed

+74
-9
lines changed

1 file changed

+74
-9
lines changed

src/adapter.rs

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ trait IrepAdapter {
2525
fn to_esbmc_irep(self) -> Irept;
2626
}
2727

28+
pub fn irep_contains(irep: &Irept, id: &str) -> bool {
29+
if irep.id == id {
30+
return true;
31+
}
32+
33+
for v in &irep.subt {
34+
if irep_contains(v, id) {
35+
return true;
36+
}
37+
}
38+
39+
for (_, v) in &irep.named_subt {
40+
if irep_contains(v, id) {
41+
return true;
42+
}
43+
}
44+
45+
for (_, v) in &irep.comments {
46+
if irep_contains(v, id) {
47+
return true;
48+
}
49+
}
50+
false
51+
}
52+
2853
impl From<CBMCParseResult> for ESBMCParseResult {
2954
fn from(data: CBMCParseResult) -> Self {
3055
let mut adapted = ESBMCParseResult {
@@ -50,7 +75,10 @@ impl From<CBMCParseResult> for ESBMCParseResult {
5075
// A symbol might have been defined later, we need to check everything again
5176
for symbol in &mut adapted.symbols_irep {
5277
symbol.fix_type(&type_cache);
53-
assert_ne!(symbol.named_subt["type"].id, "struct_tag");
78+
if irep_contains(symbol, "struct_tag") {
79+
panic!("Tag should have been filtered for {}", symbol.to_string());
80+
}
81+
5482
assert_ne!(symbol.named_subt["type"].id, "c_bool");
5583
}
5684

@@ -90,6 +118,9 @@ mod esbmcfixes {
90118
pub fn fix_name(name: &str) -> String {
91119
match name {
92120
"__CPROVER__start" => String::from("__ESBMC_main"),
121+
"_RNvNtNtCsesPP5EAma4_4core3num6verify24checked_unchecked_add_i8" => {
122+
"__ESBMC_main".to_string()
123+
}
93124
_ => String::from(name),
94125
}
95126
}
@@ -102,11 +133,7 @@ mod esbmcfixes {
102133
if irep.id == "constant"
103134
&& !["pointer", "bool"].contains(&irep.named_subt["type"].id.as_str())
104135
{
105-
// Value ID might be the decimal/hexa representation, we want the binary one!
106-
let width: usize = irep.named_subt["type"].named_subt["width"]
107-
.id
108-
.parse()
109-
.unwrap();
136+
// Value ID might be hexa representation or binary, we want the binary one!
110137
if 32 != irep.named_subt["value"].id.len() {
111138
let number = u64::from_str_radix(&irep.named_subt["value"].id, 16).unwrap();
112139
irep.named_subt.insert(
@@ -115,6 +142,7 @@ mod esbmcfixes {
115142
);
116143
}
117144
}
145+
118146
let expressions: HashSet<String> = HashSet::from(
119147
[
120148
"if",
@@ -132,6 +160,7 @@ mod esbmcfixes {
132160
"=",
133161
"<",
134162
">",
163+
"overflow_result-+",
135164
"lshr",
136165
"shl",
137166
"address_of",
@@ -141,6 +170,7 @@ mod esbmcfixes {
141170
"array_of",
142171
"sideeffect",
143172
"dereference",
173+
"object_size",
144174
"bitand",
145175
"struct",
146176
"return",
@@ -247,7 +277,6 @@ impl IrepAdapter for CBMCFunction {
247277
impl IrepAdapter for CBMCSymbol {
248278
fn to_esbmc_irep(self) -> Irept {
249279
let mut result = Irept::default();
250-
//result.id = String::from("symbol");
251280
result.named_subt.insert("type".to_string(), self.stype);
252281
result.named_subt.insert("symvalue".to_string(), self.value);
253282

@@ -265,16 +294,23 @@ impl IrepAdapter for CBMCSymbol {
265294

266295
let name = match self.name.as_str() {
267296
"__CPROVER__start" => "__ESBMC_main".to_string(),
268-
// "__CPROVER_initialize" => "__ESBMC_init".to_string(),
297+
"_RNvNtNtCsesPP5EAma4_4core3num6verify24checked_unchecked_add_i8" => {
298+
"__ESBMC_main".to_string()
299+
}
269300
_ => self.name.clone(),
270301
};
271302

272303
let basename = match self.base_name.as_str() {
273304
"__CPROVER__start" => "__ESBMC_main".to_string(),
274-
// "__CPROVER_initialize" => "__ESBMC_init".to_string(),
305+
"_RNvNtNtCsesPP5EAma4_4core3num6verify24checked_unchecked_add_i8" => {
306+
"__ESBMC_main".to_string()
307+
}
308+
275309
_ => self.base_name.clone(),
276310
};
277311

312+
assert_ne!(basename, "num::verify::checked_unchecked_add_i8");
313+
278314
if self.is_type {
279315
result
280316
.named_subt
@@ -596,6 +632,9 @@ impl Irept {
596632
}
597633

598634
if self.id == "pointer" && !self.named_subt.contains_key("subtype") {
635+
for v in &mut self.subt {
636+
v.fix_type(cache);
637+
}
599638
let mut operands = Irept::default();
600639
operands.subt = self.subt.clone();
601640
self.named_subt.insert("subtype".to_string(), operands);
@@ -645,6 +684,21 @@ impl Irept {
645684
}
646685

647686
*self = cache[&self.named_subt["identifier"]].clone();
687+
688+
// redo cache
689+
if irep_contains(self, "struct_tag") {
690+
for v in &mut self.subt {
691+
v.fix_type(cache);
692+
}
693+
694+
for (_, v) in &mut self.named_subt {
695+
v.fix_type(cache);
696+
}
697+
698+
for (_, v) in &mut self.comments {
699+
v.fix_type(cache);
700+
}
701+
}
648702
}
649703
}
650704

@@ -892,4 +946,15 @@ mod tests {
892946
run_goto_test("first_steps.rs.goto", &["--incremental-bmc"], 1);
893947
run_goto_test("first-steps-pass.goto", &["--incremental-bmc"], 0);
894948
}
949+
950+
#[test]
951+
#[ignore]
952+
fn unchecked_add_contract() {
953+
// Disabled because ESBMC does not support: object_size, overflow_result-+
954+
// run_goto_test(
955+
// "checked_unchecked_add_i8.goto",
956+
// &["--goto-functions-only"],
957+
// 0,
958+
// );
959+
}
895960
}

0 commit comments

Comments
 (0)