This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix CFG WRT __builtin_return


> Move this function to gimple.[ch], call it
> gimple_call_builtin_p implemented like
> 
> bool
> gimple_call_builtin_p (gimple stmt, enum built_in_function code)
> {
>   tree fndecl;
>   return (is_gimple_call (stmt)
> 	  && (fndecl = gimple_call_fndecl (stmt)) != NULL
> 	  && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
>           && DECL_FUNCTION_CODE (fndecl) == code);
> }
> 
> note the correctness check for BUILT_IN_NORMAL you miss.
> 
> Ok with that change.
Sure,
this is updated patch I am testing now and intende to commit later.
Thanks,
Honza

	* gimple.c (gimple_call_builtin_p): New function.
	* gimple.h (gimple_call_builtin_p): Declare.
	* tree-cfg.c (make_edges): Produce edge from BUILT_IN_RETURN
	to exit.
	(execute_warn_function_return): BUILT_IN_RETURN is return.
	(split_critical_edges): Return edges are not critical.
	(is_ctrl_altering_stmt): Builtin_in_return is altering.
	(gimple_verify_flow_info): Handle built_in_return.
	(execute_warn_function_return): Handle built_in_return.
	* ipa-pure-const.c (check_call): Ignore builtin_return.

	* gcc.dg/builtin-apply4.c: Compile with -Wmissing-return.
Index: testsuite/gcc.dg/builtin-apply4.c
===================================================================
*** testsuite/gcc.dg/builtin-apply4.c	(revision 160037)
--- testsuite/gcc.dg/builtin-apply4.c	(working copy)
***************
*** 1,5 ****
  /* PR tree-optimization/20076 */
! /* { dg-options "-O2" } */
  /* { dg-options "-O2 -mno-mmx" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
  /* { dg-do run } */
  
--- 1,5 ----
  /* PR tree-optimization/20076 */
! /* { dg-options "-O2 -Wmissing-noreturn" } */
  /* { dg-options "-O2 -mno-mmx" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
  /* { dg-do run } */
  
