[committed] analyzer: remove redundant return value from various impl_call_*

David Malcolm dmalcolm@redhat.com
Wed Jul 28 18:50:02 GMT 2021


Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as b5081130166a4f2e363f116e0e6b43d83422c947.

gcc/analyzer/ChangeLog:
	* region-model-impl-calls.cc (region_model::impl_call_alloca):
	Drop redundant return value.
	(region_model::impl_call_builtin_expect): Likewise.
	(region_model::impl_call_calloc): Likewise.
	(region_model::impl_call_malloc): Likewise.
	(region_model::impl_call_memset): Likewise.
	(region_model::impl_call_operator_new): Likewise.
	(region_model::impl_call_operator_delete): Likewise.
	(region_model::impl_call_strlen): Likewise.
	* region-model.cc (region_model::on_call_pre): Fix return value of
	known functions that don't have unknown side-effects.
	* region-model.h (region_model::impl_call_alloca): Drop redundant
	return value.
	(region_model::impl_call_builtin_expect): Likewise.
	(region_model::impl_call_calloc): Likewise.
	(region_model::impl_call_malloc): Likewise.
	(region_model::impl_call_memset): Likewise.
	(region_model::impl_call_strlen): Likewise.
	(region_model::impl_call_operator_new): Likewise.
	(region_model::impl_call_operator_delete): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/region-model-impl-calls.cc | 31 ++++++----------
 gcc/analyzer/region-model.cc            | 49 +++++++++++++++++--------
 gcc/analyzer/region-model.h             | 16 ++++----
 3 files changed, 53 insertions(+), 43 deletions(-)

diff --git a/gcc/analyzer/region-model-impl-calls.cc b/gcc/analyzer/region-model-impl-calls.cc
index eff8caa8c0a..e5a6cb2e154 100644
--- a/gcc/analyzer/region-model-impl-calls.cc
+++ b/gcc/analyzer/region-model-impl-calls.cc
@@ -207,7 +207,7 @@ call_details::get_or_create_conjured_svalue (const region *reg) const
 
 /* Handle the on_call_pre part of "alloca".  */
 
-bool
+void
 region_model::impl_call_alloca (const call_details &cd)
 {
   const svalue *size_sval = cd.get_arg_svalue (0);
@@ -215,7 +215,6 @@ region_model::impl_call_alloca (const call_details &cd)
   const svalue *ptr_sval
     = m_mgr->get_ptr_svalue (cd.get_lhs_type (), new_reg);
   cd.maybe_set_lhs (ptr_sval);
-  return true;
 }
 
 /* Handle a call to "__analyzer_describe".
@@ -274,18 +273,17 @@ region_model::impl_call_analyzer_eval (const gcall *call,
 
 /* Handle the on_call_pre part of "__builtin_expect" etc.  */
 
-bool
+void
 region_model::impl_call_builtin_expect (const call_details &cd)
 {
   /* __builtin_expect's return value is its initial argument.  */
   const svalue *sval = cd.get_arg_svalue (0);
   cd.maybe_set_lhs (sval);
-  return false;
 }
 
 /* Handle the on_call_pre part of "calloc".  */
 
-bool
+void
 region_model::impl_call_calloc (const call_details &cd)
 {
   const svalue *nmemb_sval = cd.get_arg_svalue (0);
@@ -302,7 +300,6 @@ region_model::impl_call_calloc (const call_details &cd)
 	= m_mgr->get_ptr_svalue (cd.get_lhs_type (), new_reg);
       cd.maybe_set_lhs (ptr_sval);
     }
-  return true;
 }
 
 /* Handle the on_call_pre part of "error" and "error_at_line" from
@@ -397,7 +394,7 @@ region_model::impl_call_free (const call_details &cd)
 
 /* Handle the on_call_pre part of "malloc".  */
 
-bool
+void
 region_model::impl_call_malloc (const call_details &cd)
 {
   const svalue *size_sval = cd.get_arg_svalue (0);
@@ -408,7 +405,6 @@ region_model::impl_call_malloc (const call_details &cd)
 	= m_mgr->get_ptr_svalue (cd.get_lhs_type (), new_reg);
       cd.maybe_set_lhs (ptr_sval);
     }
-  return true;
 }
 
 /* Handle the on_call_pre part of "memcpy" and "__builtin_memcpy".  */
