re PR driver/81650 (gcc -m32 mishandles -Walloc-size-larger-than=9223372036854775807)
authorJakub Jelinek <jakub@redhat.com>
Thu, 3 Aug 2017 09:43:11 +0000 (11:43 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 3 Aug 2017 09:43:11 +0000 (11:43 +0200)
PR driver/81650
* calls.c (alloc_max_size): Use HOST_WIDE_INT_UC (10??)
instead of 10??LU, perform unit multiplication in wide_int,
don't change alloc_object_size_limit if the limit is larger
than SSIZE_MAX.

* gcc.dg/pr81650.c: New test.

From-SVN: r250850

gcc/ChangeLog
gcc/calls.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr81650.c [new file with mode: 0644]

index 466afb908b6a9ee824503f7a6ca0e533f02dec66..f7b620c4d0df194c96830e3c9227a9e093ccdd14 100644 (file)
@@ -1,5 +1,11 @@
 2017-08-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR driver/81650
+       * calls.c (alloc_max_size): Use HOST_WIDE_INT_UC (10??)
+       instead of 10??LU, perform unit multiplication in wide_int,
+       don't change alloc_object_size_limit if the limit is larger
+       than SSIZE_MAX.
+
        PR tree-optimization/81655
        PR tree-optimization/81588
        * tree-ssa-reassoc.c (optimize_range_tests_var_bound): Handle also
index 8a23b50fc66661d8b53f0b2e3fe19a3a7ef9d156..6405f482e918c36685ffa87443b9d0e8420f0942 100644 (file)
@@ -1222,32 +1222,38 @@ alloc_max_size (void)
                  else if (!strcasecmp (end, "KiB") || strcmp (end, "KB"))
                    unit = 1024;
                  else if (!strcmp (end, "MB"))
-                   unit = 1000LU * 1000;
+                   unit = HOST_WIDE_INT_UC (1000) * 1000;
                  else if (!strcasecmp (end, "MiB"))
-                   unit = 1024LU * 1024;
+                   unit = HOST_WIDE_INT_UC (1024) * 1024;
                  else if (!strcasecmp (end, "GB"))
-                   unit = 1000LU * 1000 * 1000;
+                   unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000;
                  else if (!strcasecmp (end, "GiB"))
-                   unit = 1024LU * 1024 * 1024;
+                   unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024;
                  else if (!strcasecmp (end, "TB"))
-                   unit = 1000LU * 1000 * 1000 * 1000;
+                   unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000;
                  else if (!strcasecmp (end, "TiB"))
-                   unit = 1024LU * 1024 * 1024 * 1024;
+                   unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024;
                  else if (!strcasecmp (end, "PB"))
-                   unit = 1000LU * 1000 * 1000 * 1000 * 1000;
+                   unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000 * 1000;
                  else if (!strcasecmp (end, "PiB"))
-                   unit = 1024LU * 1024 * 1024 * 1024 * 1024;
+                   unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024 * 1024;
                  else if (!strcasecmp (end, "EB"))
-                   unit = 1000LU * 1000 * 1000 * 1000 * 1000 * 1000;
+                   unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000 * 1000
+                          * 1000;
                  else if (!strcasecmp (end, "EiB"))
-                   unit = 1024LU * 1024 * 1024 * 1024 * 1024 * 1024;
+                   unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024 * 1024
+                          * 1024;
                  else
                    unit = 0;
                }
 
              if (unit)
-               alloc_object_size_limit
-                 = build_int_cst (ssizetype, limit * unit);
+               {
+                 wide_int w = wi::uhwi (limit, HOST_BITS_PER_WIDE_INT + 64);
+                 w *= unit;
+                 if (wi::ltu_p (w, alloc_object_size_limit))
+                   alloc_object_size_limit = wide_int_to_tree (ssizetype, w);
+               }
            }
        }
     }
index 58e1b87c6dc70e0e727b001335b4e55dd4684417..53829f7e779a51fa6f1d8e53001743ccae70953c 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR driver/81650
+       * gcc.dg/pr81650.c: New test.
+
 2017-08-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/71440
diff --git a/gcc/testsuite/gcc.dg/pr81650.c b/gcc/testsuite/gcc.dg/pr81650.c
new file mode 100644 (file)
index 0000000..99e84de
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR driver/81650 */
+/* { dg-do compile } */
+/* { dg-options "-Walloc-size-larger-than=9223372036854775807" } */
+
+void *
+foo (void)
+{
+  return __builtin_malloc (5);
+}