Skip to content

Commit b032d1a

Browse files
committed
goto-symex: nil array size must not have a type added
An expression has a type() member, which the nil irept lacks. Trying to access (in a non-const context) the type() member would thus create it, which in turn means that it no longer compares equal to a nil_exprt. As SSA renaming did access the type() member in such a way, the type of an array without specified size would no longer compare equal to the irept describing the type as generated by the C front-end, which in turn made simplification fail. The problem was surfaced by running cbmc --unwind 2 --pointer-check --bounds-check on c/ldv-linux-4.2-rc1/linux-4.2-rc1.tar.xz-32_7a-drivers--gpu--drm--i915--i915.ko-entry_point.cil.out.i from SV-COMP.
1 parent 813a0ad commit b032d1a

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ goto_symex_statet::rename(exprt expr, const namespacet &ns)
252252
as_const(address_of_expr).object().type();
253253
return renamedt<exprt, level>{std::move(expr)};
254254
}
255+
else if(expr.is_nil())
256+
{
257+
return renamedt<exprt, level>{std::move(expr)};
258+
}
255259
else
256260
{
257261
rename<level>(expr.type(), irep_idt(), ns);

src/goto-symex/renaming_level.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ bool check_renaming(const exprt &expr)
263263
if(to_ssa_expr(expr).get_original_expr().type() != type)
264264
return true;
265265
}
266+
else if(expr.id() == ID_nil)
267+
{
268+
return expr != nil_exprt{};
269+
}
266270
else
267271
{
268272
forall_operands(it, expr)

src/util/std_types.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ Author: Daniel Kroening, [email protected]
1818
#include "std_expr.h"
1919
#include "string2int.h"
2020

21+
void array_typet::check(const typet &type, const validation_modet vm)
22+
{
23+
PRECONDITION(type.id() == ID_array);
24+
const array_typet &array_type = static_cast<const array_typet &>(type);
25+
if(array_type.size().is_nil())
26+
{
27+
DATA_CHECK(
28+
vm,
29+
array_type.size() == nil_exprt{},
30+
"nil array size must be exactly nil");
31+
}
32+
}
33+
2134
std::size_t fixedbv_typet::get_integer_bits() const
2235
{
2336
const irep_idt integer_bits=get(ID_integer_bits);

src/util/std_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,10 @@ class array_typet:public type_with_subtypet
984984
{
985985
return size().is_nil();
986986
}
987+
988+
static void check(
989+
const typet &type,
990+
const validation_modet vm = validation_modet::INVARIANT);
987991
};
988992

989993
/// Check whether a reference to a typet is a \ref array_typet.

src/util/validate_types.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ void call_on_type(const typet &type, Args &&... args)
5252
{
5353
CALL_ON_TYPE(c_bool_typet);
5454
}
55+
else if(type.id() == ID_array)
56+
{
57+
CALL_ON_TYPE(array_typet);
58+
}
5559
else
5660
{
5761
#ifdef REPORT_UNIMPLEMENTED_TYPE_CHECKS

0 commit comments

Comments
 (0)