[cfe-commits] [PATCH] Add -fobjc-direct-class-refs

John McCall rjmccall at apple.com
Wed Jul 11 19:21:00 PDT 2012

On Jul 11, 2012, at 6:05 PM, Jonathan Schleifer wrote:
> Am 12.07.2012 um 02:58 schrieb John McCall:
>> Subscripting on objects has an existing meaning in fragile runtimes:  it's pointer arithmetic.  Is that meaning useful?  Well, possibly not, but nonetheless such code has historically been valid.
> As such code does not exist for ObjFW as there is not that historical part, I'd like to just forbid pointer arithmetics and allow subscripts.

That seems totally reasonable.

>> Now, technically that only applies to subscripts of integral type;  subscripts of pointer type are ill-formed, so we could have given them the new behavior and left the integral case as pointer arithmetic.  We felt that that would add a lot of confusion for little gain, and I think that's still true for objfw.
> Not quite sure how this will add confusion?

It's nice to talk about subscripting as a single language feature.  Pointer arithmetic on ObjC pointers has been dead for years, and we now have tons of users who have never targeted a platform that used the fragile ABI.  Saying "oh, uh, by the way, don't try to subscript arrays on this runtime because it doesn't do what you think it does" is just bad manners. :)  But what you're going to do is fine, so let's just do that.

>> IIRC, you were considering making objfw use the non-fragile runtime.
> Yes, but only optionally, due to the performance impact. The idea would be to be compatible with both and being able to chose per file.
>> In that case, you might want to proactively forbid pointer arithmetic.
> Yes, that sounds sane.
>> I'd be fine with you adding a new predicate (allowsPointerArithmetic()) on ObjCRuntime for this, if you then change Sema to use it in all the appropriate places.  (You seem to have a good feel for how to do this.)  You should also add another predicate (isSubscriptPointerArithmetic()), with the invariant that it's only true if allowsPointerArithmetic() is, which Sema would use to decide how to interpret subscripting on ObjC pointers.
> Will do that, thanks.


>> I'd prefer that that be a separate patch, anyway.  The rest of your patch looks fine to me, so if you wouldn't mind preparing a patch without the subscript changes, I'd be happy to commit that for you.
> Removed the last two hunks from the patch and attached it again (just lazily removed them with an editor).

I added a test case (please do include tests in your patches!) and committed this as r160102.

For the record, I should establish a policy here and give you some fair warning.  We're happy to keep support for ObjFW in the tree as long as you're maintaining your runtime.  If it ever looks like it's become a dead project, and we can't reach any maintainers for an extended period of time, we reserve the right to strip this code out as bit-rotted.  Okay?


More information about the cfe-commits mailing list