=====

[gcc]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p
	to ensure a call statement is compatible with a built-in's
	prototype.
	* tree-ssa-math-opts.c (pass_optimize_windening_mul::execute):
	Likewise.

[gcc/testsuite]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* gcc.dg/torture/pr70457.c: New.


Index: gcc/testsuite/gcc.dg/torture/pr70457.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr70457.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr70457.c	(working copy)
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+
+/* This formerly ICEd when trying to expand pow as a built-in with
+   the wrong number of arguments.  */
+
+extern double pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__));
+extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__));
+
+typedef int int64_t __attribute__ ((__mode__ (__DI__)));
+
+typedef struct {
+  int64_t data;
+  int tag;
+} Object;
+
+extern Object Make_Flonum (double);
+extern Object P_Pow (Object, Object);
+
+Object General_Function (Object x, Object y, double (*fun)()) {
+  double d, ret;
+
+  d = 1.0;
+
+  if (y.tag >> 1)
+    ret = (*fun) (d);
+  else
+    ret = (*fun) (d, 0.0);
+
+  return Make_Flonum (ret);
+}
+
+Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); }
Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c	(revision 234702)
+++ gcc/tree-inline.c	(working copy)
@@ -4065,7 +4065,7 @@ estimate_num_insns (gimple *stmt, eni_weights *wei
 	      return 0;
 	    else if (is_inexpensive_builtin (decl))
 	      return weights->target_builtin_call_cost;
-	    else if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
+	    else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 	      {
 		/* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so
 		   specialize the cheap expansion we do here.
Index: gcc/tree-ssa-math-opts.c
===================================================================
--- gcc/tree-ssa-math-opts.c	(revision 234702)
+++ gcc/tree-ssa-math-opts.c	(working copy)
@@ -3827,7 +3827,7 @@ pass_optimize_widening_mul::execute (function *fun
 	    {
 	      tree fndecl = gimple_call_fndecl (stmt);
 	      if (fndecl
-		  && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+		  && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 		{
 		  switch (DECL_FUNCTION_CODE (fndecl))
 		    {

GCC 5
=====

[gcc]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p
	to ensure a call statement is compatible with a built-in's
	prototype.
	* tree-ssa-math-opts.c (execute_cse_sincos_1): Likewise.
	(pass_cse_sincos::execute): Likewise.
	(pass_optimize_widening_mul::execute):	Likewise.

[gcc/testsuite]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* gcc.dg/torture/pr70457.c: New.


Index: gcc/testsuite/gcc.dg/torture/pr70457.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr70457.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr70457.c	(working copy)
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+
+/* This formerly ICEd when trying to expand pow as a built-in with
+   the wrong number of arguments.  */
+
+extern double pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__));
+extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__));
+
+typedef int int64_t __attribute__ ((__mode__ (__DI__)));
+
+typedef struct {
+  int64_t data;
+  int tag;
+} Object;
+
+extern Object Make_Flonum (double);
+extern Object P_Pow (Object, Object);
+
+Object General_Function (Object x, Object y, double (*fun)()) {
+  double d, ret;
+
+  d = 1.0;
+
+  if (y.tag >> 1)
+    ret = (*fun) (d);
+  else
+    ret = (*fun) (d, 0.0);
+
+  return Make_Flonum (ret);
+}
+
+Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); }
Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c	(revision 234705)
+++ gcc/tree-inline.c	(working copy)
@@ -4111,7 +4111,7 @@ estimate_num_insns (gimple stmt, eni_weights *weig
 	      return 0;
 	    else if (is_inexpensive_builtin (decl))
 	      return weights->target_builtin_call_cost;
-	    else if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
+	    else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 	      {
 		/* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so
 		   specialize the cheap expansion we do here.
Index: gcc/tree-ssa-math-opts.c
===================================================================
--- gcc/tree-ssa-math-opts.c	(revision 234705)
+++ gcc/tree-ssa-math-opts.c	(working copy)
@@ -769,7 +769,7 @@ execute_cse_sincos_1 (tree name)
       if (gimple_code (use_stmt) != GIMPLE_CALL
 	  || !gimple_call_lhs (use_stmt)
 	  || !(fndecl = gimple_call_fndecl (use_stmt))
-	  || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
+	  || !gimple_call_builtin_p (use_stmt, BUILT_IN_NORMAL))
 	continue;
 
       switch (DECL_FUNCTION_CODE (fndecl))
@@ -1488,7 +1488,7 @@ pass_cse_sincos::execute (function *fun)
 	  if (is_gimple_call (stmt)
 	      && gimple_call_lhs (stmt)
 	      && (fndecl = gimple_call_fndecl (stmt))
-	      && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+	      && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 	    {
 	      tree arg, arg0, arg1, result;
 	      HOST_WIDE_INT n;
@@ -3339,7 +3339,7 @@ pass_optimize_widening_mul::execute (function *fun
 	    {
 	      tree fndecl = gimple_call_fndecl (stmt);
 	      if (fndecl
-		  && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+		  && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 		{
 		  switch (DECL_FUNCTION_CODE (fndecl))
 		    {


GCC 4.9
=======

[gcc]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p
	to ensure a call statement is compatible with a built-in's
	prototype.
	* tree-ssa-math-opts.c (execute_cse_sincos_1): Likewise.
	(execute_cse_sincos): Likewise.
	(execute_optimize_widening_mul): Likewise.

[gcc/testsuite]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* gcc.dg/torture/pr70457.c: New.


Index: gcc/testsuite/gcc.dg/torture/pr70457.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr70457.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr70457.c	(working copy)
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+
+/* This formerly ICEd when trying to expand pow as a built-in with
+   the wrong number of arguments.  */
+
+extern double pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__));
+extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__));
+
+typedef int int64_t __attribute__ ((__mode__ (__DI__)));
+
+typedef struct {
+  int64_t data;
+  int tag;
+} Object;
+
+extern Object Make_Flonum (double);
+extern Object P_Pow (Object, Object);
+
+Object General_Function (Object x, Object y, double (*fun)()) {
+  double d, ret;
+
+  d = 1.0;
+
+  if (y.tag >> 1)
+    ret = (*fun) (d);
+  else
+    ret = (*fun) (d, 0.0);
+
+  return Make_Flonum (ret);
+}
+
+Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); }
Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c	(revision 234702)
+++ gcc/tree-inline.c	(working copy)
@@ -3850,7 +3850,7 @@ estimate_num_insns (gimple stmt, eni_weights *weig
 	      return 0;
 	    else if (is_inexpensive_builtin (decl))
 	      return weights->target_builtin_call_cost;
-	    else if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
+	    else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 	      {
 		/* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so
 		   specialize the cheap expansion we do here.
Index: gcc/tree-ssa-math-opts.c
===================================================================
--- gcc/tree-ssa-math-opts.c	(revision 234702)
+++ gcc/tree-ssa-math-opts.c	(working copy)
@@ -746,7 +746,7 @@ execute_cse_sincos_1 (tree name)
       if (gimple_code (use_stmt) != GIMPLE_CALL
 	  || !gimple_call_lhs (use_stmt)
 	  || !(fndecl = gimple_call_fndecl (use_stmt))
-	  || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
+	  || !gimple_call_builtin_p (use_stmt, BUILT_IN_NORMAL))
 	continue;
 
       switch (DECL_FUNCTION_CODE (fndecl))
@@ -1437,7 +1437,7 @@ execute_cse_sincos (void)
 	  if (is_gimple_call (stmt)
 	      && gimple_call_lhs (stmt)
 	      && (fndecl = gimple_call_fndecl (stmt))
-	      && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+	      && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 	    {
 	      tree arg, arg0, arg1, result;
 	      HOST_WIDE_INT n;
@@ -2860,7 +2860,7 @@ execute_optimize_widening_mul (void)
 	    {
 	      tree fndecl = gimple_call_fndecl (stmt);
 	      if (fndecl
-		  && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+		  && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
 		{
 		  switch (DECL_FUNCTION_CODE (fndecl))
 		    {
