When there are multiple declarators in a declaration and the type
is specified via typeof, an expression inside the argument of
typeof may be evaluated multiple times. Fix this by adding a
save expression.
PR c/124576
gcc/c/ChangeLog:
* c-decl.cc (declspecs_add_type): Add save_expr.
gcc/testsuite/ChangeLog:
* gcc.dg/pr124576.c: New test.
}
if (spec.expr)
{
+ tree expr = save_expr (fold_convert (void_type_node, spec.expr));
if (specs->expr)
- specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr),
- specs->expr, spec.expr);
+ specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr),
+ specs->expr, expr);
else
- specs->expr = spec.expr;
+ specs->expr = expr;
specs->expr_const_operands &= spec.expr_const_operands;
}
}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-std=c99" } */
+
+int main()
+{
+ int i = 0;
+ int j = 0;
+ __typeof__((__typeof__(int[i++])*)(j++, (void*)0)) a, b, c;
+ if (1 != j)
+ __builtin_abort();
+}
+