On 01/19/2017 04:10 PM, Jan Hubicka wrote:
>>>> 2016-12-19  Martin Liska  <mli...@suse.cz>
>>>>
>>>>    * cgraphclones.c (cgraph_node::create_virtual_clone):
>>>>    Create either IPA_REF_LOAD of IPA_REF_READ depending on
>>>>    whether new_tree is a VAR_DECL or an ADDR_EXPR.
>>>>    * ipa-cp.c (create_specialized_node): Add reference just for
>>>>    ADDR_EXPRs.
>>>>    * symtab.c (symtab_node::maybe_create_reference): Remove guard
>>>>    as it's guarded in callers.
> 
> Path is OK
>>  ipa_ref *
>> -symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
>> -                                 gimple *stmt)
>> +symtab_node::maybe_create_reference (tree val, gimple *stmt)
>>  {
>>    STRIP_NOPS (val);
>> -  if (TREE_CODE (val) != ADDR_EXPR)
>> -    return NULL;
>> +  ipa_ref_use use_type;
>> +
>> +  switch (TREE_CODE (val))
>> +    {
>> +    case VAR_DECL:
>> +      use_type = IPA_REF_LOAD;
>> +      break;
>> +    case ADDR_EXPR:
>> +      use_type = IPA_REF_ADDR;
>> +      break;
>> +    default:
>> +      return NULL;
>> +    }
> 
> I would add assert into default that we don't get handled_component_ref here 
> so we are sure
> we don't miss any declarations (because the bug leads to quite esoteric 
> issues, it is better
> to be safe than sorry)
> 
> Honza
> 

Done in patch I've just installed as r244687.

Thanks for help,
Martin
>From b0c002ba76312ba7cf38a41b1127ae8a55e89639 Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Mon, 19 Dec 2016 11:03:34 +0100
Subject: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph (PR
 ipa/71190).

gcc/ChangeLog:

2017-01-19  Martin Liska  <mli...@suse.cz>

	PR ipa/71190
	* cgraph.h (maybe_create_reference): Remove argument and
	update comment.
	* cgraphclones.c (cgraph_node::create_virtual_clone): Remove one
	argument.
	* ipa-cp.c (create_specialized_node): Likewise.
	* symtab.c (symtab_node::maybe_create_reference): Handle
	VAR_DECLs and ADDR_EXPRs and select ipa_ref_use type.
---
 gcc/cgraph.h       |  6 ++----
 gcc/cgraphclones.c |  2 +-
 gcc/ipa-cp.c       |  2 +-
 gcc/symtab.c       | 25 ++++++++++++++++---------
 4 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index db2915c5751..5410a71176a 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -131,11 +131,9 @@ public:
 			     enum ipa_ref_use use_type, gimple *stmt);
 
   /* If VAL is a reference to a function or a variable, add a reference from
-     this symtab_node to the corresponding symbol table node.  USE_TYPE specify
-     type of the use and STMT the statement (if it exists).  Return the new
+     this symtab_node to the corresponding symbol table node.  Return the new
      reference or NULL if none was created.  */
-  ipa_ref *maybe_create_reference (tree val, enum ipa_ref_use use_type,
-				   gimple *stmt);
+  ipa_ref *maybe_create_reference (tree val, gimple *stmt);
 
   /* Clone all references from symtab NODE to this symtab_node.  */
   void clone_references (symtab_node *node);
diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index a17663519a9..c2337e84553 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -624,7 +624,7 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
       || in_lto_p)
     new_node->unique_name = true;
   FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
-    new_node->maybe_create_reference (map->new_tree, IPA_REF_ADDR, NULL);
+    new_node->maybe_create_reference (map->new_tree, NULL);
 
   if (ipa_transforms_to_apply.exists ())
     new_node->ipa_transforms_to_apply
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 9cc903769e8..aa3c9973a66 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -3786,7 +3786,7 @@ create_specialized_node (struct cgraph_node *node,
 					 args_to_skip, "constprop");
   ipa_set_node_agg_value_chain (new_node, aggvals);
   for (av = aggvals; av; av = av->next)
-    new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
+    new_node->maybe_create_reference (av->value, NULL);
 
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 87120970d34..c21e7acf28c 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -588,18 +588,25 @@ symtab_node::create_reference (symtab_node *referred_node,
   return ref;
 }
 
-/* If VAL is a reference to a function or a variable, add a reference from
-   this symtab_node to the corresponding symbol table node.  USE_TYPE specify
-   type of the use and STMT the statement (if it exists).  Return the new
-   reference or NULL if none was created.  */
-
 ipa_ref *
-symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
-				     gimple *stmt)
+symtab_node::maybe_create_reference (tree val, gimple *stmt)
 {
   STRIP_NOPS (val);
-  if (TREE_CODE (val) != ADDR_EXPR)
-    return NULL;
+  ipa_ref_use use_type;
+
+  switch (TREE_CODE (val))
+    {
+    case VAR_DECL:
+      use_type = IPA_REF_LOAD;
+      break;
+    case ADDR_EXPR:
+      use_type = IPA_REF_ADDR;
+      break;
+    default:
+      gcc_assert (!handled_component_p (val));
+      return NULL;
+    }
+
   val = get_base_var (val);
   if (val && VAR_OR_FUNCTION_DECL_P (val))
     {
-- 
2.11.0

Reply via email to