The patch reports an error when a non-HOST_WIDE_INT options is used
and its value is bigger than INT_MAX.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

        PR rtl-optimization/98271
        PR rtl-optimization/98276
        PR tree-optimization/98279
        * opts-common.c (set_option): Do not allow overflow for integer
        arguments.

gcc/testsuite/ChangeLog:

        PR rtl-optimization/98271
        PR rtl-optimization/98276
        PR tree-optimization/98279
        * gcc.dg/pr98271.c: New test.
---
 gcc/opts-common.c              | 12 +++++++++---
 gcc/testsuite/gcc.dg/pr98271.c | 13 +++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr98271.c

diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 8ec8c1ec1a8..30be7d5bf47 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -1466,9 +1466,15 @@ set_option (struct gcc_options *opts, struct gcc_options 
*opts_set,
          }
        else
          {
-           *(int *) flag_var = value;
-           if (set_flag_var)
-             *(int *) set_flag_var = 1;
+           if (value > INT_MAX)
+             error_at (loc, "argument to %qs is bigger than %d",
+                       option->opt_text, INT_MAX);
+           else
+             {
+               *(int *) flag_var = value;
+               if (set_flag_var)
+                 *(int *) set_flag_var = 1;
+             }
          }
break;
diff --git a/gcc/testsuite/gcc.dg/pr98271.c b/gcc/testsuite/gcc.dg/pr98271.c
new file mode 100644
index 00000000000..b453434612e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr98271.c
@@ -0,0 +1,13 @@
+/* PR rtl-optimization/98271 */
+/* PR rtl-optimization/98276 */
+/* PR tree-optimization/98279 */
+/* { dg-do compile } */
+/* { dg-options "-O --param=align-loop-iterations=1197120096074465280 
--param=gcse-cost-distance-ratio=2147483648 
--param=hot-bb-frequency-fraction=2147483648" } */
+/* { dg-error "argument to .--param=align-loop-iterations=. is bigger than 2147483647" 
"" { target *-*-* } 0 } */
+/* { dg-error "argument to .--param=gcse-cost-distance-ratio=. is bigger than 
2147483647" "" { target *-*-* } 0 } */
+/* { dg-error "argument to .--param=hot-bb-frequency-fraction=. is bigger than 
2147483647" "" { target *-*-* } 0 } */
+
+void
+foo (void)
+{
+}
--
2.29.2

Reply via email to