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]

PATCH: PR objc/18408 (but really a gimplifier fix)


This is for

objc/18408 [4.0 Regression] ICE compiling code that involves casting classes

but really is a fix to the gimplifier, so I'd like GIMPLE-literate folk to take a look at this.

The gimplification process involves stripping useless (to the back-end -- ObjC does need them!) type conversions, such as NOP_EXPRs. This can be a problem if the NOP_EXPR in question is the argument of an INDIRECT_REF (e.g., '(*(List_linked*)collection).firstLink'); once the NOP_EXPR is removed, the INDIRECT_REF now has a type that is inconsistent with that of its (new) operand, leading to an assert failure later on.

The following patch fixes this, causing the attached test case to compile correctly. Does this look OK? I'll do full before-and-after testing to ensure nothing regresses, of course. Alternatively, is there a better way of accomplishing the same goal?

Thanks,

--Zem

[gcc/ChangeLog]
2004-11-11  Ziemowit Laski  <zlaski@apple.com>

        PR objc/18408
        * gimplify.c (gimplify_expr): Adjust the type of
        INDIRECT_REFs after their argument is gimplified.

[gcc/testsuite/ChangeLog]
2004-11-11  Ziemowit Laski  <zlaski@apple.com>

        PR objc/18408
        * objc.dg/comp-types-7.m: New test.

Index: gcc/gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.84
diff -u -3 -p -r2.84 gimplify.c
--- gcc/gimplify.c 23 Oct 2004 09:16:46 -0000 2.84
+++ gcc/gimplify.c 12 Nov 2004 01:05:27 -0000
@@ -3659,6 +3659,14 @@ gimplify_expr (tree *expr_p, tree *pre_p
case INDIRECT_REF:
ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
is_gimple_reg, fb_rvalue);
+
+ /* Useless type conversions may have been discarded, so ensure
+ that the INDIRECT_REF has a type corresponding to the pointee
+ type of its operand. */
+ if (TREE_CODE (*expr_p) == INDIRECT_REF)
+ TREE_TYPE (*expr_p)
+ = TREE_TYPE (TREE_TYPE (TREE_OPERAND (*expr_p, 0)));
+
recalculate_side_effects (*expr_p);
break;


Index: gcc/testsuite/objc.dg/comp-types-7.m
===================================================================
RCS file: gcc/testsuite/objc.dg/comp-types-7.m
diff -N gcc/testsuite/objc.dg/comp-types-7.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/objc.dg/comp-types-7.m 12 Nov 2004 01:05:37 -0000
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+@interface List
+{
+@public
+ int firstLink;
+}
+@end
+
+@interface ListIndex_linked
+{
+@public
+ List *collection;
+ int link;
+}
+@end
+
+@interface List_linked: List
+@end
+
+@implementation List
+@end
+
+@implementation ListIndex_linked
+- next
+{
+ /* The gimplifier should be able to eliminate the cast in the rhs below. */
+ link = ((List_linked*)collection)->firstLink;
+}
+@end



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