This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: [PATCH] Fix PR45878
- From: "Nicola Pero" <nicola dot pero at meta-innovation dot com>
- To: "Richard Guenther" <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 14 Oct 2010 03:14:25 +0200 (CEST)
- Subject: RE: [PATCH] Fix PR45878
Thanks Richard
it looks great. :-)
Btw, I looked at this bug for a while tonight, and I ended up with a question ... maybe you know the answer or can hint at it ... why are we using OBJ_TYPE_REFs in Objective-C ?
As far as I can see, OBJ_TYPE_REFs are normally used to represent C++ virtual method lookups. The comment says that they represent "lookup in a virtual method table which is dependent on the runtime type of an object".
Objective-C method lookups/invocations seem considerably different - first of all, the result of any lookup is basically volatile and can change at any time [eg, it is valid for another thread to concurrently modify the "virtual method tables"], and second, the NeXT runtime doesn't even have a separate "lookup in a virtual method table" step - a single function call does everything (both lookup and invocation).
Do you know what is the advantage or reason for using OBJ_TYPE_REFs for Objective-C method lookups as opposed to doing them via standard C casts and function calls ?
It would be good to document the reason (if any) clearly. :-)
Thanks
-----Original Message-----
From: "Richard Guenther" <rguenther@suse.de>
Sent: Wednesday, 13 October, 2010 22:26
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR45878
This fixes another piece of that PR.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2010-10-13 Richard Guenther <rguenther@suse.de>
PR objc/45878
* gimple-fold.c (gimple_fold_obj_type_ref): Leave OBJ_TYPE_REFs
alone if there are no virtual methods.
* objc.dg/pr45878.m: New testcase.
Index: gcc/gimple-fold.c
===================================================================
*** gcc/gimple-fold.c (revision 165430)
--- gcc/gimple-fold.c (working copy)
*************** gimple_fold_obj_type_ref (tree ref, tree
*** 1524,1532 ****
if (binfo)
{
HOST_WIDE_INT token = tree_low_cst (OBJ_TYPE_REF_TOKEN (ref), 1);
! /* If there is no virtual methods fold this to an indirect call. */
if (!BINFO_VIRTUALS (binfo))
! return OBJ_TYPE_REF_EXPR (ref);
return gimple_fold_obj_type_ref_known_binfo (token, binfo);
}
else
--- 1524,1532 ----
if (binfo)
{
HOST_WIDE_INT token = tree_low_cst (OBJ_TYPE_REF_TOKEN (ref), 1);
! /* If there is no virtual methods leave the OBJ_TYPE_REF alone. */
if (!BINFO_VIRTUALS (binfo))
! return NULL_TREE;
return gimple_fold_obj_type_ref_known_binfo (token, binfo);
}
else
Index: gcc/testsuite/objc.dg/pr45878.m
===================================================================
*** gcc/testsuite/objc.dg/pr45878.m (revision 0)
--- gcc/testsuite/objc.dg/pr45878.m (revision 0)
***************
*** 0 ****
--- 1,28 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fexceptions" } */
+
+ typedef struct objc_object { Class class_pointer; } *id;
+ typedef unsigned char BOOL;
+
+ @interface Object
+ {
+ Class isa;
+ }
+ - (BOOL)isEqual:anObject;
+ @end
+
+ @interface NXConstantString: Object
+ {
+ char *c_string;
+ unsigned int len;
+ }
+ @end
+
+ void function (void)
+ {
+ if ([@"strings" isEqual: (id)0])
+ {
+ ;
+ }
+ }
+