Skip to content

Commit 9491f09

Browse files
committed
expr2c: output ID_allocate in a way that goto-cc can compile
We can compile __CPROVER_allocate, but wouldn't be able to handle ALLOCATE(type, size, bool).
1 parent d148ae6 commit 9491f09

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,24 +1156,30 @@ std::string expr2ct::convert_allocate(const exprt &src, unsigned &precedence)
11561156
if(src.operands().size() != 2)
11571157
return convert_norep(src, precedence);
11581158

1159-
unsigned p0;
1160-
std::string op0 = convert_with_precedence(to_binary_expr(src).op0(), p0);
1159+
const binary_exprt &binary_expr = to_binary_expr(src);
11611160

11621161
unsigned p1;
1163-
std::string op1 = convert_with_precedence(to_binary_expr(src).op1(), p1);
1162+
std::string op1 = convert_with_precedence(binary_expr.op1(), p1);
11641163

1165-
std::string dest = "ALLOCATE";
1164+
std::string dest = CPROVER_PREFIX "allocate";
11661165
dest += '(';
11671166

1167+
const typet &type =
1168+
static_cast<const typet &>(binary_expr.op0().find(ID_C_c_sizeof_type));
11681169
if(
11691170
src.type().id() == ID_pointer &&
1170-
to_pointer_type(src.type()).base_type().id() != ID_empty)
1171+
to_pointer_type(src.type()).base_type() == type)
11711172
{
1172-
dest += convert(to_pointer_type(src.type()).base_type());
1173+
dest += "sizeof(" + convert(to_pointer_type(src.type()).base_type()) + ')';
11731174
dest+=", ";
11741175
}
1176+
else
1177+
{
1178+
unsigned p0;
1179+
dest += convert_with_precedence(binary_expr.op0(), p0);
1180+
}
11751181

1176-
dest += op0 + ", " + op1;
1182+
dest += ", " + op1;
11771183
dest += ')';
11781184

11791185
return dest;

0 commit comments

Comments
 (0)