From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [C++ PATCH] Fix ICE with inline asm and MODIFY_EXPR/preinc/predec in output operand (PR c++/84961)
Date: Tue, 20 Mar 2018 22:01:00 -0000 [thread overview]
Message-ID: <CADzB+2=NTxq8r5E4eK2G2Dng+Mb1a0AWzfhaCakNv+UfrSJpFg@mail.gmail.com> (raw)
In-Reply-To: <20180320210452.GF8577@tucnak>
On Tue, Mar 20, 2018 at 5:04 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> While in C, x = 10 or ++x or --x aren't lvalues and so we reject such
> expressions in inline asm output operands (and inputs that only allow
> memory, not registers), in C++ they apparently are lvalues; for output
> operands we ICE in the gimplifier on this, because in the generic code
> MODIFY_EXPR or PREINCREMENT_EXPR or PREDECREMENT_EXPR aren't considered
> to be lvalues, and for "m" inputs we just reject them, but when those
> expressions are allowed on lhs of a store, they should be IMHO allowed
> as "m" inputs too.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2018-03-20 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/84961
> * semantics.c (finish_asm_stmt): Replace MODIFY_EXPR, PREINCREMENT_EXPR
> and PREDECREMENT_EXPR in output and "m" constrained input operands with
> COMPOUND_EXPR. Call cxx_mark_addressable on the rightmost
> COMPOUND_EXPR operand.
>
> * c-c++-common/pr43690.c: Don't expect errors on "m" (--x) and
> "m" (++x) in C++.
> * g++.dg/torture/pr84961-1.C: New test.
> * g++.dg/torture/pr84961-2.C: New test.
>
> --- gcc/cp/semantics.c.jj 2018-03-20 11:58:17.069356145 +0100
> +++ gcc/cp/semantics.c 2018-03-20 21:56:43.745292245 +0100
> @@ -1512,6 +1512,26 @@ finish_asm_stmt (int volatile_p, tree st
> && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
> cxx_readonly_error (operand, lv_asm);
>
> + tree *op = &operand;
> + while (TREE_CODE (*op) == COMPOUND_EXPR)
> + op = &TREE_OPERAND (*op, 1);
> + switch (TREE_CODE (*op))
> + {
> + case PREINCREMENT_EXPR:
> + case PREDECREMENT_EXPR:
> + case MODIFY_EXPR:
> + if (TREE_SIDE_EFFECTS (TREE_OPERAND (*op, 0)))
> + *op = build2 (TREE_CODE (*op), TREE_TYPE (*op),
> + cp_stabilize_reference (TREE_OPERAND (*op, 0)),
> + TREE_OPERAND (*op, 1));
> + *op = build2 (COMPOUND_EXPR, TREE_TYPE (*op), *op,
> + TREE_OPERAND (*op, 0));
> + op = &TREE_OPERAND (*op, 1);
> + break;
> + default:
> + break;
> + }
Hmm, it would be nice to share this with the similar patterns in
unary_complex_lvalue and cp_build_modify_expr.
Does COND_EXPR work without adjustment?
Jason
next prev parent reply other threads:[~2018-03-20 21:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-20 21:06 Jakub Jelinek
2018-03-20 22:01 ` Jason Merrill [this message]
2018-03-21 10:34 ` Jakub Jelinek
2018-03-21 17:03 ` Jason Merrill
2018-03-21 20:40 ` [C++ PATCH] Fix ICE with inline asm and MODIFY_EXPR/preinc/predec in output operand (PR c++/84961, take 2) Jakub Jelinek
2018-03-21 17:52 ` Jason Merrill
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='CADzB+2=NTxq8r5E4eK2G2Dng+Mb1a0AWzfhaCakNv+UfrSJpFg@mail.gmail.com' \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/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: link
Be 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).