This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Handle extern references to OBJC_CLASS_$_*
ClosedPublic

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

Details

Summary

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

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

clang/lib/CodeGen/CGObjCMac.cpp
7193

Add /* isConstant=*/false

This revision was not accepted when it landed; it landed in state Needs Review.Oct 12 2018, 10:24 AM
This revision was automatically updated to reflect the committed changes.