Skip to content

Commit ac2eaf3

Browse files
committed
New option --mmio-regions to specify memory regions
This new option will enable us to eventually drop support for __CPROVER_allocated_memory, which 1) requires awkward scanning of goto functions in goto_check_c, 2) wrongly suggests these declarations are limited to some scope, and 3) yields a spurious undefined-function warning in symex.
1 parent f6054b5 commit ac2eaf3

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE broken-smt-backend
2+
main.c
3+
--pointer-check -DCMDLINE --mmio-regions 0x10:4
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main\.pointer_dereference\.2\] .* dereference failure: invalid integer address in \*p: SUCCESS$
7+
^\[main\.assertion\.1\] .* assertion \*p==42: SUCCESS$
8+
^\[main\.pointer_dereference\.[0-9]+\] .* dereference failure: invalid integer address in p\[.*1\]: FAILURE$
9+
^\[main\.assertion\.2\] .* assertion \*\(p\+1\)==42: SUCCESS$
10+
^VERIFICATION FAILED$
11+
--
12+
^warning: ignoring

regression/cbmc/memory_allocation1/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ int main()
44
{
55
int *p=0x10;
66

7+
#ifndef CMDLINE
78
__CPROVER_allocated_memory(0x10, sizeof(int));
9+
#endif
810
*p=42;
911
assert(*p==42);
1012
*(p+1)=42;

src/ansi-c/goto_check_c.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Author: Daniel Kroening, kroening@kroening.com
3333
#include <util/simplify_expr.h>
3434
#include <util/std_code.h>
3535
#include <util/std_expr.h>
36+
#include <util/string_utils.h>
3637

3738
#include <goto-programs/goto_model.h>
3839
#include <goto-programs/remove_skip.h>
@@ -44,6 +45,8 @@ Author: Daniel Kroening, kroening@kroening.com
4445
#include <algorithm>
4546
#include <optional>
4647

48+
#include "literals/convert_integer_literal.h"
49+
4750
class goto_check_ct
4851
{
4952
public:
@@ -76,6 +79,8 @@ class goto_check_ct
7679
error_labels = _options.get_list_option("error-label");
7780
enable_pointer_primitive_check =
7881
_options.get_bool_option("pointer-primitive-check");
82+
83+
parse_mmio_regions(_options.get_option("mmio-regions"));
7984
}
8085

8186
typedef goto_functionst::goto_functiont goto_functiont;
@@ -327,6 +332,8 @@ class goto_check_ct
327332
/// \returns a pair (name, status) if the match succeeds
328333
/// and the name is known, nothing otherwise.
329334
named_check_statust match_named_check(const irep_idt &named_check) const;
335+
336+
void parse_mmio_regions(const std::string &regions);
330337
};
331338

332339
/// Allows to:
@@ -452,6 +459,22 @@ void goto_check_ct::collect_allocations(const goto_functionst &goto_functions)
452459
}
453460
}
454461

462+
void goto_check_ct::parse_mmio_regions(const std::string &regions)
463+
{
464+
for(const std::string &range : split_string(regions, ',', true, true))
465+
{
466+
const auto sep = range.find(':');
467+
if(sep == std::string::npos || sep + 1 == range.size())
468+
continue;
469+
470+
const std::string start = range.substr(0, sep);
471+
const std::string size = range.substr(sep + 1);
472+
473+
allocations.push_back(
474+
{convert_integer_literal(start), convert_integer_literal(size)});
475+
}
476+
}
477+
455478
void goto_check_ct::invalidate(const exprt &lhs)
456479
{
457480
if(lhs.id() == ID_index)

src/ansi-c/goto_check_c.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void goto_check_c(
4444
"(pointer-overflow-check)(conversion-check)(undefined-shift-check)" \
4545
"(float-overflow-check)(nan-check)(no-built-in-assertions)" \
4646
"(pointer-primitive-check)" \
47+
"(mmio-regions):" \
4748
"(retain-trivial-checks)" \
4849
"(error-label):" \
4950
"(no-assertions)(no-assumptions)" \
@@ -64,6 +65,8 @@ void goto_check_c(
6465
" --nan-check check floating-point for NaN\n" \
6566
" --enum-range-check checks that all enum type expressions have values in the enum range\n" /* NOLINT(whitespace/line_length) */ \
6667
" --pointer-primitive-check checks that all pointers in pointer primitives are valid or null\n" /* NOLINT(whitespace/line_length) */ \
68+
" --mmio-regions addr:sz,... list of start-address:size address ranges\n" \
69+
" permitted for read/write access\n" \
6770
" --retain-trivial-checks include checks that are trivially true\n" \
6871
" --error-label label check that label is unreachable\n" \
6972
" --no-built-in-assertions ignore assertions in built-in library\n" \
@@ -86,6 +89,8 @@ void goto_check_c(
8689
options.set_option("nan-check", cmdline.isset("nan-check")); \
8790
options.set_option("built-in-assertions", !cmdline.isset("no-built-in-assertions")); /* NOLINT(whitespace/line_length) */ \
8891
options.set_option("pointer-primitive-check", cmdline.isset("pointer-primitive-check")); /* NOLINT(whitespace/line_length) */ \
92+
if(cmdline.isset("mmio-regions")) \
93+
options.set_option("mmio-regions", cmdline.get_values("mmio-regions")); \
8994
options.set_option("retain-trivial-checks", \
9095
cmdline.isset("retain-trivial-checks")); \
9196
options.set_option("assertions", !cmdline.isset("no-assertions")); /* NOLINT(whitespace/line_length) */ \

0 commit comments

Comments
 (0)