From 21ca8a32a0a2bf23a61eef96cf4fde85970582a1 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 9 Jul 2001 23:46:06 +0000 Subject: [PATCH] * typeck.c (unary_complex_lvalue): Do not duplicate the argument to modify, pre-, or post-increment when used as an lvalue and when the argument has side-effects. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@43884 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 8 +++++++- gcc/cp/typeck.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e07fd96fabc..1f77946cbf2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2001-07-09 Erik Rozendaal + + * typeck.c (unary_complex_lvalue): Do not duplicate the + argument to modify, pre-, or post-increment when used as an + lvalue and when the argument has side-effects. + 2001-07-08 Joseph S. Myers * decl.c (start_decl): Don't call SET_DEFAULT_DECL_ATTRIBUTES. @@ -12,7 +18,7 @@ 2001-07-06 Ira Ruben - * cp-tree.def (TEMPLATE_DECL): Update comment. DECL_RESULT should + * cp-tree.def (TEMPLATE_DECL): Update comment. DECL_RESULT should be DECL_TEMPLATE_RESULT. 2001-07-05 Kriang Lerdsuwanakij diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 1cf76e5980a..17b75cc362b 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4808,12 +4808,21 @@ unary_complex_lvalue (code, arg) || TREE_CODE (arg) == MIN_EXPR || TREE_CODE (arg) == MAX_EXPR) return rationalize_conditional_expr (code, arg); + /* Handle (a = b), (++a), and (--a) used as an "lvalue". */ if (TREE_CODE (arg) == MODIFY_EXPR || TREE_CODE (arg) == PREINCREMENT_EXPR || TREE_CODE (arg) == PREDECREMENT_EXPR) - return unary_complex_lvalue - (code, build (COMPOUND_EXPR, TREE_TYPE (TREE_OPERAND (arg, 0)), - arg, TREE_OPERAND (arg, 0))); + { + tree lvalue = TREE_OPERAND (arg, 0); + if (TREE_SIDE_EFFECTS (lvalue)) + { + lvalue = stabilize_reference (lvalue); + arg = build (TREE_CODE (arg), TREE_TYPE (arg), + lvalue, TREE_OPERAND (arg, 1)); + } + return unary_complex_lvalue + (code, build (COMPOUND_EXPR, TREE_TYPE (lvalue), arg, lvalue)); + } if (code != ADDR_EXPR) return 0; -- 2.11.0