diff mbox

Fix PR45878

Message ID alpine.LNX.2.00.1010132021580.23074@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Oct. 13, 2010, 6:23 p.m. UTC
This fixes ccp_fold_stmt to use gimple_fold_obj_type_ref so we can
centrailize knowledge on how to interpret that in the context of
a known function-decl in OBJ_TYPE_REF_EXPR.

Appearantly this fixes PR45878.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2010-10-13  Richard Guenther  <rguenther@suse.de>

	PR objc/45878
	* tree-ssa-ccpc (ccp_fold_stmt): Use gimple_fold_obj_type_ref.
diff mbox

Patch

Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c	(revision 165419)
+++ tree-ssa-ccp.c	(working copy)
@@ -2267,6 +2284,7 @@  ccp_fold_stmt (gimple_stmt_iterator *gsi
 	tree lhs = gimple_call_lhs (stmt);
 	tree val;
 	tree argt;
+	tree callee;
 	bool changed = false;
 	unsigned i;
 
@@ -2306,16 +2324,24 @@  ccp_fold_stmt (gimple_stmt_iterator *gsi
 		changed = true;
 	      }
 	  }
-	if (TREE_CODE (gimple_call_fn (stmt)) == OBJ_TYPE_REF)
+
+	callee = gimple_call_fn (stmt);
+	if (TREE_CODE (callee) == OBJ_TYPE_REF
+	    && TREE_CODE (OBJ_TYPE_REF_EXPR (callee)) == SSA_NAME)
 	  {
-	    tree expr = OBJ_TYPE_REF_EXPR (gimple_call_fn (stmt));
-	    expr = valueize_op (expr);
-	    if (TREE_CODE (expr) == ADDR_EXPR
-	        && TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL)
-	     {
-	       gimple_call_set_fn (stmt, expr);
-	       changed = true;
-	     }
+	    tree expr = OBJ_TYPE_REF_EXPR (callee);
+	    OBJ_TYPE_REF_EXPR (callee) = valueize_op (expr);
+	    if (TREE_CODE (OBJ_TYPE_REF_EXPR (callee)) == ADDR_EXPR)
+	      {
+		tree t;
+		t = gimple_fold_obj_type_ref (callee, NULL_TREE);
+		if (t)
+		  {
+		    gimple_call_set_fn (stmt, t);
+		    changed = true;
+		  }
+	      }
+	    OBJ_TYPE_REF_EXPR (callee) = expr;
 	  }
 
 	return changed;