gimple-parser.c (c_parser_gimple_postfix_expression): Parse _Literal ( type-name...
authorRichard Biener <rguenther@suse.de>
Fri, 13 Jan 2017 08:16:59 +0000 (08:16 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 13 Jan 2017 08:16:59 +0000 (08:16 +0000)
2017-01-13  Richard Biener  <rguenther@suse.de>

c/
* gimple-parser.c (c_parser_gimple_postfix_expression): Parse
_Literal ( type-name ) number.

* tree-pretty-print.c (dump_generic_node): Dump INTEGER_CSTs
as _Literal ( type ) number in case usual suffixes do not
preserve all information.

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

From-SVN: r244393

gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/gimple-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/gimplefe-22.c [new file with mode: 0644]
gcc/tree-pretty-print.c

index a635cc7d5698bbc78b9cf166771d0428f304722d..d79749ecefe401562cc104371cdc97b06fc23254 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-13  Richard Biener  <rguenther@suse.de>
+
+       * tree-pretty-print.c (dump_generic_node): Dump INTEGER_CSTs
+       as _Literal ( type ) number in case usual suffixes do not
+       preserve all information.
+
 2017-01-12  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        PR target/79004
index 65531aa34754a3bcaf89d6b5af4d1f012270d63c..fd6f74b3b4136a57795d64cd2fd9db7aa11846d0 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-13  Richard Biener  <rguenther@suse.de>
+
+       * gimple-parser.c (c_parser_gimple_postfix_expression): Parse
+       _Literal ( type-name ) number.
+
 2017-01-12  Richard Biener  <rguenther@suse.de>
 
        * gimple-parser.c (c_parser_gimple_postfix_expression): Parse
index ee8a01a7f93861738237896906d7591176c9656c..927c68545cf31e3464b0b6e6d3e323dcb748aee7 100644 (file)
@@ -799,6 +799,32 @@ c_parser_gimple_postfix_expression (c_parser *parser)
                                       type, ptr.value, alias_off);
              break;
            }
+         else if (strcmp (IDENTIFIER_POINTER (id), "_Literal") == 0)
+           {
+             /* _Literal '(' type-name ')' number  */
+             c_parser_consume_token (parser);
+             tree type = NULL_TREE;
+             if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+               {
+                 struct c_type_name *type_name = c_parser_type_name (parser);
+                 tree tem;
+                 if (type_name)
+                   type = groktypename (type_name, &tem, NULL);
+                 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
+                                            "expected %<)%>");
+               }
+             tree val = c_parser_gimple_postfix_expression (parser).value;
+             if (! type
+                 || ! val
+                 || val == error_mark_node
+                 || TREE_CODE (val) != INTEGER_CST)
+               {
+                 c_parser_error (parser, "invalid _Literal");
+                 return expr;
+               }
+             expr.value = fold_convert (type, val);
+             return expr;
+           }
          /* SSA name.  */
          unsigned version, ver_offset;
          if (! lookup_name (id)
index 4dc4fc1109fbe750762573d86a662439332372a3..91b769c0be5118a323324a721919f89ac565d6f6 100644 (file)
@@ -1,3 +1,7 @@
+2017-01-13  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/gimplefe-22.c: New testcase.
+
 2017-01-13  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/77283
diff --git a/gcc/testsuite/gcc.dg/gimplefe-22.c b/gcc/testsuite/gcc.dg/gimplefe-22.c
new file mode 100644 (file)
index 0000000..8e213b9
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+void __GIMPLE ()
+foo (short * p)
+{
+  *p = _Literal (short int) 1;
+  return;
+}
index 87b404475eeeb7f3873a81dbac952cbaea034319..ebce67ec3e16930b118f20b013382b55a90ab833 100644 (file)
@@ -1664,6 +1664,16 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags,
       break;
 
     case INTEGER_CST:
+      if (flags & TDF_GIMPLE
+         && (POINTER_TYPE_P (TREE_TYPE (node))
+             || (TYPE_PRECISION (TREE_TYPE (node))
+                 < TYPE_PRECISION (integer_type_node))
+             || exact_log2 (TYPE_PRECISION (TREE_TYPE (node))) == -1))
+       {
+         pp_string (pp, "_Literal (");
+         dump_generic_node (pp, TREE_TYPE (node), spc, flags, false);
+         pp_string (pp, ") ");
+       }
       if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE
          && ! (flags & TDF_GIMPLE))
        {
@@ -1693,11 +1703,7 @@ 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));
-         if (flags & TDF_GIMPLE)
-           pp_character (pp, 'U');
-       }
+       pp_unsigned_wide_integer (pp, tree_to_uhwi (node));
       else
        {
          wide_int val = node;
@@ -1710,6 +1716,24 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags,
          print_hex (val, pp_buffer (pp)->digit_buffer);
          pp_string (pp, pp_buffer (pp)->digit_buffer);
        }
+      if ((flags & TDF_GIMPLE)
+         && (POINTER_TYPE_P (TREE_TYPE (node))
+             || (TYPE_PRECISION (TREE_TYPE (node))
+                 < TYPE_PRECISION (integer_type_node))
+             || exact_log2 (TYPE_PRECISION (TREE_TYPE (node))) == -1))
+       {
+         if (TYPE_UNSIGNED (TREE_TYPE (node)))
+           pp_character (pp, 'u');
+         if (TYPE_PRECISION (TREE_TYPE (node))
+             == TYPE_PRECISION (unsigned_type_node))
+           ;
+         else if (TYPE_PRECISION (TREE_TYPE (node))
+                  == TYPE_PRECISION (long_unsigned_type_node))
+           pp_character (pp, 'l');
+         else if (TYPE_PRECISION (TREE_TYPE (node))
+                  == TYPE_PRECISION (long_long_unsigned_type_node))
+           pp_string (pp, "ll");
+       }
       if (TREE_OVERFLOW (node))
        pp_string (pp, "(OVF)");
       break;