Go patch committed: Use correct check for index value overflow

Message ID CAOyqgcUB=4FNf3NFmNBBQhavd2U1aJ6MGyeEdaz-4iC+PZZo8g@mail.gmail.com
State Committed
Commit bd8a3eecc4edffad6e5091ae42c1cb1c1730b2ab
Series Go patch committed: Use correct check for index value overflow |


Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Ian Lance Taylor March 27, 2024, 11:09 p.m. UTC
  This patch to the Go frontend uses the correct size and comparison
when doing an index value overflow check.  This has apparently been
wrong since I introduced the code ten years ago.  This fixes GCC PR
114500.  Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.
Committed to mainline.



diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index de6e21fb3b5..50d430d5034 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@ 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 8429e553eac..238d5a56ca2 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -18790,7 +18790,7 @@  Composite_literal_expression::lower_array(Type* type)
 	  Named_type* ntype = Type::lookup_integer_type("int");
 	  Integer_type* inttype = ntype->integer_type();
-	  if (sizeof(index) <= static_cast<size_t>(inttype->bits() * 8)
+	  if (sizeof(index) >= static_cast<size_t>(inttype->bits() / 8)
 	      && index >> (inttype->bits() - 1) != 0)
 	      go_error_at(index_expr->location(), "index value overflow");