diff mbox

Go patch committed: Don't crash on out of range switch value

Message ID mcrmxls7i95.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Feb. 19, 2011, 4:36 a.m. UTC
This patch to the Go frontend avoids a crash when a switch case has an
untyped constant whose value is out of range for the type of the switch
value.  Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
diff mbox

Patch

diff -r a71271749889 go/statements.cc
--- a/go/statements.cc	Fri Feb 18 20:22:58 2011 -0800
+++ b/go/statements.cc	Fri Feb 18 20:33:16 2011 -0800
@@ -3212,7 +3212,12 @@ 
 	  mpz_t ival;
 	  mpz_init(ival);
 	  if (!(*p)->integer_constant_value(true, ival, &itype))
-	    gcc_unreachable();
+	    {
+	      // Something went wrong.  This can happen with a
+	      // negative constant and an unsigned switch value.
+	      gcc_assert(saw_errors());
+	      continue;
+	    }
 	  gcc_assert(itype != NULL);
 	  tree type_tree = itype->get_tree(context->gogo());
 	  tree val = Expression::integer_constant_tree(ival, type_tree);