Skip to content

Commit 3f48b6e

Browse files
committed
Check for lvalue in assigns clause after type checking
Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent 38ca41f commit 3f48b6e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,7 @@ void ansi_c_convert_typet::read_rec(const typet &type)
256256

257257
for(const exprt &target : to_unary_expr(as_expr).op().operands())
258258
{
259-
if(!is_lvalue(target))
260-
{
261-
error().source_location = target.source_location();
262-
error() << "illegal target in assigns clause" << eom;
263-
throw 0;
264-
}
265-
else if(has_subexpr(target, ID_side_effect))
259+
if(has_subexpr(target, ID_side_effect))
266260
{
267261
error().source_location = target.source_location();
268262
error() << "Assigns clause is not side-effect free." << eom;

src/ansi-c/c_typecheck_base.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,21 @@ void c_typecheck_baset::typecheck_declaration(
739739
}
740740

741741
for(auto &target : code_type.assigns())
742+
{
742743
typecheck_expr(target);
744+
if(target.type().id() == ID_empty)
745+
{
746+
error().source_location = target.source_location();
747+
error() << "void-typed targets not permitted" << eom;
748+
throw 0;
749+
}
750+
if(!target.get_bool(ID_C_lvalue))
751+
{
752+
error().source_location = target.source_location();
753+
error() << "illegal target in assigns clause" << eom;
754+
throw 0;
755+
}
756+
}
743757

744758
if(!as_const(code_type).ensures().empty())
745759
{

0 commit comments

Comments
 (0)