public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Jambor <mjambor@suse.cz>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Jan Hubicka <hubicka@ucw.cz>
Subject: [PATCH 3/7] cgraph_node -> cgraph_get_node with asserts
Date: Wed, 06 Apr 2011 23:26:00 -0000	[thread overview]
Message-ID: <20110406232245.532048483@virgil.suse.cz> (raw)
In-Reply-To: <20110406232220.922143392@virgil.suse.cz>

[-- Attachment #1: get_cgraph_force.diff --]
[-- Type: text/plain, Size: 4914 bytes --]

Hi,

the patch below changes a number of calls to cgraph_node to calls to
cgraph_get_node.  These calls should never return NULL but because the
callers do not immediately dereference the pointer they get, a NULL
value would result in a segmentation fault at some later point,
obscuring the real cause.  Therefore I have added checking asserts to
guard this does not happen.

Bootstrapped and tested separately on x86_64-linux without any
problems, tests on other platforms (together with the other patches)
in progress.

OK for trunk?

Thanks,

Martin


2011-04-06  Martin Jambor  <mjambor@suse.cz>

	* tree-inline.c (tree_function_versioning): Call cgraph_get_node
	instead of cgraph_node and assert it does not return NULL.
	* lto-streamer-in.c (lto_read_body): Likewise.
	* omp-low.c (new_omp_context): Likewise.
	(create_task_copyfn): Likewise.
	* tree-emutls.c (lower_emutls_function_body): Likewise.
	* matrix-reorg.c (transform_allocation_sites): Likewise.



Index: src/gcc/tree-inline.c
===================================================================
--- src.orig/gcc/tree-inline.c
+++ src/gcc/tree-inline.c
@@ -5001,8 +5001,10 @@ tree_function_versioning (tree old_decl,
 	      && TREE_CODE (new_decl) == FUNCTION_DECL);
   DECL_POSSIBLY_INLINED (old_decl) = 1;
 
-  old_version_node = cgraph_node (old_decl);
-  new_version_node = cgraph_node (new_decl);
+  old_version_node = cgraph_get_node (old_decl);
+  gcc_checking_assert (old_version_node);
+  new_version_node = cgraph_get_node (new_decl);
+  gcc_checking_assert (new_version_node);
 
   /* Output the inlining info for this abstract function, since it has been
      inlined.  If we don't do this now, we can lose the information about the
Index: src/gcc/lto-streamer-in.c
===================================================================
--- src.orig/gcc/lto-streamer-in.c
+++ src/gcc/lto-streamer-in.c
@@ -1446,8 +1446,9 @@ lto_read_body (struct lto_file_decl_data
     {
       struct function *fn = DECL_STRUCT_FUNCTION (fn_decl);
       struct lto_in_decl_state *decl_state;
-      struct cgraph_node *node = cgraph_node (fn_decl);
+      struct cgraph_node *node = cgraph_get_node (fn_decl);
 
+      gcc_checking_assert (node);
       push_cfun (fn);
       init_tree_ssa (fn);
 
Index: src/gcc/omp-low.c
===================================================================
--- src.orig/gcc/omp-low.c
+++ src/gcc/omp-low.c
@@ -1209,7 +1209,8 @@ new_omp_context (gimple stmt, omp_contex
     {
       ctx->cb.src_fn = current_function_decl;
       ctx->cb.dst_fn = current_function_decl;
-      ctx->cb.src_node = cgraph_node (current_function_decl);
+      ctx->cb.src_node = cgraph_get_node (current_function_decl);
+      gcc_checking_assert (ctx->cb.src_node);
       ctx->cb.dst_node = ctx->cb.src_node;
       ctx->cb.src_cfun = cfun;
       ctx->cb.copy_decl = omp_copy_decl;
@@ -6263,7 +6264,8 @@ create_task_copyfn (gimple task_stmt, om
       memset (&tcctx, '\0', sizeof (tcctx));
       tcctx.cb.src_fn = ctx->cb.src_fn;
       tcctx.cb.dst_fn = child_fn;
-      tcctx.cb.src_node = cgraph_node (tcctx.cb.src_fn);
+      tcctx.cb.src_node = cgraph_get_node (tcctx.cb.src_fn);
+      gcc_checking_assert (tcctx.cb.src_node);
       tcctx.cb.dst_node = tcctx.cb.src_node;
       tcctx.cb.src_cfun = ctx->cb.src_cfun;
       tcctx.cb.copy_decl = task_copyfn_copy_decl;
Index: src/gcc/tree-emutls.c
===================================================================
--- src.orig/gcc/tree-emutls.c
+++ src/gcc/tree-emutls.c
@@ -619,7 +619,8 @@ lower_emutls_function_body (struct cgrap
 
   d.cfun_node = node;
   d.builtin_decl = built_in_decls[BUILT_IN_EMUTLS_GET_ADDRESS];
-  d.builtin_node = cgraph_node (d.builtin_decl);
+  d.builtin_node = cgraph_get_node (d.builtin_decl);
+  gcc_checking_assert (d.builtin_node);
 
   FOR_EACH_BB (d.bb)
     {
Index: src/gcc/matrix-reorg.c
===================================================================
--- src.orig/gcc/matrix-reorg.c
+++ src/gcc/matrix-reorg.c
@@ -2169,7 +2169,8 @@ transform_allocation_sites (void **slot,
   update_ssa (TODO_update_ssa);
   /* Replace the malloc size argument in the malloc of level 0 to be
      the size of all the dimensions.  */
-  c_node = cgraph_node (mi->allocation_function_decl);
+  c_node = cgraph_get_node (mi->allocation_function_decl);
+  gcc_checking_assert (c_node);
   old_size_0 = gimple_call_arg (call_stmt_0, 0);
   tmp = force_gimple_operand_gsi (&gsi, mi->dimension_size[0], true,
 				  NULL, true, GSI_SAME_STMT);
@@ -2218,7 +2219,8 @@ transform_allocation_sites (void **slot,
       if (!mi->free_stmts[i].stmt)
 	continue;
 
-      c_node = cgraph_node (mi->free_stmts[i].func);
+      c_node = cgraph_get_node (mi->free_stmts[i].func);
+      gcc_checking_assert (c_node);
       gcc_assert (is_gimple_call (mi->free_stmts[i].stmt));
       e = cgraph_edge (c_node, mi->free_stmts[i].stmt);
       gcc_assert (e);

  parent reply	other threads:[~2011-04-06 23:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-06 23:25 [PATCH 0/7] Change of call graph interface - cgraph_node function removal Martin Jambor
2011-04-06 23:26 ` [PATCH 2/7] cgraph_node -> cgraph_get_node conversions accepting NULL results Martin Jambor
2011-04-11 10:18   ` Jan Hubicka
2011-04-11 13:33     ` Martin Jambor
2011-04-06 23:26 ` [PATCH 1/7] Simple cgraph_node -> cgraph_get_node conversions Martin Jambor
2011-04-11 10:13   ` Jan Hubicka
2011-04-13 13:09   ` H.J. Lu
2011-04-06 23:26 ` [PATCH 7/7] Tweaks to objc -> call graph interface Martin Jambor
2011-04-06 23:26 ` Martin Jambor [this message]
2011-04-11 10:20   ` [PATCH 3/7] cgraph_node -> cgraph_get_node with asserts Jan Hubicka
2011-04-06 23:26 ` [PATCH 5/7] Tweaks to C++ -> call graph interface Martin Jambor
2011-04-11 15:30   ` Jason Merrill
2011-04-06 23:26 ` [PATCH 4/7] Removal of cgraph_node function Martin Jambor
2011-04-11 10:28   ` Jan Hubicka
2011-04-11 14:15     ` Martin Jambor
2011-04-06 23:26 ` [PATCH 6/7] A tweak to fortran -> call graph interface Martin Jambor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110406232245.532048483@virgil.suse.cz \
    --to=mjambor@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).