public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/58943] [4.7/4.8/4.9 Regression] wrong calculation of indirect structure member arithmetic via function call Date: Wed, 04 Dec 2013 11:04:00 -0000 [thread overview] Message-ID: <bug-58943-4-zgshN6eb7M@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-58943-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58943 --- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> --- So something like: --- gcc/c/c-typeck.c.jj 2013-12-03 08:27:22.000000000 +0100 +++ gcc/c/c-typeck.c 2013-12-04 11:53:57.160894632 +0100 @@ -5192,6 +5192,7 @@ build_modify_expr (location_t location, { tree result; tree newrhs; + tree rhseval = NULL_TREE; tree rhs_semantic_type = NULL_TREE; tree lhstype = TREE_TYPE (lhs); tree olhstype = lhstype; @@ -5253,8 +5254,17 @@ build_modify_expr (location_t location, /* Construct the RHS for any non-atomic compound assignemnt. */ if (!is_atomic_op) { + /* If in LHS op= RHS the RHS has side-effects, ensure they + are preevaluated before the rest of the assignment expression's + side-effects, because RHS could contain e.g. function calls + that modify LHS. */ + if (TREE_SIDE_EFFECTS (rhs)) + { + newrhs = c_save_expr (rhs); + rhseval = newrhs; + } newrhs = build_binary_op (location, - modifycode, lhs, rhs, 1); + modifycode, lhs, newrhs, 1); /* The original type of the right hand side is no longer meaningful. */ @@ -5268,7 +5278,7 @@ build_modify_expr (location_t location, if so, we need to generate setter calls. */ result = objc_maybe_build_modify_expr (lhs, newrhs); if (result) - return result; + goto return_result; /* Else, do the check that we postponed for Objective-C. */ if (!lvalue_or_else (location, lhs, lv_assign)) @@ -5362,7 +5372,7 @@ build_modify_expr (location_t location, if (result) { protected_set_expr_location (result, location); - return result; + goto return_result; } } @@ -5383,11 +5393,15 @@ build_modify_expr (location_t location, as the LHS argument. */ if (olhstype == TREE_TYPE (result)) - return result; + goto return_result; result = convert_for_assignment (location, olhstype, result, rhs_origtype, ic_assign, false, NULL_TREE, NULL_TREE, 0); protected_set_expr_location (result, location); + +return_result: + if (rhseval) + result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result); return result; } ? In any case, it will have various consequences on OpenMP and perhaps vectorization.
next prev parent reply other threads:[~2013-12-04 11:04 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-10-31 16:00 [Bug c/58943] New: " Dimitar.Peikov at gmail dot com 2013-11-04 14:10 ` [Bug c/58943] [4.7/4.8/4.9 Regression] " rguenth at gcc dot gnu.org 2013-11-19 10:41 ` rguenth at gcc dot gnu.org 2013-12-03 15:02 ` jakub at gcc dot gnu.org 2013-12-03 16:57 ` joseph at codesourcery dot com 2013-12-04 11:04 ` jakub at gcc dot gnu.org [this message] 2013-12-04 17:01 ` joseph at codesourcery dot com 2014-01-15 8:04 ` jakub at gcc dot gnu.org 2014-06-12 13:46 ` [Bug c/58943] [4.7/4.8 " rguenth at gcc dot gnu.org 2014-12-19 13:40 ` [Bug c/58943] [4.8 " jakub at gcc dot gnu.org 2015-06-23 8:46 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-58943-4-zgshN6eb7M@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).