Fixed problem with rewriting stand-alone @implementation (with no matching @interface).
A new test case added.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43568 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index ea73db5..66ece41 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1253,10 +1253,12 @@
   if (!IDecl) {
     // Legacy case of @implementation with no corresponding @interface.
     // Build, chain & install the interface decl into the identifier.
-    IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, ClassName);
+    IDecl = new ObjcInterfaceDecl(AtClassImplLoc, 0, ClassName, 
+				  false, true);
     IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
     ClassName->setFETokenInfo(IDecl);
     IDecl->setSuperClass(SDecl);
+    IDecl->setLocEnd(ClassLoc);
     
     // Remember that this needs to be removed when the scope is popped.
     TUScope->AddDecl(IDecl);
@@ -1273,7 +1275,8 @@
 }
 
 void Sema::CheckImplementationIvars(ObjcImplementationDecl *ImpDecl,
-                                    ObjcIvarDecl **ivars, unsigned numIvars) {
+                                    ObjcIvarDecl **ivars, unsigned numIvars,
+                                    SourceLocation RBrace) {
   assert(ImpDecl && "missing implementation decl");
   ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(ImpDecl->getIdentifier());
   if (!IDecl)
@@ -1282,7 +1285,7 @@
   /// (legacy objective-c @implementation decl without an @interface decl).
   /// Add implementations's ivar to the synthesize class's ivar list.
   if (IDecl->ImplicitInterfaceDecl()) {
-    IDecl->addInstanceVariablesToClass(ivars, numIvars, SourceLocation());
+    IDecl->addInstanceVariablesToClass(ivars, numIvars, RBrace);
     return;
   }
   
@@ -1795,7 +1798,7 @@
         cast<ObjcImplementationDecl>(static_cast<Decl*>(RecDecl));
       assert(IMPDecl && "ActOnFields - missing ObjcImplementationDecl");
       IMPDecl->ObjcAddInstanceVariablesToClassImpl(ClsFields, RecFields.size());
-      CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size());
+      CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
     }
   }
 }