Tested x86_64-pc-linux-gnu. Any advice about the Wstringop-overflow-4 issue?
Should I just xfail it for now?
-- 8< --
And also add the clobber for non-placement new.
This addition confuses a few tests:
The analyzer currently has trouble with loops, and the clobber code loops
over an array. David said offline that it's OK to xfail the "too complex"
warnings; the other changes seem neutral.
The Wstringop-overflow testcase change seems like an instance of a
preexisting bug; C++98-only xfails seem to come and go in this testcase.
Initially I thought this was because in C++11 and above we throw on
allocation size multiplication overflow, but in C++98 we saturate--but
-fno-exceptions makes us saturate in C++11, and we still only get the
warning in C++98. The tree dumps look the same until cddce1, at which point
we get this difference:
(C++11) Assume loop 3 to be finite: it has an exit and -ffinite-loops is on
or loop was previously finite.
(C++98) Estimating # of iterations of loop 3
cannot prove finiteness of loop 3
And the dumps diverge significantly from that point. It seems rather
unfortunate that the optimizers aren't able to prove finiteness of loops
produced by build_vec_init; how can we improve that?
gcc/cp/ChangeLog:
* init.cc (build_new_1): Also clobber for non-placement new.
gcc/testsuite/ChangeLog:
* g++.dg/analyzer/new-2.C: Adjust diags, add xfail.
* g++.dg/analyzer/noexcept-new.C: Adjust diags, add xfail.
* g++.dg/warn/Wstringop-overflow-4.C: Add C++98 xfail.
---
gcc/cp/init.cc | 2 +-
gcc/testsuite/g++.dg/analyzer/new-2.C | 5 +++--
gcc/testsuite/g++.dg/analyzer/noexcept-new.C | 15 ++++++++-------
gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C | 4 ++--
4 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 3fe476d7eec..65e4b3d13a6 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -3563,7 +3563,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type,
tree nelts,
in start_preparsed_function. This is most important for activating an
array in a union (c++/121068), but should also help the optimizers. */
const bool do_clobber
- = (std_placement && flag_lifetime_dse > 1
+ = (flag_lifetime_dse > 1
&& !processing_template_decl
&& !is_empty_type (elt_type)
&& (!*init || CLASS_TYPE_P (elt_type)));
diff --git a/gcc/testsuite/g++.dg/analyzer/new-2.C
b/gcc/testsuite/g++.dg/analyzer/new-2.C
index 391d159a53a..7dafdd0c87a 100644
--- a/gcc/testsuite/g++.dg/analyzer/new-2.C
+++ b/gcc/testsuite/g++.dg/analyzer/new-2.C
@@ -56,12 +56,13 @@ void test_nonthrowing ()
int* x = new(std::nothrow) int;
int* y = new(std::nothrow) int();
int* arr = new(std::nothrow) int[10];
+ // { dg-bogus "Wanalyzer-too-complex" "array clobber" { xfail *-*-* } .-1 }
*/
int z = *y + 2; /* { dg-warning "dereference of NULL 'y'" } */
/* { dg-bogus "use of uninitialized value '\\*y'" "" { target *-*-* } .-1 }
*/
- z = *x + 4; /* { dg-warning "dereference of possibly-NULL 'x'" } */
+ z = *x + 4; /* { dg-warning "dereference of NULL 'x'" } */
/* { dg-warning "use of uninitialized value '\\*x'" "" { target *-*-* } .-1
} */
- z = arr[0] + 4; /* { dg-warning "dereference of possibly-NULL 'arr'" } */
+ z = arr[0] + 4; /* { dg-warning "dereference of NULL 'arr'" } */
/* { dg-warning "use of uninitialized value '\\*arr'" "" { target *-*-* }
.-1 } */
delete y;
diff --git a/gcc/testsuite/g++.dg/analyzer/noexcept-new.C
b/gcc/testsuite/g++.dg/analyzer/noexcept-new.C
index f4bb4956d26..7883267d6b3 100644
--- a/gcc/testsuite/g++.dg/analyzer/noexcept-new.C
+++ b/gcc/testsuite/g++.dg/analyzer/noexcept-new.C
@@ -11,15 +11,15 @@ struct A
void test_throwing ()
{
- int* x = new int;
+ int* x = new int; /* { dg-warning "dereference of possibly-NULL" } */
int* y = new int(); /* { dg-warning "dereference of possibly-NULL" } */
- int* arr = new int[10];
+ int* arr = new int[10]; /* { dg-warning "dereference of possibly-NULL" } */
A *a = new A(); /* { dg-warning "dereference of possibly-NULL" } */
int z = *y + 2;
- z = *x + 4; /* { dg-warning "dereference of possibly-NULL 'x'" } */
+ z = *x + 4;
/* { dg-warning "use of uninitialized value '\\*x'" "" { target *-*-* } .-1
} */
- z = arr[0] + 4; /* { dg-warning "dereference of possibly-NULL 'arr'" } */
+ z = arr[0] + 4;
/* { dg-warning "use of uninitialized value '\\*arr'" "" { target *-*-* }
.-1 } */
a->y = a->x + 3;
@@ -34,13 +34,14 @@ void test_nonthrowing ()
int* x = new(std::nothrow) int;
int* y = new(std::nothrow) int();
int* arr = new(std::nothrow) int[10];
+ // { dg-bogus "Wanalyzer-too-complex" "array clobber" { xfail *-*-* } .-1 }
*/
int z = *y + 2; /* { dg-warning "dereference of NULL 'y'" } */
/* { dg-bogus "use of uninitialized value '\\*y'" "" { target *-*-* } .-1 }
*/
- z = *x + 4; /* { dg-warning "dereference of possibly-NULL 'x'" } */
+ z = *x + 4; /* { dg-warning "dereference of NULL 'x'" } */
/* { dg-warning "use of uninitialized value '\\*x'" "" { target *-*-* } .-1
} */
- z = arr[0] + 4; /* { dg-warning "dereference of possibly-NULL 'arr'" } */
- /* { dg-warning "use of uninitialized value '\\*arr'" "" { target *-*-* }
.-1 } */
+ z = arr[0] + 4; /* { dg-warning "dereference of NULL 'arr'" } */
+ /* { dg-warning "use of uninitialized value '\\*arr'" "" { xfail *-*-* } .-1
} */
delete y;
delete x;
diff --git a/gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C
b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C
index 2024f8d93ca..385afd652cb 100644
--- a/gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C
+++ b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-4.C
@@ -79,7 +79,7 @@ void test_strcpy_new_char_array (size_t n)
T (S (0), new char[r_0_1][1]);
T (S (1), new char[r_0_1][1]); // { dg-warning "\\\[-Wstringop-overflow" }
- T (S (1), new char[r_0_1][2]);
+ T (S (1), new char[r_0_1][2]); // { dg-bogus "size 0" "" { xfail
c++98_only } }
T (S (2), new char[r_0_1][2]); // { dg-warning "\\\[-Wstringop-overflow" }
size_t r_1_2 = UR (1, 2);
@@ -113,7 +113,7 @@ void test_strcpy_new_int16_t (size_t n, const size_t vals[])
size_t r_2_3 = XUR (2, 3);
T (S (0), new int16_t[r_0_1]);
- T (S (1), new int16_t[r_0_1]);
+ T (S (1), new int16_t[r_0_1]); // { dg-bogus "size 0" "" { xfail c++98_only
} }
T (S (2), new int16_t[r_0_1]); // { dg-warning
"\\\[-Wstringop-overflow" }
T (S (0), new int16_t[r_1_2]);
base-commit: a0536f80ffa6cde5900644dcd129d2086c237a8a
--
2.51.0