aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2005-04-01 00:34:44 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2005-04-01 00:34:44 +0100
commit0223e4f514d36b505bf23ae213b99886bebe0dad (patch)
tree7792b0bdd163e128984c1a5dd6701ff7587ff7e3 /gcc/gimplify.c
parent96ddf8ef2326b2da28955873ff0b5ab921f481c0 (diff)
downloadgcc-0223e4f514d36b505bf23ae213b99886bebe0dad.zip
gcc-0223e4f514d36b505bf23ae213b99886bebe0dad.tar.gz
gcc-0223e4f514d36b505bf23ae213b99886bebe0dad.tar.bz2
re PR c/17855 (modification of function struct return not diagnosed)
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. From-SVN: r97352
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r--gcc/gimplify.c18
1 files changed, 18 insertions, 0 deletions
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: