]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: Avoid folding new and delete pairs
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 30 Jun 2024 05:42:43 +0000 (22:42 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 30 Jun 2024 22:43:58 +0000 (15:43 -0700)
GCC 15 may fold new and delete pairs, like

  A *bb = new A[10];
  delete [] bb;
  bb = new (std::nothrow) A [10];
  delete [] bb;

as shown in

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115712

Avoid folding new and delete pairs by adding a function call between new
and delete.

* testsuite/ld-elf/dl5.cc: Include "dl5.h".
(A): Removed.
Call foo between new and delete.
* testsuite/ld-elf/dl5.h: New file.
* testsuite/ld-elf/new.cc: Include "dl5.h".
(foo): New function.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
ld/testsuite/ld-elf/dl5.cc
ld/testsuite/ld-elf/dl5.h [new file with mode: 0644]
ld/testsuite/ld-elf/new.cc

index cc404553f93bf73e4fa209efcb9f378e7e38530a..77dbb62f3d5618682b139848b78315fbdd5019d5 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <new>
+#include "dl5.h"
 
 int pass = 0;
 
@@ -30,22 +31,14 @@ operator delete (void *ptr) throw ()
     free (ptr);
 }
 
-class A 
-{
-public:
-  A() {}
-  ~A() { }
-  int a;
-  int b;
-};
-
-
 int
 main (void)
 {
   A *bb = new A[10];
   delete [] bb;
+  foo (bb);
   bb = new (std::nothrow) A [10];
+  foo (bb);
   delete [] bb;
 
   if (pass == 4)
diff --git a/ld/testsuite/ld-elf/dl5.h b/ld/testsuite/ld-elf/dl5.h
new file mode 100644 (file)
index 0000000..0d4a7c1
--- /dev/null
@@ -0,0 +1,10 @@
+class A 
+{
+public:
+  A() {}
+  ~A() { }
+  int a;
+  int b;
+};
+
+extern void foo (A *);
index 513cf2f3ad62596bd465ef028d6962c6b8ca8c76..b038d770c6d3065ac8a14bb4296a8d46e93f0aae 100644 (file)
@@ -1,4 +1,5 @@
 #include <new>
+#include "dl5.h"
 
 using std::bad_alloc;
 
@@ -45,3 +46,8 @@ operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw()
 {
   return ::operator new(sz, nothrow);
 }
+
+void
+foo (A *)
+{
+}