This commit is contained in:
Jakub Jelinek 2012-11-05 17:21:03 +01:00
parent f3ca3c472d
commit 747298b149
4 changed files with 197 additions and 4 deletions

1
.gitignore vendored
View File

@ -45,3 +45,4 @@
/gcc-4.7.2-20121001.tar.bz2
/gcc-4.7.2-20121009.tar.bz2
/gcc-4.7.2-20121015.tar.bz2
/gcc-4.7.2-20121105.tar.bz2

View File

@ -1,9 +1,9 @@
%global DATE 20121015
%global SVNREV 192447
%global DATE 20121105
%global SVNREV 193167
%global gcc_version 4.7.2
# Note, gcc_release must be integer, if you want to add suffixes to
# %{release}, append them after %{gcc_release} on Release: line.
%global gcc_release 6
%global gcc_release 7
%global _unpackaged_files_terminate_build 0
%global multilib_64_archs sparc64 ppc64 s390x x86_64
%ifarch %{ix86} x86_64 ia64 ppc ppc64 alpha
@ -185,6 +185,7 @@ Patch14: gcc47-ppl-0.10.patch
Patch15: gcc47-libitm-fno-exceptions.patch
Patch16: gcc47-rh837630.patch
Patch17: gcc47-arm-hfp-ldso.patch
Patch18: gcc47-c++-new-check-opt.patch
Patch1000: fastjar-0.97-segfault.patch
Patch1001: fastjar-0.97-len1.patch
@ -689,6 +690,7 @@ package or when debugging this package.
%if 0%{?fedora} >= 18 || 0%{?rhel} >= 7
%patch17 -p0 -b .arm-hfp-ldso~
%endif
%patch18 -p0 -b .c++-new-check-opt~
%if 0%{?_enable_debug_packages}
cat > split-debuginfo.sh <<\EOF
@ -2662,6 +2664,20 @@ fi
%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/plugin
%changelog
* Mon Nov 5 2012 Jakub Jelinek <jakub@redhat.com> 4.7.2-7
- update from the 4.7 branch
- PRs c++/54984, c++/54988, debug/54828, libstdc++/55047, libstdc++/55123,
libstdc++/55169, middle-end/54945, rtl-optimization/53701,
rtl-optimization/54870, target/53975, target/54892, target/55019,
target/55175, tree-optimization/53708, tree-optimization/54146,
tree-optimization/54877, tree-optimization/54902,
tree-optimization/54920, tree-optimization/54985
- backported s390{,x} zEC12 enablement (#805114)
- backport of selected debug info quality improvements
- PRs debug/54402, debug/54693, debug/54953, debug/54970, debug/54971
- optimize away overflow checking for new char[n]; and similar cases
where n is multiplied by 1
* Mon Oct 15 2012 Jon Ciesla <limburgher@gmail.com> 4.7.2-6
- Provides: bundled(libiberty)

View File

@ -0,0 +1,176 @@
2012-10-31 Florian Weimer <fweimer@redhat.com>
* init.c (build_new_1): Do not check for arithmetic overflow if
inner array size is 1.
* g++.dg/init/new40.C: New.
--- gcc/cp/init.c (revision 193033)
+++ gcc/cp/init.c (working copy)
@@ -2176,6 +2176,8 @@ build_new_1 (VEC(tree,gc) **placement, t
double_int inner_nelts_count = double_int_one;
tree inner_nelts = NULL_TREE;
tree alloc_call, alloc_expr;
+ /* Size of the inner array elements. */
+ double_int inner_size;
/* The address returned by the call to "operator new". This node is
a VAR_DECL and is therefore reusable. */
tree alloc_node;
@@ -2318,8 +2320,6 @@ build_new_1 (VEC(tree,gc) **placement, t
double_int max_size
= double_int_lshift (double_int_one, TYPE_PRECISION (sizetype) - 1,
HOST_BITS_PER_DOUBLE_INT, false);
- /* Size of the inner array elements. */
- double_int inner_size;
/* Maximum number of outer elements which can be allocated. */
double_int max_outer_nelts;
tree max_outer_nelts_tree;
@@ -2438,7 +2438,15 @@ build_new_1 (VEC(tree,gc) **placement, t
if (array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type))
size = size_binop (PLUS_EXPR, size, cookie_size);
else
- cookie_size = NULL_TREE;
+ {
+ cookie_size = NULL_TREE;
+ /* No size arithmetic necessary, so the size check is
+ not needed. */
+ if (outer_nelts_check != NULL
+ && double_int_one_p (inner_size)
+ && inner_nelts == NULL_TREE)
+ outer_nelts_check = NULL_TREE;
+ }
/* Perform the overflow check. */
if (outer_nelts_check != NULL_TREE)
size = fold_build3 (COND_EXPR, sizetype, outer_nelts_check,
@@ -2474,7 +2482,15 @@ build_new_1 (VEC(tree,gc) **placement, t
/* Use a global operator new. */
/* See if a cookie might be required. */
if (!(array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type)))
- cookie_size = NULL_TREE;
+ {
+ cookie_size = NULL_TREE;
+ /* No size arithmetic necessary, so the size check is
+ not needed. */
+ if (outer_nelts_check != NULL
+ && double_int_one_p (inner_size)
+ && inner_nelts == NULL_TREE)
+ outer_nelts_check = NULL_TREE;
+ }
alloc_call = build_operator_new_call (fnname, placement,
&size, &cookie_size,
--- gcc/testsuite/g++.dg/init/new40.C (revision 0)
+++ gcc/testsuite/g++.dg/init/new40.C (working copy)
@@ -0,0 +1,112 @@
+// Testcase for overflow handling in operator new[].
+// Optimization of unnecessary overflow checks.
+// { dg-do run }
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdexcept>
+
+static size_t magic_allocation_size
+ = 1 + (size_t (1) << (sizeof (size_t) * 8 - 1));
+
+struct exc : std::bad_alloc {
+};
+
+static size_t expected_size;
+
+struct pod_with_new {
+ char ch;
+ void *operator new[] (size_t sz)
+ {
+ if (sz != expected_size)
+ abort ();
+ throw exc ();
+ }
+};
+
+struct with_new {
+ char ch;
+ with_new () { }
+ ~with_new () { }
+ void *operator new[] (size_t sz)
+ {
+ if (sz != size_t (-1))
+ abort ();
+ throw exc ();
+ }
+};
+
+struct non_pod {
+ char ch;
+ non_pod () { }
+ ~non_pod () { }
+};
+
+void *
+operator new (size_t sz) _GLIBCXX_THROW (std::bad_alloc)
+{
+ if (sz != expected_size)
+ abort ();
+ throw exc ();
+}
+
+int
+main ()
+{
+ if (sizeof (pod_with_new) == 1)
+ expected_size = magic_allocation_size;
+ else
+ expected_size = -1;
+
+ try {
+ new pod_with_new[magic_allocation_size];
+ abort ();
+ } catch (exc &) {
+ }
+
+ if (sizeof (with_new) == 1)
+ expected_size = magic_allocation_size;
+ else
+ expected_size = -1;
+
+ try {
+ new with_new[magic_allocation_size];
+ abort ();
+ } catch (exc &) {
+ }
+
+ expected_size = magic_allocation_size;
+ try {
+ new char[magic_allocation_size];
+ abort ();
+ } catch (exc &) {
+ }
+
+ expected_size = -1;
+
+ try {
+ new pod_with_new[magic_allocation_size][2];
+ abort ();
+ } catch (exc &) {
+ }
+
+ try {
+ new with_new[magic_allocation_size][2];
+ abort ();
+ } catch (exc &) {
+ }
+
+ try {
+ new char[magic_allocation_size][2];
+ abort ();
+ } catch (exc &) {
+ }
+
+ try {
+ new non_pod[magic_allocation_size];
+ abort ();
+ } catch (exc &) {
+ }
+
+ return 0;
+}

View File

@ -1,2 +1,2 @@
2659f09c2e43ef8b7d4406321753f1b2 fastjar-0.97.tar.gz
2891991f350ae9f513b8070beab43611 gcc-4.7.2-20121015.tar.bz2
2dfb5b278c94d6859782bbf649f0b8e7 gcc-4.7.2-20121105.tar.bz2