Skip to content

Commit

Permalink
Fix type casts from initializer lists to arrays of unspecified size
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig committed Sep 7, 2017
1 parent 1fa569f commit 3273bf5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions regression/ansi-c/Initializer_cast2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main()
{
int A[(sizeof((int[]){1, 2, 3})==3*sizeof(int))?1:-1];

return 0;
}
7 changes: 7 additions & 0 deletions regression/ansi-c/Initializer_cast2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
--
^CONVERSION ERROR$
9 changes: 8 additions & 1 deletion src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,14 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
// or an expression for a pointer or scalar.
// We produce a compound_literal expression.
exprt tmp(ID_compound_literal, expr.type());
tmp.move_to_operands(op);
tmp.copy_to_operands(op);

// handle the case of TYPE being an array with unspecified size
if(op.id()==ID_array &&
expr.type().id()==ID_array &&
to_array_type(expr.type()).size().is_nil())
tmp.type()=op.type();

expr=tmp;
expr.set(ID_C_lvalue, true); // these are l-values
return;
Expand Down

0 comments on commit 3273bf5

Please sign in to comment.