public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Fix array dimension handling on 32-bit host
@ 2015-12-02  1:28 Ian Lance Taylor
  2015-12-02  9:58 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Lance Taylor @ 2015-12-02  1:28 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 546 bytes --]

The Go frontend code that handled array dimensions when generating
reflection and mangling assumed that an array dimension would fit in
an unsigned long.  That is of course not true when a 32-bit host is
cross-compiling to a 64-bit target.  This patch fixes the problem.
This was reported as GCC PR 65717.  Bootstrapped and ran Go tests on
x86_64-pc-linux-gnu, and also on a 32-bit Solaris host crossing to a
64-bit Solaris target.  Committed to mainline.  Could be committed to
GCC 5 branch but I'm not sure whether the branch is open yet.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2360 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 231095)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-81eb6a3f425b2158c67ee32c0cc973a72ce9d6be
+c375f3bf470f94220149b486c947bb3eb57cde7d
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/types.cc
===================================================================
--- gcc/go/gofrontend/types.cc	(revision 231095)
+++ gcc/go/gofrontend/types.cc	(working copy)
@@ -6398,22 +6398,21 @@ Array_type::do_reflection(Gogo* gogo, st
   if (this->length_ != NULL)
     {
       Numeric_constant nc;
-      unsigned long val;
-      if (!this->length_->numeric_constant_value(&nc)
-	  || nc.to_unsigned_long(&val) != Numeric_constant::NC_UL_VALID)
+      if (!this->length_->numeric_constant_value(&nc))
 	{
-	  if (!this->issued_length_error_)
-	    {
-	      error_at(this->length_->location(), "invalid array length");
-	      this->issued_length_error_ = true;
-	    }
+	  go_assert(saw_errors());
+	  return;
 	}
-      else
+      mpz_t val;
+      if (!nc.to_int(&val))
 	{
-	  char buf[50];
-	  snprintf(buf, sizeof buf, "%lu", val);
-	  ret->append(buf);
+	  go_assert(saw_errors());
+	  return;
 	}
+      char* s = mpz_get_str(NULL, 10, val);
+      ret->append(s);
+      free(s);
+      mpz_clear(val);
     }
   ret->push_back(']');
 
@@ -6544,22 +6543,21 @@ Array_type::do_mangled_name(Gogo* gogo,
   if (this->length_ != NULL)
     {
       Numeric_constant nc;
-      unsigned long val;
-      if (!this->length_->numeric_constant_value(&nc)
-	  || nc.to_unsigned_long(&val) != Numeric_constant::NC_UL_VALID)
+      if (!this->length_->numeric_constant_value(&nc))
 	{
-	  if (!this->issued_length_error_)
-	    {
-	      error_at(this->length_->location(), "invalid array length");
-	      this->issued_length_error_ = true;
-	    }
+	  go_assert(saw_errors());
+	  return;
 	}
-      else
+      mpz_t val;
+      if (!nc.to_int(&val))
 	{
-	  char buf[50];
-	  snprintf(buf, sizeof buf, "%lu", val);
-	  ret->append(buf);
+	  go_assert(saw_errors());
+	  return;
 	}
+      char *s = mpz_get_str(NULL, 10, val);
+      ret->append(s);
+      free(s);
+      mpz_clear(val);
     }
   ret->push_back('e');
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Go patch committed: Fix array dimension handling on 32-bit host
  2015-12-02  1:28 Go patch committed: Fix array dimension handling on 32-bit host Ian Lance Taylor
@ 2015-12-02  9:58 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2015-12-02  9:58 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches, gofrontend-dev

On Wed, Dec 2, 2015 at 2:28 AM, Ian Lance Taylor <iant@golang.org> wrote:
> The Go frontend code that handled array dimensions when generating
> reflection and mangling assumed that an array dimension would fit in
> an unsigned long.  That is of course not true when a 32-bit host is
> cross-compiling to a 64-bit target.  This patch fixes the problem.
> This was reported as GCC PR 65717.  Bootstrapped and ran Go tests on
> x86_64-pc-linux-gnu, and also on a 32-bit Solaris host crossing to a
> 64-bit Solaris target.  Committed to mainline.  Could be committed to
> GCC 5 branch but I'm not sure whether the branch is open yet.

It is not, it will be again after GCC 5.3.0 was released next week.

Richard.

> Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-02  9:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-02  1:28 Go patch committed: Fix array dimension handling on 32-bit host Ian Lance Taylor
2015-12-02  9:58 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).