[PATCH] D71112: [ASTImporter] Implicitly declare parameters for imported ObjCMethodDecls

Raphael Isemann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 6 09:53:45 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG164e0fc5c7f7: [ASTImporter] Implicitly declare parameters for imported ObjCMethodDecls (authored by teemperor).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71112/new/

https://reviews.llvm.org/D71112

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/Language.cpp


Index: clang/unittests/AST/Language.cpp
===================================================================
--- clang/unittests/AST/Language.cpp
+++ clang/unittests/AST/Language.cpp
@@ -37,8 +37,10 @@
   case Lang_CXX2a:
     BasicArgs = {"-std=c++2a", "-frtti"};
     break;
-  case Lang_OpenCL:
   case Lang_OBJCXX:
+    BasicArgs = {"-x", "objective-c++", "-frtti"};
+    break;
+  case Lang_OpenCL:
     llvm_unreachable("Not implemented yet!");
   }
   return BasicArgs;
Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5599,6 +5599,30 @@
             2u);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImplicitlyDeclareSelf) {
+  Decl *FromTU = getTuDecl(R"(
+                           __attribute__((objc_root_class))
+                           @interface Root
+                           @end
+                           @interface C : Root
+                             -(void)method;
+                           @end
+                           @implementation C
+                             -(void)method {}
+                           @end
+                           )",
+                           Lang_OBJCXX, "input.mm");
+  auto *FromMethod = LastDeclMatcher<ObjCMethodDecl>().match(
+      FromTU, namedDecl(hasName("method")));
+  ASSERT_TRUE(FromMethod);
+  auto ToMethod = Import(FromMethod, Lang_OBJCXX);
+  ASSERT_TRUE(ToMethod);
+
+  // Both methods should have their implicit parameters.
+  EXPECT_TRUE(FromMethod->getSelfDecl() != nullptr);
+  EXPECT_TRUE(ToMethod->getSelfDecl() != nullptr);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
                         DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -4010,6 +4010,14 @@
 
   ToMethod->setLexicalDeclContext(LexicalDC);
   LexicalDC->addDeclInternal(ToMethod);
+
+  // Implicit params are declared when Sema encounters the definition but this
+  // never happens when the method is imported. Manually declare the implicit
+  // params now that the MethodDecl knows its class interface.
+  if (D->getSelfDecl())
+    ToMethod->createImplicitParams(Importer.getToContext(),
+                                   ToMethod->getClassInterface());
+
   return ToMethod;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71112.232598.patch
Type: text/x-patch
Size: 2514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191206/b23cf4bf/attachment-0001.bin>


More information about the cfe-commits mailing list