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"(
+@interface ObjC
+@end
+@interface ObjC () {
+  char data; // legal with non-fragile ABI.
+}
+@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())


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"(
+@interface ObjC
+@end
+@interface ObjC () {
+  char data; // legal with non-fragile ABI.
+}
+@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())
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to