]> granicus.if.org Git - clang/commit
[CodeGen] Handle extern references to OBJC_CLASS_$_*
authorErik Pilkington <erik.pilkington@gmail.com>
Fri, 12 Oct 2018 17:22:10 +0000 (17:22 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Fri, 12 Oct 2018 17:22:10 +0000 (17:22 +0000)
commit0edbdbe2bc1e46c22c82e60e55bb4be4f26e6769
tree6a81362a5030f784cdbf77825a9ccefc8d005080
parent085848c54cf3102f13d2595c6c22624af06197dd
[CodeGen] Handle extern references to OBJC_CLASS_$_*

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 commit fixes the problem
by RAUWing the old (incorrectly typed) global with a new global, then removing
the old global.

rdar://45077269

Differential revision: https://reviews.llvm.org/D53154

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344373 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGObjCMac.cpp
test/CodeGenObjC/extern-void-class-decl.m [new file with mode: 0644]