This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix ICE with inline asm and MODIFY_EXPR/preinc/predec in output operand (PR c++/84961)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 21 Mar 2018 11:26:06 +0100
- Subject: Re: [C++ PATCH] Fix ICE with inline asm and MODIFY_EXPR/preinc/predec in output operand (PR c++/84961)
- References: <20180320210452.GF8577@tucnak> <CADzB+2=NTxq8r5E4eK2G2Dng+Mb1a0AWzfhaCakNv+UfrSJpFg@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Mar 20, 2018 at 05:58:43PM -0400, Jason Merrill wrote:
> On Tue, Mar 20, 2018 at 5:04 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > --- 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.
You mean just outline the
if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
lhs = build2 (TREE_CODE (lhs), TREE_TYPE (lhs),
cp_stabilize_reference (TREE_OPERAND (lhs, 0)),
TREE_OPERAND (lhs, 1));
lhs = build2 (COMPOUND_EXPR, lhstype, lhs, TREE_OPERAND (lhs, 0));
into lhs = some_function (lhs); and use that in finish_asm_stmt,
unary_complex_lvalue and cp_build_modify_expr in these spots?
I really have no idea how to commonize anything else, e.g. the COMPOUND_EXPR
handling is substantially different between the 3 functions.
Any suggestion for the some_function name if you want that?
> Does COND_EXPR work without adjustment?
It seems to be:
int a, b;
void
foo (bool x)
{
asm volatile ("" : "=r" (x ? a : b));
}
void
bar (bool x)
{
asm volatile ("" : : "m" (x ? a : b));
}
I guess it should be added as another testcase.
Jakub