This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Don't crash on out of range switch value
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Fri, 18 Feb 2011 20:36:38 -0800
- Subject: Go patch committed: Don't crash on out of range switch value
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 -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);