public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6267] compiler: check for floating-point exponent overflow
@ 2020-12-18 23:56 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2020-12-18 23:56 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5128f8d0d99008d4f069bbaef9ee4372fe5da7ce

commit r11-6267-g5128f8d0d99008d4f069bbaef9ee4372fe5da7ce
Author: Ian Lance Taylor <iant@golang.org>
Date:   Tue Dec 15 21:52:23 2020 -0800

    compiler: check for floating-point exponent overflow
    
    Adjust mksysinfo and mkrsysinfo to strip out floating-point max numbers,
    as they can trigger this error.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/278476

Diff:
---
 gcc/go/gofrontend/MERGE                            |  2 +-
 gcc/go/gofrontend/lex.cc                           |  4 ++++
 .../go.test/test/fixedbugs/issue11326b.go          |  4 ++++
 gcc/testsuite/go.test/test/fixedbugs/issue13471.go | 22 +++++++++++-----------
 libgo/mkrsysinfo.sh                                |  1 +
 libgo/mksysinfo.sh                                 |  1 +
 6 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 6567db167a2..40242cc6a3f 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-526037336231593939a517b7c0b2892d413adb40
+1317de50147304a226b3ec5c4d81376470c358e5
 
 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/lex.cc b/gcc/go/gofrontend/lex.cc
index e71b8cddf65..0baf4e4e24b 100644
--- a/gcc/go/gofrontend/lex.cc
+++ b/gcc/go/gofrontend/lex.cc
@@ -1316,9 +1316,13 @@ Lex::gather_number()
 	}
     }
 
+  mpfr_clear_overflow();
   mpfr_t val;
   int r = mpfr_init_set_str(val, num.c_str(), base, MPFR_RNDN);
   go_assert(r == 0);
+  if (mpfr_overflow_p())
+    go_error_at(this->location(),
+		"floating-point exponent too large to represent");
 
   bool is_imaginary = *p == 'i';
   if (is_imaginary)
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue11326b.go b/gcc/testsuite/go.test/test/fixedbugs/issue11326b.go
index 8aba4d91215..b5f933bfea1 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue11326b.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue11326b.go
@@ -1,5 +1,9 @@
 // run
 
+// Does not work with gccgo, which uses a smaller (but still permitted)
+// exponent size.
+// +build !gccgo
+
 // Copyright 2015 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue13471.go b/gcc/testsuite/go.test/test/fixedbugs/issue13471.go
index 9bfc8c3d2cf..9069412ffa6 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue13471.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue13471.go
@@ -9,17 +9,17 @@
 package main
 
 func main() {
-	const _ int64 = 1e646456992 // ERROR "integer too large|floating-point constant truncated to integer"
-	const _ int32 = 1e64645699  // ERROR "integer too large|floating-point constant truncated to integer"
-	const _ int16 = 1e6464569   // ERROR "integer too large|floating-point constant truncated to integer"
-	const _ int8 = 1e646456     // ERROR "integer too large|floating-point constant truncated to integer"
-	const _ int = 1e64645       // ERROR "integer too large|floating-point constant truncated to integer"
+	const _ int64 = 1e646456992 // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
+	const _ int32 = 1e64645699  // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
+	const _ int16 = 1e6464569   // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
+	const _ int8 = 1e646456     // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
+	const _ int = 1e64645       // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
 
-	const _ uint64 = 1e646456992 // ERROR "integer too large|floating-point constant truncated to integer"
-	const _ uint32 = 1e64645699  // ERROR "integer too large|floating-point constant truncated to integer"
-	const _ uint16 = 1e6464569   // ERROR "integer too large|floating-point constant truncated to integer"
-	const _ uint8 = 1e646456     // ERROR "integer too large|floating-point constant truncated to integer"
-	const _ uint = 1e64645       // ERROR "integer too large|floating-point constant truncated to integer"
+	const _ uint64 = 1e646456992 // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
+	const _ uint32 = 1e64645699  // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
+	const _ uint16 = 1e6464569   // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
+	const _ uint8 = 1e646456     // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
+	const _ uint = 1e64645       // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
 
-	const _ rune = 1e64645 // ERROR "integer too large|floating-point constant truncated to integer"
+	const _ rune = 1e64645 // ERROR "integer too large|floating-point constant truncated to integer|exponent too large"
 }
diff --git a/libgo/mkrsysinfo.sh b/libgo/mkrsysinfo.sh
index c28f0e5f1f6..e016ca4dc59 100755
--- a/libgo/mkrsysinfo.sh
+++ b/libgo/mkrsysinfo.sh
@@ -26,6 +26,7 @@ grep -v '^// ' gen-sysinfo.go | \
   grep -v '^type _*locale[_ ]' | \
   grep -v 'in6_addr' | \
   grep -v 'sockaddr_in6' | \
+  egrep -v '^const _*FLT(64|128)_(NORM_)?MAX' | \
   sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1timeval\2/g' \
       -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
       -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh
index b32a0266b71..24d4ce2df6b 100755
--- a/libgo/mksysinfo.sh
+++ b/libgo/mksysinfo.sh
@@ -38,6 +38,7 @@ grep -v '^// ' gen-sysinfo.go | \
   grep -v '^type _*locale[_ ]' | \
   grep -v 'in6_addr' | \
   grep -v 'sockaddr_in6' | \
+  egrep -v '^const _*FLT(64|128)_(NORM_)?MAX' | \
   sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
       -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
       -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-18 23:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18 23:56 [gcc r11-6267] compiler: check for floating-point exponent overflow Ian Lance Taylor

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).