Patchwork [C++] Fix PR53605

login
register
mail settings
Submitter Richard Guenther
Date June 11, 2012, 12:15 p.m.
Message ID <Pine.LNX.4.64.1206111413230.29541@jbgna.fhfr.qr>
Download mbox | patch
Permalink /patch/164124/
State New
Headers show

Comments

Richard Guenther - June 11, 2012, 12:15 p.m.
When I changed empty arrays domain to use a signed sizetype [0, -1]
domain mangling of a empty-array-type broke because mangling adds
an unsigned one to the signed -1 which causes an ICE (I chose to
do that instead of shifting the range to [1, 0] because much more
code relies on a zero lower bound ...).

The following fixes that by using double-ints for the arithmetic
and thus also does not generate a not needed tree node.

Bootstrapped and tested on x86_64-unknown-linux-gnu, ok?

Thanks,
Richard.

2012-06-11  Richard Guenther  <rguenther@suse.de>

	PR c++/53616
	* mangle.c (write_array_type): Use double-ints for array domain
	arithmetic.

	* g++.dg/ext/pr53605.C: New testcase.
Jason Merrill - June 11, 2012, 1:39 p.m.
OK.

Jason
H.J. Lu - June 23, 2012, 1:45 p.m.
On Mon, Jun 11, 2012 at 5:15 AM, Richard Guenther <rguenther@suse.de> wrote:
>
> When I changed empty arrays domain to use a signed sizetype [0, -1]
> domain mangling of a empty-array-type broke because mangling adds
> an unsigned one to the signed -1 which causes an ICE (I chose to
> do that instead of shifting the range to [1, 0] because much more
> code relies on a zero lower bound ...).
>
> The following fixes that by using double-ints for the arithmetic
> and thus also does not generate a not needed tree node.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, ok?
>
> Thanks,
> Richard.
>
> 2012-06-11  Richard Guenther  <rguenther@suse.de>
>
>        PR c++/53616
>        * mangle.c (write_array_type): Use double-ints for array domain
>        arithmetic.
>

This caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53752

Patch

Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 188384)
+++ gcc/cp/mangle.c	(working copy)
@@ -3119,8 +3119,10 @@  write_array_type (const tree type)
 	{
 	  /* The ABI specifies that we should mangle the number of
 	     elements in the array, not the largest allowed index.  */
-	  max = size_binop (PLUS_EXPR, max, size_one_node);
-	  write_unsigned_number (tree_low_cst (max, 1));
+	  double_int dmax
+	    = double_int_add (tree_to_double_int (max), double_int_one);
+	  gcc_assert (double_int_fits_in_uhwi_p (dmax));
+	  write_unsigned_number (dmax.low);
 	}
       else
 	{
Index: gcc/testsuite/g++.dg/ext/pr53605.C
===================================================================
--- gcc/testsuite/g++.dg/ext/pr53605.C	(revision 0)
+++ gcc/testsuite/g++.dg/ext/pr53605.C	(revision 0)
@@ -0,0 +1,16 @@ 
+// { dg-do compile }
+
+// Avoid -pedantic-error default
+// { dg-options "" }
+
+template <bool lhs_is_null_literal>
+class EqHelper {
+public:
+    template <typename T1, typename T2>
+	static int  Compare( const T1& expected,
+			     const T2& actual);
+};
+void foo(){
+    static const int kData[] = {};
+    ::EqHelper<false>::Compare(kData, "abc");
+}