[PATCH] D79576: [AST] Fix the PrintQualifiedName for ObjC instance variable in class extension.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 19 06:29:11 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f56599c14af: [AST] Fix the PrintQualifiedName for ObjC instance variable in class extension. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79576

Files:
  clang/lib/AST/Decl.cpp
  clang/unittests/AST/NamedDeclPrinterTest.cpp


Index: clang/unittests/AST/NamedDeclPrinterTest.cpp
===================================================================
--- clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -230,6 +230,27 @@
     "Obj::property"));
 }
 
+TEST(NamedDeclPrinter, TestInstanceObjCClassExtension) {
+  const char *Code =
+R"(
+ at interface ObjC
+ at end
+ at interface ObjC () {
+  char data; // legal with non-fragile ABI.
+}
+ at end
+)";
+
+  std::vector<std::string> Args{
+      "-std=c++11", "-xobjective-c++",
+      "-fobjc-runtime=macosx" /*force to use non-fragile ABI*/};
+  ASSERT_TRUE(PrintedNamedDeclMatches(Code, Args,
+                                      /*SuppressUnwrittenScope*/ true,
+                                      namedDecl(hasName("data")).bind("id"),
+                                      // not "::data"
+                                      "ObjC::data", "input.mm"));
+}
+
 TEST(NamedDeclPrinter, TestObjCClassExtensionWithGetter) {
   const char *Code =
 R"(
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1571,13 +1571,16 @@
 
   // For ObjC methods and properties, look through categories and use the
   // interface as context.
-  if (auto *MD = dyn_cast<ObjCMethodDecl>(this))
+  if (auto *MD = dyn_cast<ObjCMethodDecl>(this)) {
     if (auto *ID = MD->getClassInterface())
       Ctx = ID;
-  if (auto *PD = dyn_cast<ObjCPropertyDecl>(this)) {
+  } else if (auto *PD = dyn_cast<ObjCPropertyDecl>(this)) {
     if (auto *MD = PD->getGetterMethodDecl())
       if (auto *ID = MD->getClassInterface())
         Ctx = ID;
+  } else if (auto *ID = dyn_cast<ObjCIvarDecl>(this)) {
+    if (auto *CI = ID->getContainingInterface())
+      Ctx = CI;
   }
 
   if (Ctx->isFunctionOrMethod())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79576.264883.patch
Type: text/x-patch
Size: 1852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200519/c12b345e/attachment.bin>


More information about the cfe-commits mailing list