]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
a68: Add error on integral denotation overflow
authorJames Bohl <bohlj47@gmail.com>
Thu, 26 Feb 2026 03:59:44 +0000 (22:59 -0500)
committerJose E. Marchesi <jemarch@gnu.org>
Thu, 26 Feb 2026 11:31:53 +0000 (12:31 +0100)
Signed-off-by: James Bohl <bohlj47@gmail.com>
gcc/algol68/ChangeLog

* a68-low-units.cc (a68_lower_denotation): Add error on
integral denotation overflow.

gcc/testsuite/ChangeLog

* algol68/compile/error-denotation-1.a68: New test.
* algol68/compile/error-denotation-2.a68: Likewise.
* algol68/compile/error-denotation-3.a68: Likewise.
* algol68/execute/plusab-1.a68: Fixed denotation overflow.

gcc/algol68/a68-low-units.cc
gcc/testsuite/algol68/compile/error-denotation-1.a68 [new file with mode: 0644]
gcc/testsuite/algol68/compile/error-denotation-2.a68 [new file with mode: 0644]
gcc/testsuite/algol68/compile/error-denotation-3.a68 [new file with mode: 0644]
gcc/testsuite/algol68/execute/plusab-1.a68

index ba0ab5e238297ff4690a802bc44a72689f769915..8257d2dc96c73f930a8d6caa478e3b4df960868a 100644 (file)
@@ -41,6 +41,7 @@
 #include "convert.h"
 
 #include "a68.h"
+#include "a68-pretty-print.h"
 
 /* Note that enclosed clauses, which are units, are handled in
    a68-low-clauses.  */
@@ -250,8 +251,19 @@ a68_lower_denotation (NODE_T *p, LOW_CTX_T ctx)
        s = SUB (p);
 
       type = CTYPE (moid);
+      errno = 0;
+#if defined(INT64_T_IS_LONG)
       int64_t val = strtol (NSYMBOL (s), &end, 10);
+#else
+      int64_t val = strtoll (NSYMBOL (s), &end, 10);
+#endif
       gcc_assert (end[0] == '\0');
+      if (errno == ERANGE || val > wi::max_value (type).to_shwi ())
+       {
+         a68_moid_format_token m (moid);
+         a68_error (s, "denotation is too large for %e", &m);
+       }
+
       return build_int_cst (type, val);
     }
   if (moid == M_BITS
diff --git a/gcc/testsuite/algol68/compile/error-denotation-1.a68 b/gcc/testsuite/algol68/compile/error-denotation-1.a68
new file mode 100644 (file)
index 0000000..f911cc3
--- /dev/null
@@ -0,0 +1,4 @@
+{ dg-options {-fstropping=supper} }
+begin int i0 := 123456789012345678901234567890; { dg-error "denotation is too large for int" }
+      skip
+end
diff --git a/gcc/testsuite/algol68/compile/error-denotation-2.a68 b/gcc/testsuite/algol68/compile/error-denotation-2.a68
new file mode 100644 (file)
index 0000000..3aa1ef9
--- /dev/null
@@ -0,0 +1,6 @@
+{ dg-options {-fstropping=supper} }
+{ dg-require-effective-target int32 }
+begin int i0 := 2147483648; { dg-error "denotation is too large for int" }
+      int i1 := 2147483647;
+      skip
+end
diff --git a/gcc/testsuite/algol68/compile/error-denotation-3.a68 b/gcc/testsuite/algol68/compile/error-denotation-3.a68
new file mode 100644 (file)
index 0000000..ed27dc1
--- /dev/null
@@ -0,0 +1,6 @@
+{ dg-options {-fstropping=supper} }
+{ dg-require-effective-target longlong64 }
+begin long long int i0 := long long 9223372036854775808; { dg-error "denotation is too large for long long int" }
+      long long int i1 := long long 9223372036854775807;
+      skip
+end
index 8de4e97b046ad728655309e9050c679807b12b75..48865f8a1fe4184e0d4228275cd0b10136534f7a 100644 (file)
@@ -12,11 +12,11 @@ BEGIN BEGIN INT i := 10;
             i PLUSAB SHORT 100;
             ASSERT (i = SHORT 1200)
       END;
-      BEGIN SHORT SHORT INT i := SHORT SHORT 10000;
-            i +:= SHORT SHORT 1000;
-            ASSERT (i = SHORT SHORT 11000);
-            i PLUSAB SHORT SHORT 1000;
-            ASSERT (i = SHORT SHORT 12000)
+      BEGIN SHORT SHORT INT i := SHORT SHORT 100;
+            i +:= SHORT SHORT 10;
+            ASSERT (i = SHORT SHORT 110);
+            i PLUSAB SHORT SHORT 10;
+            ASSERT (i = SHORT SHORT 120)
       END;
 
       BEGIN LONG INT i := LONG 1000;