From: Richard Biener Date: Mon, 30 Oct 2017 12:43:45 +0000 (+0000) Subject: gimple-parser.c (c_parser_gimple_statement): Parse conditional stmts. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c1136864438968b76d5063c1af99118c19b1cf83;p=gcc.git gimple-parser.c (c_parser_gimple_statement): Parse conditional stmts. 2017-10-30 Richard Biener c/ * gimple-parser.c (c_parser_gimple_statement): Parse conditional stmts. * gcc.dg/gimplefe-27.c: New testcase. From-SVN: r254217 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index fe450ec4331..8bb9d372a77 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2017-10-30 Richard Biener + + * gimple-parser.c (c_parser_gimple_statement): Parse conditional + stmts. + 2017-10-27 Michael Meissner * c-decl.c (header_for_builtin_fn): Add support for copysign, fma, diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index c2e31df218c..8f624e3b9a2 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -419,6 +419,23 @@ c_parser_gimple_statement (c_parser *parser, gimple_seq *seq) 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6f98a1a7acc..598e4c082ab 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-10-30 Richard Biener + + * gcc.dg/gimplefe-27.c: New testcase. + 2017-10-30 Joseph Myers * gcc.dg/c17-version-1.c, gcc.dg/c17-version-2.c: New tests. diff --git a/gcc/testsuite/gcc.dg/gimplefe-27.c b/gcc/testsuite/gcc.dg/gimplefe-27.c new file mode 100644 index 00000000000..604a2cc2fcc --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-27.c @@ -0,0 +1,9 @@ +/* { dg-options "-O -fgimple" } */ + +int __GIMPLE () +p (int n) +{ + int _2; + _2 = n_1(D) != 0 ? 2 : 0; + return _2; +}