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]

[PATCH] Ensure entries pid_map are initialized to NULL


gimple_ic_transform calls find_func_by_pid and compares the resulting
cgraph_node* to NULL.? This cgraph_node* comes from pid_map.? When
pid_map is created in init_pid_map, the memory is xmalloc'ed (i.e., is
uninitialized) and only certain entries are explicitly set in the
subsequent loop.  Consequently, if gimple_ic_transform calls
find_func_by_pid for a PID which was not explicitly set, it will get a
garbage value and not NULL.  I have observed this resulting in an ICE
although I cannot reliably reproduce the problem.  This patch
initializes pid_map by using xcalloc instead of xmalloc.  While this
does not fix the root cause of the ICE (my analysis suggests that
gimple_ic_transform should not be querying uninitialized PIDs in the
map), this patch does make the code more robust to bad .gcda files.

Bootstrapped/regtested on x86_64-linux and i686-linux.  Ok for trunk?

2009-08-04  Neil Vachharajani  <nvachhar@google.com>

       * value-prof.c (init_pid_map): Replace xmalloc with xcalloc.

--- gcc/value-prof.c.orig        2009-08-04 17:10:24.000000000 -0700
+++ gcc/value-prof.c  2009-08-04 16:41:00.021142462 -0700
@@ -1060,7 +1060,7 @@
     return;

   pid_map
-    = (struct cgraph_node**) xmalloc (sizeof (struct cgraph_node*) *
cgraph_max_pid);
+    = (struct cgraph_node**) xcalloc (cgraph_max_pid, sizeof (struct
cgraph_node*));

   for (n = cgraph_nodes; n; n = n->next)
     {


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