Page MenuHomePhabricator

[CodeGen] Handle extern references to OBJC_CLASS_$_*

Authored by erik.pilkington on Oct 11 2018, 11:16 AM.



Some ObjC users declare a extern variable named OBJC_CLASS_$_Foo, then use it's address as a Class. I.e., one could define isInstanceOfF:

BOOL isInstanceOfF(id c) {
  extern void OBJC_CLASS_$_F;
  return [c class] == (Class)&OBJC_CLASS_$_F;

This leads to asserts in clang CodeGen if there is an @implementation of F in the same TU as an instance of this pattern, because CodeGen assumes that a variable named OBJC_CLASS_$_* has the right type. This patch fixes the problem by RAUWing the old (incorrectly typed) global with a new global, then removing the old global.

I know almost nothing about Objective-C runtime stuff, so take this patch with a grain of salt!

Fixes rdar://45077269

Diff Detail

rC Clang

Event Timeline

jfb added a comment.Oct 11 2018, 11:22 AM

Overall this seems fine, but I'm no ObjC expert either so I'll defer to @rjmccall

7193 ↗(On Diff #169251)

Add /* isConstant=*/false

This revision was not accepted when it landed; it landed in state Needs Review.Oct 12 2018, 10:24 AM
Closed by commit rC344373: [CodeGen] Handle extern references to OBJC_CLASS_$_* (authored by epilk, committed by ). · Explain Why
This revision was automatically updated to reflect the committed changes.