Skip to content

Commit

Permalink
Typecheck initializer lists
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig committed Jun 11, 2018
1 parent 999ad15 commit e229b4c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions regression/cpp/gcc_vector1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifdef __GNUC__

typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));

__m128 setzero(void)
{
return (__m128){ 0.0f, 0.0f, 0.0f, 0.0f };
}

#else

void setzero()
{
}

#endif

int main(int argc, char* argv[])
{
setzero();
return 0;
}
8 changes: 8 additions & 0 deletions regression/cpp/gcc_vector1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.cpp

^EXIT=0$
^SIGNAL=0$
--
^CONVERSION ERROR$
^warning: ignoring
19 changes: 19 additions & 0 deletions src/cpp/cpp_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,25 @@ void cpp_typecheckt::typecheck_expr_explicit_typecast(exprt &expr)
else
typecheck_type(expr.type());

// We allow (TYPE){ initializer_list }
// This is called "compound literal", and is syntactic
// sugar for a (possibly local) declaration.
if(expr.op0().id()==ID_initializer_list)
{
// just do a normal initialization
do_initializer(expr.op0(), expr.type(), false);

// This produces a struct-expression,
// union-expression, array-expression,
// 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(expr.op0());
expr=tmp;
expr.set(ID_C_lvalue, true); // these are l-values
return;
}

exprt new_expr;

if(const_typecast(expr.op0(), expr.type(), new_expr) ||
Expand Down

0 comments on commit e229b4c

Please sign in to comment.