Please keep in mind that I'm not a GCC internals expert, and this really
requires some analysis from an ObjC maintainer (and expert) along with someone
who is familiar with the details of how -fstrict-aliasing works.

See also: http://gcc.gnu.org/ml/gcc/2009-04/msg00290.html

The short version is this:  Currently, it would appear the compiler (and I'm
assuming all versions of the compiler that perform -fstrict-aliasing) applies
C99 strict-aliasing rules to pointers to Objective-C objects.  Although there
is no formal language specification for Objective-C, it would seem that the
most appropriate way to treat pointers to Objective-C objects is the same as
'char *' in terms of C99 aliasing rules.  That is to say, a pointer to an
Objective-C object can aliasing anything.

As an experiment, I added the following line to c-common.c /
c_common_get_alias_set() to determine how often the compiler is applying
incorrect aliasing rules while informing the alias analyzer that the pointer
can aliasing anything.

if(((c_language == clk_objc) || (c_language == clk_objcxx)) &&
((TYPE_LANG_SPECIFIC (t) && (TYPE_LANG_SPECIFIC(t)->objc_info)) ||
objc_is_object_ptr(t))) {
  warning(OPT_Wstrict_aliasing, "Caught and returning 'can alias anything' for
objc type");
  return(0);
}

right before the following line:

if (c_language != clk_c || flag_isoc99)

This returned a number (actually, a lot) of warnings when compiling Objective-C
code at -O2 and -Wstrict-aliasing.

In the mailing-list post referenced above, someone mentions that they think
that GNUstep uses '-fno-strict-aliasing' when compiling code.  This seems like
a good test to see how effective a patch like this is.

Recommendation:

Apply the above 'patch' (or functional equivalent) to the compiler, minus the
warning() line, to all versions of the compiler that apply C99 strict-aliasing
rules.


-- 
           Summary: Objective-C(++) and C99 strict-aliasing interaction bug
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: objc
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: john dot engelhart at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39753

Reply via email to