Skip to content

Commit e229b4c

Browse files
committed
Typecheck initializer lists
1 parent 999ad15 commit e229b4c

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

regression/cpp/gcc_vector1/main.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifdef __GNUC__
2+
3+
typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
4+
5+
__m128 setzero(void)
6+
{
7+
return (__m128){ 0.0f, 0.0f, 0.0f, 0.0f };
8+
}
9+
10+
#else
11+
12+
void setzero()
13+
{
14+
}
15+
16+
#endif
17+
18+
int main(int argc, char* argv[])
19+
{
20+
setzero();
21+
return 0;
22+
}

regression/cpp/gcc_vector1/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.cpp
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^CONVERSION ERROR$
8+
^warning: ignoring

src/cpp/cpp_typecheck_expr.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,25 @@ void cpp_typecheckt::typecheck_expr_explicit_typecast(exprt &expr)
939939
else
940940
typecheck_type(expr.type());
941941

942+
// We allow (TYPE){ initializer_list }
943+
// This is called "compound literal", and is syntactic
944+
// sugar for a (possibly local) declaration.
945+
if(expr.op0().id()==ID_initializer_list)
946+
{
947+
// just do a normal initialization
948+
do_initializer(expr.op0(), expr.type(), false);
949+
950+
// This produces a struct-expression,
951+
// union-expression, array-expression,
952+
// or an expression for a pointer or scalar.
953+
// We produce a compound_literal expression.
954+
exprt tmp(ID_compound_literal, expr.type());
955+
tmp.move_to_operands(expr.op0());
956+
expr=tmp;
957+
expr.set(ID_C_lvalue, true); // these are l-values
958+
return;
959+
}
960+
942961
exprt new_expr;
943962

944963
if(const_typecast(expr.op0(), expr.type(), new_expr) ||

0 commit comments

Comments
 (0)