We missed handling of conditional stmts in assignments so the
following adds support for it.

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

Richard.

2017-10-30  Richard Biener  <rguent...@suse.de>

        c/
        * gimple-parser.c (c_parser_gimple_statement): Parse conditional
        stmts.

        * gcc.dg/gimplefe-27.c: New testcase.

Index: gcc/c/gimple-parser.c
===================================================================
--- gcc/c/gimple-parser.c       (revision 254211)
+++ gcc/c/gimple-parser.c       (working copy)
@@ -419,6 +419,23 @@ c_parser_gimple_statement (c_parser *par
   if (lhs.value != error_mark_node
       && rhs.value != error_mark_node)
     {
+      /* If we parsed a comparison and the next token is a '?' then
+         parse a conditional expression.  */
+      if (COMPARISON_CLASS_P (rhs.value)
+         && c_parser_next_token_is (parser, CPP_QUERY))
+       {
+         struct c_expr trueval, falseval;
+         c_parser_consume_token (parser);
+         trueval = c_parser_gimple_postfix_expression (parser);
+         falseval.set_error ();
+         if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
+           falseval = c_parser_gimple_postfix_expression (parser);
+         if (trueval.value == error_mark_node
+             || falseval.value == error_mark_node)
+           return;
+         rhs.value = build3_loc (loc, COND_EXPR, TREE_TYPE (trueval.value),
+                                 rhs.value, trueval.value, falseval.value);
+       }
       assign = gimple_build_assign (lhs.value, rhs.value);
       gimple_seq_add_stmt (seq, assign);
       gimple_set_location (assign, loc);
Index: gcc/testsuite/gcc.dg/gimplefe-27.c
===================================================================
--- gcc/testsuite/gcc.dg/gimplefe-27.c  (nonexistent)
+++ gcc/testsuite/gcc.dg/gimplefe-27.c  (working copy)
@@ -0,0 +1,9 @@
+/* { dg-options "-O -fgimple" } */
+
+int __GIMPLE ()
+p (int n)
+{
+  int _2;
+  _2 = n_1(D) != 0 ? 2 : 0;
+  return _2;
+}

Reply via email to