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]

[PR 79375] Avoid passing NULL by reference


Hi,

current trunk ipa-prop passes NULL by C++ reference to
ipa_alloc_node_params when analyzing functions without any parameters
which is harmless because that function immediately returns but is
undefined and ubsan rightly complains about it.  The following patch
avoids calling the call under such circumstances.

Bootstrapped and tested on x86_64-linux.  I think it is quite obvious
and so will commit it tomorrow, because I have rto run now.

Thanks,

Martin


2017-02-04  Martin Jambor  <mjambor@suse.cz>

	PR ipa/79375
	* ipa-prop.c (ipa_alloc_node_params): Make static, return bool
	whether allocation happened.
	(ipa_initialize_node_params): Do not call ipa_alloc_node_params if
	nothing was allocated.
---
 gcc/ipa-prop.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index d031a70caa4..e4e44ce20c6 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -176,16 +176,21 @@ ipa_dump_param (FILE *file, struct ipa_node_params *info, int i)
     }
 }
 
-/* Initialize the ipa_node_params structure associated with NODE 
-   to hold PARAM_COUNT parameters.  */
+/* If necessary, allocate vector of parameter descriptors in info of NODE.
+   Return true if they were allocated, false if not.  */
 
-void
+static bool
 ipa_alloc_node_params (struct cgraph_node *node, int param_count)
 {
   struct ipa_node_params *info = IPA_NODE_REF (node);
 
   if (!info->descriptors && param_count)
-    vec_safe_grow_cleared (info->descriptors, param_count);
+    {
+      vec_safe_grow_cleared (info->descriptors, param_count);
+      return true;
+    }
+  else
+    return false;
 }
 
 /* Initialize the ipa_node_params structure associated with NODE by counting
@@ -197,11 +202,9 @@ ipa_initialize_node_params (struct cgraph_node *node)
 {
   struct ipa_node_params *info = IPA_NODE_REF (node);
 
-  if (!info->descriptors)
-    {
-      ipa_alloc_node_params (node, count_formal_params (node->decl));
-      ipa_populate_param_decls (node, *info->descriptors);
-    }
+  if (!info->descriptors
+      && ipa_alloc_node_params (node, count_formal_params (node->decl)))
+    ipa_populate_param_decls (node, *info->descriptors);
 }
 
 /* Print the jump functions associated with call graph edge CS to file F.  */
-- 
2.11.0


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