This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: ObjC-specific changes to c-typeck.c
- From: Ziemowit Laski <zlaski at apple dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 23 Aug 2004 12:54:13 -0700
- Subject: PATCH: ObjC-specific changes to c-typeck.c
Returning to the ObjC++ integration theme, I shall now offer a series
of patches
modifying files (or portions thereof) specific to the C front-end, one
patch per
file.
The current patch contains the mod needed for c-typeck.c. The problem
was
that casts to ObjC types (e.g., '(Object <Proto> *)foo') were sometimes
getting
"optimized away" by build_c_cast(). This led to problems when
constructing
message expressions (e.g., '[(Object <Proto> *)foo msg]'), where not
knowing
the user-intended type for the receiver led to incorrect diagnostics,
or worse yet,
incorrect codegen (if an ABI-incompatible method signature were to be
selected).
OK to install if there are no regressions?
Thank you,
--Zem
[gcc/ChangeLog]
2004-08-23 Ziemowit Laski <zlaski@apple.com>
* c-typeck.c (build_c_cast): In ObjC, always preserve cast to an
Objective-C type.
Index: gcc/c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.360
diff -u -3 -p -r1.360 c-typeck.c
--- gcc/c-typeck.c 23 Aug 2004 03:12:31 -0000 1.360
+++ gcc/c-typeck.c 23 Aug 2004 19:23:00 -0000
@@ -2922,8 +2922,10 @@ build_c_cast (tree type, tree expr)
/* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types
differing
only in <protocol> qualifications. But when constructing cast
expressions,
the protocols do matter and must be kept around. */
- if (!c_dialect_objc () || !objc_is_object_ptr (type))
- type = TYPE_MAIN_VARIANT (type);
+ if (objc_is_object_ptr (type) && type != TREE_TYPE (expr))
+ return build1 (NOP_EXPR, type, expr);
+
+ type = TYPE_MAIN_VARIANT (type);
if (TREE_CODE (type) == ARRAY_TYPE)
{
--------------------------------------------------------------
Ziemowit Laski 1 Infinite Loop, MS 301-2K
Mac OS X Compiler Group Cupertino, CA USA 95014-2083
Apple Computer, Inc. +1.408.974.6229 Fax .5477