@@ -439,7 +435,7 @@ region_model::impl_call_memcpy (const call_details &cd)
 
 /* Handle the on_call_pre part of "memset" and "__builtin_memset".  */
 
-bool
+void
 region_model::impl_call_memset (const call_details &cd)
 {
   const svalue *dest_sval = cd.get_arg_svalue (0);
@@ -457,12 +453,11 @@ region_model::impl_call_memset (const call_details &cd)
 							  num_bytes_sval);
   check_region_for_write (sized_dest_reg, cd.get_ctxt ());
   fill_region (sized_dest_reg, fill_value_u8);
-  return true;
 }
 
 /* Handle the on_call_pre part of "operator new".  */
 
-bool
+void
 region_model::impl_call_operator_new (const call_details &cd)
 {
   const svalue *size_sval = cd.get_arg_svalue (0);
@@ -473,14 +468,13 @@ region_model::impl_call_operator_new (const call_details &cd)
 	= m_mgr->get_ptr_svalue (cd.get_lhs_type (), new_reg);
       cd.maybe_set_lhs (ptr_sval);
     }
-  return false;
 }
 
 /* Handle the on_call_pre part of "operator delete", which comes in
    both sized and unsized variants (2 arguments and 1 argument
    respectively).  */
 
-bool
+void
 region_model::impl_call_operator_delete (const call_details &cd)
 {
   const svalue *ptr_sval = cd.get_arg_svalue (0);
@@ -490,7 +484,6 @@ region_model::impl_call_operator_delete (const call_details &cd)
 	 poisoning pointers.  */
       unbind_region_and_descendents (freed_reg, POISON_KIND_FREED);
     }
-  return false;
 }
 
 /* Handle the on_call_pre part of "realloc".  */
@@ -521,10 +514,9 @@ region_model::impl_call_strcpy (const call_details &cd)
   mark_region_as_unknown (dest_reg, cd.get_uncertainty ());
 }
 
-/* Handle the on_call_pre part of "strlen".
-   Return true if the LHS is updated.  */
+/* Handle the on_call_pre part of "strlen".  */
 
-bool
+void
 region_model::impl_call_strlen (const call_details &cd)
 {
   region_model_context *ctxt = cd.get_ctxt ();
@@ -543,11 +535,10 @@ region_model::impl_call_strlen (const call_details &cd)
 	  const svalue *result_sval
 	    = m_mgr->get_or_create_constant_svalue (t_cst);
 	  cd.maybe_set_lhs (result_sval);
-	  return true;
+	  return;
 	}
     }
-  /* Otherwise an unknown value.  */
-  return true;
+  /* Otherwise a conjured value.  */
 }
 
 /* Handle calls to functions referenced by
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 9d84b8c28a1..92fa917d14d 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -1080,7 +1080,8 @@ region_model::on_call_pre (const gcall *call, region_model_context *ctxt,
        default:
 	 break;
        case IFN_BUILTIN_EXPECT:
-	 return impl_call_builtin_expect (cd);
+	 impl_call_builtin_expect (cd);
+	 return false;
        }
     }
 
@@ -1101,17 +1102,21 @@ region_model::on_call_pre (const gcall *call, region_model_context *ctxt,
 	    break;
 	  case BUILT_IN_ALLOCA:
 	  case BUILT_IN_ALLOCA_WITH_ALIGN:
-	    return impl_call_alloca (cd);
+	    impl_call_alloca (cd);
+	    return false;
 	  case BUILT_IN_CALLOC:
-	    return impl_call_calloc (cd);
+	    impl_call_calloc (cd);
+	    return false;
 	  case BUILT_IN_EXPECT:
 	  case BUILT_IN_EXPECT_WITH_PROBABILITY:
-	    return impl_call_builtin_expect (cd);
+	    impl_call_builtin_expect (cd);
+	    return false;
 	  case BUILT_IN_FREE:
 	    /* Handle in "on_call_post".  */
 	    break;
 	  case BUILT_IN_MALLOC:
-	    return impl_call_malloc (cd);
+	    impl_call_malloc (cd);
+	    return false;
 	  case BUILT_IN_MEMCPY:
 	  case BUILT_IN_MEMCPY_CHK:
 	    impl_call_memcpy (cd);
@@ -1129,9 +1134,8 @@ region_model::on_call_pre (const gcall *call, region_model_context *ctxt,
 	    impl_call_strcpy (cd);
 	    return false;
 	  case BUILT_IN_STRLEN:
-	    if (impl_call_strlen (cd))
-	      return false;
-	    break;
+	    impl_call_strlen (cd);
+	    return false;
 
 	  /* Stdio builtins.  */
 	  case BUILT_IN_FPRINTF:
@@ -1158,11 +1162,20 @@ region_model::on_call_pre (const gcall *call, region_model_context *ctxt,
 	    break;
 	  }
       else if (is_named_call_p (callee_fndecl, "malloc", call, 1))
-	return impl_call_malloc (cd);
+	{
+	  impl_call_malloc (cd);
+	  return false;
+	}
       else if (is_named_call_p (callee_fndecl, "calloc", call, 2))
-	return impl_call_calloc (cd);
+	{
+	  impl_call_calloc (cd);
+	  return false;
+	}
       else if (is_named_call_p (callee_fndecl, "alloca", call, 1))
-	return impl_call_alloca (cd);
+	{
+	  impl_call_alloca (cd);
+	  return false;
+	}
       else if (is_named_call_p (callee_fndecl, "realloc", call, 2))
 	{
 	  impl_call_realloc (cd);
@@ -1207,13 +1220,19 @@ region_model::on_call_pre (const gcall *call, region_model_context *ctxt,
       else if (is_named_call_p (callee_fndecl, "strlen", call, 1)
 	       && POINTER_TYPE_P (cd.get_arg_type (0)))
 	{
-	  if (impl_call_strlen (cd))
-	    return false;
+	  impl_call_strlen (cd);
+	  return false;
 	}
       else if (is_named_call_p (callee_fndecl, "operator new", call, 1))
-	return impl_call_operator_new (cd);
+	{
+	  impl_call_operator_new (cd);
+	  return false;
+	}
       else if (is_named_call_p (callee_fndecl, "operator new []", call, 1))
-	return impl_call_operator_new (cd);
+	{
+	  impl_call_operator_new (cd);
+	  return false;
+	}
       else if (is_named_call_p (callee_fndecl, "operator delete", call, 1)
 	       || is_named_call_p (callee_fndecl, "operator delete", call, 2)
 	       || is_named_call_p (callee_fndecl, "operator delete []", call, 1))
diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h
index 1c7a3865346..d07ce9c6343 100644
--- a/gcc/analyzer/region-model.h
+++ b/gcc/analyzer/region-model.h
@@ -546,28 +546,28 @@ class region_model
   void purge_state_involving (const svalue *sval, region_model_context *ctxt);
 
   /* Specific handling for on_call_pre.  */
-  bool impl_call_alloca (const call_details &cd);
+  void impl_call_alloca (const call_details &cd);
   void impl_call_analyzer_describe (const gcall *call,
 				    region_model_context *ctxt);
   void impl_call_analyzer_dump_capacity (const gcall *call,
 					 region_model_context *ctxt);
   void impl_call_analyzer_eval (const gcall *call,
 				region_model_context *ctxt);
-  bool impl_call_builtin_expect (const call_details &cd);
-  bool impl_call_calloc (const call_details &cd);
+  void impl_call_builtin_expect (const call_details &cd);
+  void impl_call_calloc (const call_details &cd);
   bool impl_call_error (const call_details &cd, unsigned min_args,
 			bool *out_terminate_path);
   void impl_call_fgets (const call_details &cd);
   void impl_call_fread (const call_details &cd);
   void impl_call_free (const call_details &cd);
-  bool impl_call_malloc (const call_details &cd);
+  void impl_call_malloc (const call_details &cd);
   void impl_call_memcpy (const call_details &cd);
-  bool impl_call_memset (const call_details &cd);
+  void impl_call_memset (const call_details &cd);
   void impl_call_realloc (const call_details &cd);
   void impl_call_strcpy (const call_details &cd);
-  bool impl_call_strlen (const call_details &cd);
-  bool impl_call_operator_new (const call_details &cd);
-  bool impl_call_operator_delete (const call_details &cd);
+  void impl_call_strlen (const call_details &cd);
+  void impl_call_operator_new (const call_details &cd);
+  void impl_call_operator_delete (const call_details &cd);
   void impl_deallocation_call (const call_details &cd);
 
   void handle_unrecognized_call (const gcall *call,
-- 
2.26.3



More information about the Gcc-patches mailing list