[PATCH] Allow (Object *)kMyGlobalCFObjc casts without bridging
John McCall
rjmccall at apple.com
Tue Feb 24 14:30:44 PST 2015
> On Feb 24, 2015, at 11:14 AM, Ben Langmuir <blangmuir at apple.com> wrote:
> Hi John,
>
> As we discussed:
>
> Allow (Object *)kMyGlobalCFObj casts without bridging
>
> Previously we allowed these casts only for constants declared in system
> headers, which we assume are retain/release-neutral. Now also allow them
> for constants in user headers, treating them as +0. Practically, this
> means that we will now allow:
> id x = (id)kMyGlobalConst;
>
> But unlike with system headers we cannot mix them with +1 values:
> id y = (id)(b ? kMyGlobalConst : [Obj newValAtPlusOne]); // error
> id z = (id)(b ? kSystemGlobalConst: [Obj newValAtPlusOne]); // OK
>
> <extern-global-const-unbridged-cast.patch>
Yes, this good great, thank you.
You should also adjust the ARC specification:
1. Add "a load from a const non-system global variable of C retainable
pointer type” to the list of known unretained expressions in the section
entitled "Conversion to retainable object pointer type of expressions
with known semantics”. This should have a “beginning LLVM 3.6” note;
when it’s available in a released Apple compiler, we can be more specific.
2. Add a note to the rationale explaining the different treatment of
system and non-system globals: basically, that it’s reasonable to assume
that global constants were initialized with true constants (e.g. string
literals), but user constants might have been initialized with something
dynamically allocated, using a global initializer.
John.
More information about the cfe-commits
mailing list