public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR c++/31246 Wunreachable-code warnings for compiler-generated code
@ 2008-10-23  7:59 Manuel López-Ibáñez
  2009-06-20 22:28 ` Gabriel Dos Reis
  0 siblings, 1 reply; 2+ messages in thread
From: Manuel López-Ibáñez @ 2008-10-23  7:59 UTC (permalink / raw)
  To: Gcc Patch List; +Cc: Paolo Carlini, Gabriel Dos Reis

[-- Attachment #1: Type: text/plain, Size: 782 bytes --]

I think I haven't found all cases yet but this patch is enough to fix PR 31246.

Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
--enable-languages=all,obj-c++ --enable-decimal-float.

OK for trunk?


2008-10-23  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR c++/31246
	* gimplify.c (gimplify_expr): Propagate no_warning flag when
	gimplifying.
	* gimple (gimple_build_call_from_tree): Likewise.
	* tree-cfg.c (remove_useless_stmts_warn_notreached): Check
	no_warning flag before warning.
cp/
	* init.c (build_new_1): Set TREE_NO_WARNING for compiler-generated
	code.
	* except.c (build_throw): Likewise.
	* cp-gimplify.c (genericize_eh_spec_block): Likewise.
	
testsuite/	
	* g++.dg/warn/pr31246.C: New.
	* g++.dg/warn/pr31246-2.C: New.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fix-pr31246.diff --]
[-- Type: text/x-diff; name=fix-pr31246.diff, Size: 6269 bytes --]

Index: gcc/testsuite/g++.dg/warn/pr31246.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr31246.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr31246.C	(revision 0)
@@ -0,0 +1,9 @@
+// PR 31246
+// { dg-do compile }
+// { dg-options "-Wunreachable-code -D_GLIBCXX_DEBUG" }
+#include <vector>
+
+int main()
+{
+  std::vector<int>::iterator a;
+}
Index: gcc/testsuite/g++.dg/warn/pr31246-2.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr31246-2.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr31246-2.C	(revision 0)
@@ -0,0 +1,9 @@
+// PR 31246
+// { dg-do compile }
+// { dg-options "-Wunreachable-code" }
+#include <new>
+
+int* get_ptr(void* ptr)
+{
+  return new(ptr) int();
+}
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c	(revision 141266)
+++ gcc/cp/init.c	(working copy)
@@ -2256,12 +2256,18 @@ build_new_1 (tree placement, tree type, 
 	  if (!cleanup)
 	    /* We're done.  */;
 	  else if (stable)
 	    /* This is much simpler if we were able to preevaluate all of
 	       the arguments to the constructor call.  */
-	    init_expr = build2 (TRY_CATCH_EXPR, void_type_node,
-				init_expr, cleanup);
+	    {
+	      /* CLEANUP is compiler-generated, so no diagnostics.  */
+	      TREE_NO_WARNING (cleanup) = true;
+	      init_expr = build2 (TRY_CATCH_EXPR, void_type_node,
+				  init_expr, cleanup);
+	      /* Likewise, this try-catch is compiler-generated.  */
+	      TREE_NO_WARNING (init_expr) = true;
+	    }
 	  else
 	    /* Ack!  First we allocate the memory.  Then we set our sentry
 	       variable to true, and expand a cleanup that deletes the
 	       memory if sentry is true.  Then we run the constructor, and
 	       finally clear the sentry.
@@ -2277,10 +2283,13 @@ build_new_1 (tree placement, tree type, 
 	      begin = get_target_expr (boolean_true_node);
 	      CLEANUP_EH_ONLY (begin) = 1;
 
 	      sentry = TARGET_EXPR_SLOT (begin);
 
+	      /* CLEANUP is compiler-generated, so no diagnostics.  */
+	      TREE_NO_WARNING (cleanup) = true;
+
 	      TARGET_EXPR_CLEANUP (begin)
 		= build3 (COND_EXPR, void_type_node, sentry,
 			  cleanup, void_zero_node);
 
 	      end = build2 (MODIFY_EXPR, TREE_TYPE (sentry),
@@ -2288,12 +2297,13 @@ build_new_1 (tree placement, tree type, 
 
 	      init_expr
 		= build2 (COMPOUND_EXPR, void_type_node, begin,
 			  build2 (COMPOUND_EXPR, void_type_node, init_expr,
 				  end));
+	      /* Likewise, this is compiler-generated.  */
+	      TREE_NO_WARNING (init_expr) = true;
 	    }
-
 	}
     }
   else
     init_expr = NULL_TREE;
 
Index: gcc/cp/except.c
===================================================================
--- gcc/cp/except.c	(revision 141266)
+++ gcc/cp/except.c	(working copy)
@@ -791,12 +791,16 @@ build_throw (tree exp)
 	 for temporaries within the initialization are run before the one
 	 for the exception object, preserving LIFO order.  */
       exp = build1 (CLEANUP_POINT_EXPR, void_type_node, exp);
 
       if (elided)
-	exp = build2 (TRY_CATCH_EXPR, void_type_node, exp,
-		      do_free_exception (ptr));
+	{
+	  exp = build2 (TRY_CATCH_EXPR, void_type_node, exp,
+			do_free_exception (ptr));
+	  /* This try-catch is compiler-generated.  */
+	  TREE_NO_WARNING (exp) = true;
+	}
       else
 	exp = build1 (MUST_NOT_THROW_EXPR, void_type_node, exp);
 
       /* Prepend the allocation.  */
       exp = build2 (COMPOUND_EXPR, TREE_TYPE (exp), allocate_expr, exp);
Index: gcc/cp/cp-gimplify.c
===================================================================
--- gcc/cp/cp-gimplify.c	(revision 141266)
+++ gcc/cp/cp-gimplify.c	(working copy)
@@ -151,10 +151,12 @@ genericize_eh_spec_block (tree *stmt_p)
   tree body = EH_SPEC_STMTS (*stmt_p);
   tree allowed = EH_SPEC_RAISES (*stmt_p);
   tree failure = build_call_n (call_unexpected_node, 1, build_exc_ptr ());
 
   *stmt_p = build_gimple_eh_filter_tree (body, allowed, failure);
+  TREE_NO_WARNING (*stmt_p) = true;
+  TREE_NO_WARNING (TREE_OPERAND (*stmt_p, 1)) = true;
 }
 
 /* Genericize an IF_STMT by turning it into a COND_EXPR.  */
 
 static void
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c	(revision 141266)
+++ gcc/gimplify.c	(working copy)
@@ -6649,10 +6649,11 @@ gimplify_expr (tree *expr_p, gimple_seq 
 	    gimple ehf;
 	    gimple_seq failure = NULL;
 
 	    gimplify_and_add (EH_FILTER_FAILURE (*expr_p), &failure);
 	    ehf = gimple_build_eh_filter (EH_FILTER_TYPES (*expr_p), failure);
+	    gimple_set_no_warning (ehf, TREE_NO_WARNING (*expr_p));
 	    gimple_eh_filter_set_must_not_throw
 	      (ehf, EH_FILTER_MUST_NOT_THROW (*expr_p));
 	    gimplify_seq_add_stmt (pre_p, ehf);
 	    ret = GS_ALL_DONE;
 	    break;
Index: gcc/gimple.c
===================================================================
--- gcc/gimple.c	(revision 141266)
+++ gcc/gimple.c	(working copy)
@@ -358,10 +358,11 @@ gimple_build_call_from_tree (tree t)
   gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t));
   gimple_call_set_cannot_inline (call, CALL_CANNOT_INLINE_P (t));
   gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t));
   gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t));
   gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
+  gimple_set_no_warning (call, TREE_NO_WARNING (t));
 
   return call;
 }
 
 
Index: gcc/tree-cfg.c
===================================================================
--- gcc/tree-cfg.c	(revision 141266)
+++ gcc/tree-cfg.c	(working copy)
@@ -1498,16 +1498,18 @@ remove_useless_stmts_warn_notreached (gi
 
   for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
     {
       gimple stmt = gsi_stmt (gsi);
 
+      if (gimple_no_warning_p (stmt)) return false;
+
       if (gimple_has_location (stmt))
         {
           location_t loc = gimple_location (stmt);
           if (LOCATION_LINE (loc) > 0)
 	    {
-              warning (OPT_Wunreachable_code, "%Hwill never be executed", &loc);
+              warning_at (loc, OPT_Wunreachable_code, "will never be executed");
               return true;
             }
         }
 
       switch (gimple_code (stmt))

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PR c++/31246 Wunreachable-code warnings for compiler-generated   code
  2008-10-23  7:59 PR c++/31246 Wunreachable-code warnings for compiler-generated code Manuel López-Ibáñez
@ 2009-06-20 22:28 ` Gabriel Dos Reis
  0 siblings, 0 replies; 2+ messages in thread
From: Gabriel Dos Reis @ 2009-06-20 22:28 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: Gcc Patch List, Paolo Carlini

On Wed, Oct 22, 2008 at 7:40 PM, Manuel
López-Ibáñez<lopezibanez@gmail.com> wrote:
> I think I haven't found all cases yet but this patch is enough to fix PR 31246.
>
> Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
> --enable-languages=all,obj-c++ --enable-decimal-float.
>
> OK for trunk?

Yes.

-- Gaby

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-06-20 18:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-23  7:59 PR c++/31246 Wunreachable-code warnings for compiler-generated code Manuel López-Ibáñez
2009-06-20 22:28 ` Gabriel Dos Reis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).