objective-C IRGen: for @implementation nested in
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 26 Oct 2012 20:22:11 +0000 (20:22 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 26 Oct 2012 20:22:11 +0000 (20:22 +0000)
extern "C", its method definitions must be IRGen'ed
before meta-data for class is generated. Otherwise,
IRGen crashes (to say the least).
// rdar://12581683

llvm-svn: 166809

clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenObjCXX/implementation-in-extern-c.mm [new file with mode: 0644]

index 5425eaf..65ba91a 100644 (file)
@@ -2582,8 +2582,15 @@ void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) {
   }
 
   for (RecordDecl::decl_iterator I = LSD->decls_begin(), E = LSD->decls_end();
-       I != E; ++I)
+       I != E; ++I) {
+    if (ObjCImplDecl *OID = dyn_cast<ObjCImplDecl>(*I)) {
+      for (ObjCContainerDecl::method_iterator M = OID->meth_begin(),
+           MEnd = OID->meth_end();
+           M != MEnd; ++M)
+        EmitTopLevelDecl(*M);
+    }
     EmitTopLevelDecl(*I);
+  }
 }
 
 /// EmitTopLevelDecl - Emit code for a single top level declaration.
diff --git a/clang/test/CodeGenObjCXX/implementation-in-extern-c.mm b/clang/test/CodeGenObjCXX/implementation-in-extern-c.mm
new file mode 100644 (file)
index 0000000..4c1ee25
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
+// rdar://12581683
+
+extern "C" {
+@interface RetainBucket 
++ (id) sharedRetainBucket;
+@end
+
+@implementation RetainBucket
++ (id) sharedRetainBucket
+{
+    static id sharedBucket = (id)0;
+    return sharedBucket;
+}
+@end
+}
+