public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][GIMPLEFE] Parse ?: stmts
@ 2017-10-30 10:47 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2017-10-30 10:47 UTC (permalink / raw)
  To: gcc-patches


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  <rguenther@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;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-10-30 10:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-30 10:47 [PATCH][GIMPLEFE] Parse ?: stmts Richard Biener

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).