Skip to content

Commit 8fc63dc

Browse files
committed
Add INVARIANTS checking for empty structs
These may required in order to support code which uses empty structs as a C language extension supported by some C compilers. However until we implement support in cbmc, it is important to stop with a relevant message.
1 parent c8c2396 commit 8fc63dc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/solvers/smt2_incremental/struct_encoding.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ typet struct_encodingt::encode(typet type) const
3232
work_queue.pop();
3333
if(const auto struct_tag = type_try_dynamic_cast<struct_tag_typet>(current))
3434
{
35-
current = bv_typet{(*boolbv_width)(*struct_tag)};
35+
const auto width = (*boolbv_width)(*struct_tag);
36+
if(width == 0)
37+
UNIMPLEMENTED_FEATURE("support for zero bit width structs.");
38+
current = bv_typet{width};
3639
}
3740
if(const auto array = type_try_dynamic_cast<array_typet>(current))
3841
{
@@ -44,6 +47,9 @@ typet struct_encodingt::encode(typet type) const
4447

4548
static exprt encode(const struct_exprt &struct_expr)
4649
{
50+
INVARIANT(
51+
!struct_expr.operands().empty(),
52+
"empty structs may not be encoded into SMT terms.");
4753
if(struct_expr.operands().size() == 1)
4854
return struct_expr.operands().front();
4955
return concatenation_exprt{struct_expr.operands(), struct_expr.type()};

0 commit comments

Comments
 (0)