[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
Thu May 7 07:20:07 PDT 2020
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, ilya-biryukov.
Herald added a project: clang.
Similar to property, we print the containing interface decl as the
nested name specifier for ivar; otherwise we will get "::ivar_name".
this would fix an assertion crash in clangd: https://github.com/clangd/clangd/issues/365
Repository:
rG LLVM Github Monorepo
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.262644.patch
Type: text/x-patch
Size: 1852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200507/833f179c/attachment-0001.bin>
More information about the cfe-commits
mailing list