From 588d1952948769585bff991528868f4dec5db357 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 22 Sep 2004 23:51:58 +0100 Subject: [PATCH] re PR c/16566 (ICE with flexible arrays) PR c/16566 * c-typeck.c (build_component_ref): Don't special-case COMPOUND_EXPR. testsuite: * gcc.c-torture/compile/pr16566-1.c, gcc.c-torture/compile/pr16566-2.c, gcc.c-torture/compile/pr16566-3.c: New tests. From-SVN: r87892 --- gcc/ChangeLog | 6 ++++++ gcc/c-typeck.c | 20 ------------------- gcc/testsuite/ChangeLog | 7 +++++++ .../gcc.c-torture/compile/pr16566-1.c | 15 ++++++++++++++ .../gcc.c-torture/compile/pr16566-2.c | 13 ++++++++++++ .../gcc.c-torture/compile/pr16566-3.c | 12 +++++++++++ 6 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr16566-1.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr16566-2.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr16566-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0d59f07fa33..b0fe994abfd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-09-22 Joseph S. Myers + + PR c/16566 + * c-typeck.c (build_component_ref): Don't special-case + COMPOUND_EXPR. + 2004-09-22 Frank Ch. Eigler * dominance.c (verify_dominators): Don't SEGV if recount_dominator diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index d94965b19a1..35678e04f31 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -1452,26 +1452,6 @@ build_component_ref (tree datum, tree component) if (!objc_is_public (datum, component)) return error_mark_node; - /* If DATUM is a COMPOUND_EXPR, move our reference inside it. - Ensure that the arguments are not lvalues; otherwise, - if the component is an array, it would wrongly decay to a pointer in - C89 mode. - We cannot do this with a COND_EXPR, because in a conditional expression - the default promotions are applied to both sides, and this would yield - the wrong type of the result; for example, if the components have - type "char". */ - switch (TREE_CODE (datum)) - { - case COMPOUND_EXPR: - { - tree value = build_component_ref (TREE_OPERAND (datum, 1), component); - return build2 (COMPOUND_EXPR, TREE_TYPE (value), - TREE_OPERAND (datum, 0), non_lvalue (value)); - } - default: - break; - } - /* See if there is a field or component with name COMPONENT. */ if (code == RECORD_TYPE || code == UNION_TYPE) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d6226d5f85d..70f7b6f238b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2004-09-22 Joseph S. Myers + + PR c/16566 + * gcc.c-torture/compile/pr16566-1.c, + gcc.c-torture/compile/pr16566-2.c, + gcc.c-torture/compile/pr16566-3.c: New tests. + 2004-09-22 Kazu Hirata PR tree-optimization/17512 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr16566-1.c b/gcc/testsuite/gcc.c-torture/compile/pr16566-1.c new file mode 100644 index 00000000000..4ed4ab730e6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr16566-1.c @@ -0,0 +1,15 @@ +/* ICE with flexible arrays in non-lvalue structures. Bug 16566 + (comment #3). */ + +struct S; + +struct C { + int i; + struct S *tab[]; +}; + +struct S { struct C c; }; + +void foo (struct S *x) { + foo(((void)1, x->c).tab[0]); +} diff --git a/gcc/testsuite/gcc.c-torture/compile/pr16566-2.c b/gcc/testsuite/gcc.c-torture/compile/pr16566-2.c new file mode 100644 index 00000000000..c0036f0fc64 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr16566-2.c @@ -0,0 +1,13 @@ +/* ICE with flexible arrays in non-lvalue structures. Bug 16566 + (comment #5). */ + +struct A +{ + int i; + int x[]; +}; + +int foo(struct A a) +{ + return (a,a).x[0]; +} diff --git a/gcc/testsuite/gcc.c-torture/compile/pr16566-3.c b/gcc/testsuite/gcc.c-torture/compile/pr16566-3.c new file mode 100644 index 00000000000..954aa361da2 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr16566-3.c @@ -0,0 +1,12 @@ +/* ICE with flexible arrays in non-lvalue structures. Bug 16566 + (testcase from duplicate bug 16575). */ + +struct S; +struct C { + int i; + struct S *tab[]; +}; +struct S { struct C c; }; +void foo (struct S *x) { + ((void)1, x->c).tab[0] = 0; +} -- 2.30.2