Patchwork [C++] Fix -Wunused-but-set-* with delete [] (PR c++/58325)

login
register
mail settings
Submitter Jakub Jelinek
Date Sept. 9, 2013, 3:25 p.m.
Message ID <20130909152527.GP1817@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/273599/
State New
Headers show

Comments

Jakub Jelinek - Sept. 9, 2013, 3:25 p.m.
Hi!

If base of delete[] has TREE_SIDE_EFFECTS, build_vec_delete
calls get_target_expr on it and we never call mark_exp_read on it in the
end.  Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk/4.8?

2013-09-09  Jakub Jelinek  <jakub@redhat.com>

	PR c++/58325
	* init.c (build_vec_delete): Call mark_rvalue_use on base.

	* g++.dg/warn/Wunused-var-21.C: New test.


	Jakub
Jason Merrill - Sept. 9, 2013, 3:53 p.m.
OK.

Jason

Patch

--- gcc/cp/init.c.jj	2013-09-09 11:32:39.000000000 +0200
+++ gcc/cp/init.c	2013-09-09 12:33:23.244771455 +0200
@@ -4109,6 +4109,7 @@  build_vec_delete (tree base, tree maxind
       tree cookie_addr;
       tree size_ptr_type = build_pointer_type (sizetype);
 
+      base = mark_rvalue_use (base);
       if (TREE_SIDE_EFFECTS (base))
 	{
 	  base_init = get_target_expr (base);
--- gcc/testsuite/g++.dg/warn/Wunused-var-21.C.jj	2013-09-09 12:34:52.204318484 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-21.C	2013-09-09 12:34:36.000000000 +0200
@@ -0,0 +1,31 @@ 
+// PR c++/58325
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+void
+f1 ()
+{
+  int *volatile a = new int[1];
+  delete[] a;
+}
+
+void
+f2 ()
+{
+  int *b = new int[1];
+  delete[] b;
+}
+
+void
+f3 ()
+{
+  int *volatile c = new int;
+  delete c;
+}
+
+void
+f4 ()
+{
+  int *d = new int;
+  delete d;
+}