From 05fb348da54dfe5d665e375d9986b1e0f910b76b Mon Sep 17 00:00:00 2001 From: jsm28 Date: Thu, 31 Mar 2005 23:34:44 +0000 Subject: [PATCH] PR c/17855 * gimplify.c (gimplify_expr): Create a temporary for lvalue COND_EXPR and CALL_EXPR. testsuite: * gcc.c-torture/compile/struct-non-lval-1.c, gcc.c-torture/compile/struct-non-lval-2.c, gcc.c-torture/compile/struct-non-lval-3.c: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@97352 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/gimplify.c | 18 ++++++++++++++++++ gcc/testsuite/ChangeLog | 7 +++++++ .../gcc.c-torture/compile/struct-non-lval-1.c | 7 +++++++ .../gcc.c-torture/compile/struct-non-lval-2.c | 7 +++++++ .../gcc.c-torture/compile/struct-non-lval-3.c | 7 +++++++ 6 files changed, 52 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/compile/struct-non-lval-1.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/struct-non-lval-2.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/struct-non-lval-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9b9ff0d..fac7f92 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-04-01 Joseph S. Myers + + PR c/17855 + * gimplify.c (gimplify_expr): Create a temporary for lvalue + COND_EXPR and CALL_EXPR. + 2005-03-31 Vladimir Makarov PR target/20632 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 9191bae..bd15e04 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3810,10 +3810,28 @@ gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p, case COND_EXPR: ret = gimplify_cond_expr (expr_p, pre_p, post_p, NULL_TREE, fallback); + /* C99 code may assign to an array in a structure value of a + conditional expression, and this has undefined behavior + only on execution, so create a temporary if an lvalue is + required. */ + if (fallback == fb_lvalue) + { + *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p); + lang_hooks.mark_addressable (*expr_p); + } break; case CALL_EXPR: ret = gimplify_call_expr (expr_p, pre_p, fallback != fb_none); + /* C99 code may assign to an array in a structure returned + from a function, and this has undefined behavior only on + execution, so create a temporary if an lvalue is + required. */ + if (fallback == fb_lvalue) + { + *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p); + lang_hooks.mark_addressable (*expr_p); + } break; case TREE_LIST: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6e6601d..f3c2617 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2005-04-01 Joseph S. Myers + + PR c/17855 + * gcc.c-torture/compile/struct-non-lval-1.c, + gcc.c-torture/compile/struct-non-lval-2.c, + gcc.c-torture/compile/struct-non-lval-3.c: New tests. + 2005-03-31 Janis Johnson * gcc.dg/tls/tls.exp: Remove temporary file. diff --git a/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-1.c b/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-1.c new file mode 100644 index 0000000..0924f5c --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-1.c @@ -0,0 +1,7 @@ +/* Bug c/17855. */ +struct foo {char x, y, z[2];}; +struct foo f(); +void bar(int baz) +{ + f().z[baz] = 1; +} diff --git a/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-2.c b/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-2.c new file mode 100644 index 0000000..daa0d17 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-2.c @@ -0,0 +1,7 @@ +/* Bug c/17855, using conditional expression for non-lvalue. */ +struct foo {char x, y, z[2];}; +struct foo p, q; int r; +void bar(int baz) +{ + (r ? p : q).z[baz] = 1; +} diff --git a/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-3.c b/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-3.c new file mode 100644 index 0000000..3020194 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/struct-non-lval-3.c @@ -0,0 +1,7 @@ +/* Bug c/17855, using assignment for non-lvalue. */ +struct foo {char x, y, z[2];}; +struct foo p, q; +void bar(int baz) +{ + (p = q).z[baz] = 1; +} -- 2.7.4