Patch to make ObjcImplementationDecl derived from TypeDecl and supprt legacy
objective-c code with no @interface declaration.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42319 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 9a52874..5470eb4 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1105,6 +1105,14 @@
   
   ObjcImplementationDecl* IMPDecl = 
     new ObjcImplementationDecl(AtClassImplLoc, ClassName, SDecl);
+  if (!IDecl) {
+    // Legacy case of @implementation with no corresponding @interface.
+    // Build, chain & install the interface decl into the identifier.
+    IDecl = new ObjcInterfaceDecl(AtClassImplLoc, 0, ClassName);
+    IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
+    ClassName->setFETokenInfo(IDecl);
+    
+  }
   
   // Check that there is no duplicate implementation of this class.
   bool err = false;
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 425e871..7cb370b 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -858,7 +858,7 @@
   static bool classof(const ObjcCategoryDecl *D) { return true; }
 };
   
-class ObjcImplementationDecl : public ScopedDecl {
+class ObjcImplementationDecl : public TypeDecl {
     
   /// Implementation Class's super class.
   ObjcInterfaceDecl *SuperClass;
@@ -878,7 +878,7 @@
   public:
   ObjcImplementationDecl(SourceLocation L, IdentifierInfo *Id,
                          ObjcInterfaceDecl* superDecl)
-    : ScopedDecl(ObjcImplementation, L, Id, 0),
+    : TypeDecl(ObjcImplementation, L, Id, 0),
       SuperClass(superDecl),
       Ivars(0), NumIvars(-1),
       InsMethods(0), NumInsMethods(-1), ClsMethods(0), NumClsMethods(-1) {}
diff --git a/test/Sema/objc-legacy-implementation-1.m b/test/Sema/objc-legacy-implementation-1.m
new file mode 100644
index 0000000..c706ec7
--- /dev/null
+++ b/test/Sema/objc-legacy-implementation-1.m
@@ -0,0 +1,9 @@
+@implementation INTF // expected-warning {{cannot find interface declaration for 'INTF'}}
+@end
+
+INTF* pi;
+
+INTF* FUNC()
+{
+	return pi;
+}