Patchwork [c-family] Fix -fdump-ada-spec buglet in C++

login
register
mail settings
Submitter Eric Botcazou
Date Oct. 15, 2012, 6:08 p.m.
Message ID <1967969.xFf7Crz380@polaris>
Download mbox | patch
Permalink /patch/191621/
State New
Headers show

Comments

Eric Botcazou - Oct. 15, 2012, 6:08 p.m.
Hi,

since the sizetype change, we generate invalid Ada for flexible array members 
with -fdump-ada-spec in C++.  The attached patch fixes this issue and also 
partially revamps the code to polish some rough edges.

Tested on x86_64-suse-linux, OK for mainline?


2012-10-15  Eric Botcazou  <ebotcazou@adacore.com>

c-family/
	* c-ada-spec.c (ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX): Define.
	(dump_generic_ada_node) <INTEGER_CST>: Deal with sizetype specially.
	Remove POINTER_TYPE handling, add large unsigned handling and use
	ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX for big numbers.


2012-10-15  Eric Botcazou  <ebotcazou@adacore.com>

	* g++.dg/other/dump-ada-spec-2.C: New test.
Joseph S. Myers - Oct. 15, 2012, 9:32 p.m.
On Mon, 15 Oct 2012, Eric Botcazou wrote:

> Hi,
> 
> since the sizetype change, we generate invalid Ada for flexible array members 
> with -fdump-ada-spec in C++.  The attached patch fixes this issue and also 
> partially revamps the code to polish some rough edges.
> 
> Tested on x86_64-suse-linux, OK for mainline?

OK.

Patch

Index: c-ada-spec.c
===================================================================
--- c-ada-spec.c	(revision 192447)
+++ c-ada-spec.c	(working copy)
@@ -30,6 +30,21 @@  along with GCC; see the file COPYING3.
 #include "c-pragma.h"
 #include "cpp-id-data.h"
 
+/* Adapted from hwint.h to use the Ada prefix.  */
+#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
+# if HOST_BITS_PER_WIDE_INT == 64
+#  define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \
+     "16#%" HOST_LONG_FORMAT "x%016" HOST_LONG_FORMAT "x#"
+# else
+#  define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \
+     "16#%" HOST_LONG_FORMAT "x%08" HOST_LONG_FORMAT "x#"
+# endif
+#else
+  /* We can assume that 'long long' is at least 64 bits.  */
+# define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \
+    "16#%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x#"
+#endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */
+
 /* Local functions, macros and variables.  */
 static int dump_generic_ada_node (pretty_printer *, tree, tree,
 				  int (*)(tree, cpp_operation), int, int, bool);
@@ -2175,12 +2190,16 @@  dump_generic_ada_node (pretty_printer *b
       break;
 
     case INTEGER_CST:
-      if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
-	{
-	  pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
-	  pp_string (buffer, "B"); /* pseudo-unit */
-	}
-      else if (!host_integerp (node, 0))
+      /* We treat the upper half of the sizetype range as negative.  This
+	 is consistent with the internal treatment and makes it possible
+	 to generate the (0 .. -1) range for flexible array members.  */
+      if (TREE_TYPE (node) == sizetype)
+	node = fold_convert (ssizetype, node);
+      if (host_integerp (node, 0))
+	pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
+      else if (host_integerp (node, 1))
+	pp_unsigned_wide_integer (buffer, TREE_INT_CST_LOW (node));
+      else
 	{
 	  tree val = node;
 	  unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
@@ -2193,12 +2212,10 @@  dump_generic_ada_node (pretty_printer *b
 	      low = -low;
 	    }
 	  sprintf (pp_buffer (buffer)->digit_buffer,
-	  HOST_WIDE_INT_PRINT_DOUBLE_HEX,
-	    (unsigned HOST_WIDE_INT) high, low);
+		   ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX,
+		   (unsigned HOST_WIDE_INT) high, low);
 	  pp_string (buffer, pp_buffer (buffer)->digit_buffer);
 	}
-      else
-	pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
       break;
 
     case REAL_CST: