From: Richard Biener Date: Thu, 12 Jan 2017 08:33:09 +0000 (+0000) Subject: tree-pretty-print.c (dump_generic_node): Provide -gimple variant for MEM_REF. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6bb4ea5cdf9664f2cec861a2a120192b4ac04d1f;p=gcc.git tree-pretty-print.c (dump_generic_node): Provide -gimple variant for MEM_REF. 2017-01-12 Richard Biener * tree-pretty-print.c (dump_generic_node): Provide -gimple variant for MEM_REF. Sanitize INTEGER_CST for -gimple. c/ * gimple-parser.c (c_parser_gimple_postfix_expression): Parse __MEM. * gcc.dg/gimplefe-21.c: New testcase. From-SVN: r244350 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 20da95331ea..012c095c78f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-01-12 Richard Biener + + * tree-pretty-print.c (dump_generic_node): Provide -gimple + variant for MEM_REF. Sanitize INTEGER_CST for -gimple. + 2017-01-12 Richard Biener * tree.c (initialize_tree_contains_struct): Make TS_OPTIMIZATION diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 341407a21de..65531aa3475 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2017-01-12 Richard Biener + + * gimple-parser.c (c_parser_gimple_postfix_expression): Parse + __MEM. + 2017-01-11 Jakub Jelinek PR c++/72813 diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 37e792ac355..ee8a01a7f93 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -727,6 +727,79 @@ c_parser_gimple_postfix_expression (c_parser *parser) if (c_parser_peek_token (parser)->id_kind == C_ID_ID) { tree id = c_parser_peek_token (parser)->value; + if (strcmp (IDENTIFIER_POINTER (id), "__MEM") == 0) + { + /* __MEM '<' type-name [ ',' number ] '>' + '(' [ '(' type-name ')' ] unary-expression + [ '+' number ] ')' */ + location_t loc = c_parser_peek_token (parser)->location; + c_parser_consume_token (parser); + struct c_type_name *type_name = NULL; + tree alignment = NULL_TREE; + if (c_parser_require (parser, CPP_LESS, "expected %<<%>")) + { + type_name = c_parser_type_name (parser); + /* Optional alignment. */ + if (c_parser_next_token_is (parser, CPP_COMMA)) + { + c_parser_consume_token (parser); + alignment + = c_parser_gimple_postfix_expression (parser).value; + } + c_parser_skip_until_found (parser, + CPP_GREATER, "expected %<>%>"); + } + struct c_expr ptr; + ptr.value = error_mark_node; + tree alias_off = NULL_TREE; + if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) + { + tree alias_type = NULL_TREE; + /* Optional alias-type cast. */ + if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) + { + c_parser_consume_token (parser); + struct c_type_name *alias_type_name + = c_parser_type_name (parser); + c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, + "expected %<)%>"); + if (alias_type_name) + { + tree tem; + alias_type = groktypename (alias_type_name, + &tem, NULL); + } + } + ptr = c_parser_gimple_unary_expression (parser); + if (! alias_type) + alias_type = TREE_TYPE (ptr.value); + /* Optional constant offset. */ + if (c_parser_next_token_is (parser, CPP_PLUS)) + { + c_parser_consume_token (parser); + alias_off + = c_parser_gimple_postfix_expression (parser).value; + alias_off = fold_convert (alias_type, alias_off); + } + if (! alias_off) + alias_off = build_int_cst (alias_type, 0); + c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, + "expected %<)%>"); + } + if (! type_name || c_parser_error (parser)) + { + c_parser_set_error (parser, false); + return expr; + } + tree tem = NULL_TREE; + tree type = groktypename (type_name, &tem, NULL); + if (alignment) + type = build_aligned_type (type, tree_to_uhwi (alignment)); + expr.value = build2_loc (loc, MEM_REF, + type, ptr.value, alias_off); + break; + } + /* SSA name. */ unsigned version, ver_offset; if (! lookup_name (id) && c_parser_parse_ssa_name_id (id, &version, &ver_offset)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b10c0360710..561bd3fe539 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-01-12 Richard Biener + + * gcc.dg/gimplefe-21.c: New testcase. + 2017-01-12 Michael Collison * gcc.dg/zero_bits_compound-2.c: Fix test for aarch64. diff --git a/gcc/testsuite/gcc.dg/gimplefe-21.c b/gcc/testsuite/gcc.dg/gimplefe-21.c new file mode 100644 index 00000000000..55ea0b825c5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-21.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +float __GIMPLE () +foo (int * p) +{ + float f; + float D1800; + unsigned int D1799; + + D1799 = __MEM ((char *)p + 1); + __MEM ((char *)&f + 0xfffffffffffffffe) = D1799; + __MEM (p) = 1; + __MEM (p) = 1; + __MEM (p + 2) = 1; + __MEM ((char *)p) = 1; + D1800 = f; + return D1800; +} diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 36b29d53878..87b404475ee 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -1459,7 +1459,38 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags, case MEM_REF: { - if (integer_zerop (TREE_OPERAND (node, 1)) + if (flags & TDF_GIMPLE) + { + pp_string (pp, "__MEM <"); + dump_generic_node (pp, TREE_TYPE (node), + spc, flags | TDF_SLIM, false); + if (TYPE_ALIGN (TREE_TYPE (node)) + != TYPE_ALIGN (TYPE_MAIN_VARIANT (TREE_TYPE (node)))) + { + pp_string (pp, ", "); + pp_decimal_int (pp, TYPE_ALIGN (TREE_TYPE (node))); + } + pp_greater (pp); + pp_string (pp, " ("); + if (TREE_TYPE (TREE_OPERAND (node, 0)) + != TREE_TYPE (TREE_OPERAND (node, 1))) + { + pp_left_paren (pp); + dump_generic_node (pp, TREE_TYPE (TREE_OPERAND (node, 1)), + spc, flags | TDF_SLIM, false); + pp_right_paren (pp); + } + dump_generic_node (pp, TREE_OPERAND (node, 0), + spc, flags | TDF_SLIM, false); + if (! integer_zerop (TREE_OPERAND (node, 1))) + { + pp_string (pp, " + "); + dump_generic_node (pp, TREE_OPERAND (node, 1), + spc, flags | TDF_SLIM, false); + } + pp_right_paren (pp); + } + else if (integer_zerop (TREE_OPERAND (node, 1)) /* Dump the types of INTEGER_CSTs explicitly, for we can't infer them and MEM_ATTR caching will share MEM_REFs with differently-typed op0s. */ @@ -1633,7 +1664,8 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags, break; case INTEGER_CST: - if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE) + if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE + && ! (flags & TDF_GIMPLE)) { /* In the case of a pointer, one may want to divide by the size of the pointed-to type. Unfortunately, this not @@ -1661,7 +1693,11 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags, else if (tree_fits_shwi_p (node)) pp_wide_integer (pp, tree_to_shwi (node)); else if (tree_fits_uhwi_p (node)) - pp_unsigned_wide_integer (pp, tree_to_uhwi (node)); + { + pp_unsigned_wide_integer (pp, tree_to_uhwi (node)); + if (flags & TDF_GIMPLE) + pp_character (pp, 'U'); + } else { wide_int val = node;