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]

Re: [PATCH] Fix PR optimization/12085


> Is it "valid Objective-C"? Some testcases in the objc testsuite produce
> CALL_EXPR trees with a cast to a non-compatible function type.

Attached is a patch that passes the objc testsuite.  Note that objc_comptypes 
appears to do nothing for function types and always return -1 (so the 
testcase compiles).  If I use comptypes for objc, I get several testsuite 
failures.


2003-12-17  Eric Botcazou  <ebotcazou@libertysurf.fr>

        PR c/12085
	* c-typeck.c (build_function_call): Issue an error if a
	function is called through an incompatible prototype.


2003-12-17  Eric Botcazou  <ebotcazou@libertysurf.fr>

	* gcc.dg/cast-function-1.c: New test.


-- 
Eric Botcazou
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.265
diff -u -p -r1.265 c-typeck.c
--- c-typeck.c	13 Dec 2003 04:11:19 -0000	1.265
+++ c-typeck.c	17 Dec 2003 08:25:54 -0000
@@ -1684,6 +1684,24 @@ build_function_call (tree function, tree
   /* fntype now gets the type of function pointed to.  */
   fntype = TREE_TYPE (fntype);
 
+  /* Check that the function is called through a compatible prototype.  */
+  if (TREE_CODE (function) == NOP_EXPR)
+    {
+      tree real_fntype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (function, 0)));
+      int compatible_p;
+
+      if (c_dialect_objc ())
+	compatible_p = objc_comptypes (fntype, real_fntype, 0);
+      else
+	compatible_p = comptypes (fntype, real_fntype, COMPARE_STRICT);
+
+      if (! compatible_p)
+	{
+	  error ("function called through a non-compatible type");
+	  return error_mark_node;
+	}
+    }
+
   /* Convert the parameters to the types declared in the
      function prototype, or apply default promotions.  */
 
/* PR c/12085 */
/* Origin: David Hollenberg <dhollen@mosis.org> */

/* { dg-do compile } */

int foo(int);

void bar(void)
{
  double d;
  int i;

  d = ((double (*) (int)) foo)(i);  /* { dg-error "non-compatible" } */
  i = ((int (*) (double)) foo)(d);  /* { dg-error "non-compatible" } */
}

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