Index: builtins.def
===================================================================
*** builtins.def	(revision 160037)
--- builtins.def	(working copy)
*************** DEF_GCC_BUILTIN        (BUILT_IN_POPCOUN
*** 691,697 ****
  DEF_GCC_BUILTIN        (BUILT_IN_POPCOUNTLL, "popcountll", BT_FN_INT_ULONGLONG, ATTR_CONST_NOTHROW_LIST)
  DEF_GCC_BUILTIN        (BUILT_IN_PREFETCH, "prefetch", BT_FN_VOID_CONST_PTR_VAR, ATTR_NOVOPS_LIST)
  DEF_LIB_BUILTIN        (BUILT_IN_REALLOC, "realloc", BT_FN_PTR_PTR_SIZE, ATTR_NOTHROW_LIST)
! DEF_GCC_BUILTIN        (BUILT_IN_RETURN, "return", BT_FN_VOID_PTR, ATTR_NORETURN_NOTHROW_LIST)
  DEF_GCC_BUILTIN        (BUILT_IN_RETURN_ADDRESS, "return_address", BT_FN_PTR_UINT, ATTR_NULL)
  DEF_GCC_BUILTIN        (BUILT_IN_SAVEREGS, "saveregs", BT_FN_PTR_VAR, ATTR_NULL)
  DEF_GCC_BUILTIN        (BUILT_IN_SETJMP, "setjmp", BT_FN_INT_PTR, ATTR_NULL)
--- 691,697 ----
  DEF_GCC_BUILTIN        (BUILT_IN_POPCOUNTLL, "popcountll", BT_FN_INT_ULONGLONG, ATTR_CONST_NOTHROW_LIST)
  DEF_GCC_BUILTIN        (BUILT_IN_PREFETCH, "prefetch", BT_FN_VOID_CONST_PTR_VAR, ATTR_NOVOPS_LIST)
  DEF_LIB_BUILTIN        (BUILT_IN_REALLOC, "realloc", BT_FN_PTR_PTR_SIZE, ATTR_NOTHROW_LIST)
! DEF_GCC_BUILTIN        (BUILT_IN_RETURN, "return", BT_FN_VOID_PTR, ATTR_NOTHROW_LIST)
  DEF_GCC_BUILTIN        (BUILT_IN_RETURN_ADDRESS, "return_address", BT_FN_PTR_UINT, ATTR_NULL)
  DEF_GCC_BUILTIN        (BUILT_IN_SAVEREGS, "saveregs", BT_FN_PTR_VAR, ATTR_NULL)
  DEF_GCC_BUILTIN        (BUILT_IN_SETJMP, "setjmp", BT_FN_INT_PTR, ATTR_NULL)
Index: ipa-pure-const.c
===================================================================
*** ipa-pure-const.c	(revision 160051)
--- ipa-pure-const.c	(working copy)
*************** check_call (funct_state local, gimple ca
*** 369,374 ****
--- 369,377 ----
       graph.  */
    if (callee_t)
      {
+       /* built_in_return is really just an return statemnt.  */
+       if (gimple_call_builtin_p (call, BUILT_IN_RETURN))
+ 	return;
        /* When bad things happen to bad functions, they cannot be const
  	 or pure.  */
        if (setjmp_call_p (callee_t))
Index: gimple.c
===================================================================
*** gimple.c	(revision 160037)
--- gimple.c	(working copy)
*************** gimple_decl_printable_name (tree decl, i
*** 4732,4735 ****
--- 4732,4747 ----
    return IDENTIFIER_POINTER (DECL_NAME (decl));
  }
  
+ /* Return true when STMT is builtins call to CODE.  */
+ 
+ bool
+ gimple_call_builtin_p (gimple stmt, enum built_in_function code)
+ {
+   tree fndecl;
+   return (is_gimple_call (stmt)
+ 	  && (fndecl = gimple_call_fndecl (stmt)) != NULL
+ 	  && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+ 	  && DECL_FUNCTION_CODE (fndecl) == code);
+ }
+ 
  #include "gt-gimple.h"
Index: gimple.h
===================================================================
*** gimple.h	(revision 160037)
--- gimple.h	(working copy)
*************** extern bool walk_stmt_load_store_ops (gi
*** 961,966 ****
--- 961,967 ----
  				      bool (*)(gimple, tree, void *),
  				      bool (*)(gimple, tree, void *));
  extern bool gimple_ior_addresses_taken (bitmap, gimple);
+ extern bool gimple_call_builtin_p (gimple, enum built_in_function);
  
  /* In gimplify.c  */
  extern tree create_tmp_var_raw (tree, const char *);
Index: tree-cfg.c
===================================================================
*** tree-cfg.c	(revision 160037)
--- tree-cfg.c	(working copy)
*************** make_edges (void)
*** 568,575 ****
  		 create abnormal edges to them.  */
  	      make_eh_edges (last);
  
  	      /* Some calls are known not to return.  */
! 	      fallthru = !(gimple_call_flags (last) & ECF_NORETURN);
  	      break;
  
  	    case GIMPLE_ASSIGN:
--- 568,579 ----
  		 create abnormal edges to them.  */
  	      make_eh_edges (last);
  
+ 	      /* BUILTIN_RETURN is really a return statement.  */
+ 	      if (gimple_call_builtin_p (last, BUILT_IN_RETURN))
+ 		make_edge (bb, EXIT_BLOCK_PTR, 0), fallthru = false;
  	      /* Some calls are known not to return.  */
! 	      else
! 	        fallthru = !(gimple_call_flags (last) & ECF_NORETURN);
  	      break;
  
  	    case GIMPLE_ASSIGN:
*************** is_ctrl_altering_stmt (gimple t)
*** 2248,2253 ****
--- 2252,2261 ----
  	/* A call also alters control flow if it does not return.  */
  	if (flags & ECF_NORETURN)
  	  return true;
+ 
+ 	/* BUILT_IN_RETURN call is same as return statement.  */
+ 	if (gimple_call_builtin_p (t, BUILT_IN_RETURN))
+ 	  return true;
        }
        break;
  
*************** gimple_verify_flow_info (void)
*** 4422,4427 ****
--- 4430,4439 ----
  	    }
  	  break;
  
+ 	case GIMPLE_CALL:
+ 	  if (!gimple_call_builtin_p (stmt, BUILT_IN_RETURN))
+ 	    break;
+ 	  /* ... fallthru ... */
  	case GIMPLE_RETURN:
  	  if (!single_succ_p (bb)
  	      || (single_succ_edge (bb)->flags
*************** split_critical_edges (void)
*** 7036,7042 ****
  	      gsi = gsi_last_bb (e->src);
  	      if (!gsi_end_p (gsi)
  		  && stmt_ends_bb_p (gsi_stmt (gsi))
! 		  && gimple_code (gsi_stmt (gsi)) != GIMPLE_RETURN)
  		split_edge (e);
  	    }
  	}
--- 7048,7056 ----
  	      gsi = gsi_last_bb (e->src);
  	      if (!gsi_end_p (gsi)
  		  && stmt_ends_bb_p (gsi_stmt (gsi))
! 		  && (gimple_code (gsi_stmt (gsi)) != GIMPLE_RETURN
! 		      && !gimple_call_builtin_p (gsi_stmt (gsi),
! 						 BUILT_IN_RETURN)))
  		split_edge (e);
  	    }
  	}
*************** execute_warn_function_return (void)
*** 7134,7140 ****
        FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
  	{
  	  last = last_stmt (e->src);
! 	  if (gimple_code (last) == GIMPLE_RETURN
  	      && (location = gimple_location (last)) != UNKNOWN_LOCATION)
  	    break;
  	}
--- 7148,7155 ----
        FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
  	{
  	  last = last_stmt (e->src);
! 	  if ((gimple_code (last) == GIMPLE_RETURN
! 	       || gimple_call_builtin_p (last, BUILT_IN_RETURN))
  	      && (location = gimple_location (last)) != UNKNOWN_LOCATION)
  	    break;
  	}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]