mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
c: argument expressions may be evaluated too often by typeof [PR124576]
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.
This commit is contained in:
committed by
Martin Uecker
parent
9c40f8de18
commit
9aaedeaced
@@ -13136,11 +13136,12 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs,
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
12
gcc/testsuite/gcc.dg/pr124576.c
Normal file
12
gcc/testsuite/gcc.dg/pr124576.c
Normal file
@@ -0,0 +1,12 @@
|
||||
/* { 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user