r333046 - [AST][ObjC] Print implicit property expression that only has a setter without crashing
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Tue May 22 17:52:20 PDT 2018
Author: arphaman
Date: Tue May 22 17:52:20 2018
New Revision: 333046
URL: http://llvm.org/viewvc/llvm-project?rev=333046&view=rev
Log:
[AST][ObjC] Print implicit property expression that only has a setter without crashing
rdar://40447209
Modified:
cfe/trunk/include/clang/Basic/IdentifierTable.h
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Basic/IdentifierTable.cpp
cfe/trunk/test/Misc/ast-print-objectivec.m
Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=333046&r1=333045&r2=333046&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Tue May 22 17:52:20 2018
@@ -825,6 +825,9 @@ public:
static Selector constructSetterSelector(IdentifierTable &Idents,
SelectorTable &SelTable,
const IdentifierInfo *Name);
+
+ /// Return the property name for the given setter selector.
+ static std::string getPropertyNameFromSetterSelector(Selector Sel);
};
/// DeclarationNameExtra - Common base of the MultiKeywordSelector,
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=333046&r1=333045&r2=333046&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Tue May 22 17:52:20 2018
@@ -1406,9 +1406,13 @@ void StmtPrinter::VisitObjCPropertyRefEx
OS << Node->getClassReceiver()->getName() << ".";
}
- if (Node->isImplicitProperty())
- Node->getImplicitPropertyGetter()->getSelector().print(OS);
- else
+ if (Node->isImplicitProperty()) {
+ if (const auto *Getter = Node->getImplicitPropertyGetter())
+ Getter->getSelector().print(OS);
+ else
+ OS << SelectorTable::getPropertyNameFromSetterSelector(
+ Node->getImplicitPropertySetter()->getSelector());
+ } else
OS << Node->getExplicitProperty()->getName();
}
Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=333046&r1=333045&r2=333046&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Tue May 22 17:52:20 2018
@@ -645,6 +645,12 @@ SelectorTable::constructSetterSelector(I
return SelTable.getUnarySelector(SetterName);
}
+std::string SelectorTable::getPropertyNameFromSetterSelector(Selector Sel) {
+ StringRef Name = Sel.getNameForSlot(0);
+ assert(Name.startswith("set") && "invalid setter name");
+ return (Twine(toLowercase(Name[3])) + Name.drop_front(4)).str();
+}
+
size_t SelectorTable::getTotalMemory() const {
SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
return SelTabImpl.Allocator.getTotalMemory();
Modified: cfe/trunk/test/Misc/ast-print-objectivec.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-objectivec.m?rev=333046&r1=333045&r2=333046&view=diff
==============================================================================
--- cfe/trunk/test/Misc/ast-print-objectivec.m (original)
+++ cfe/trunk/test/Misc/ast-print-objectivec.m Tue May 22 17:52:20 2018
@@ -50,3 +50,13 @@ struct __attribute__((objc_bridge_relate
// CHECK: @class C1;
// CHECK: struct __attribute__((objc_bridge_related(C1, , ))) S1;
+
+ at interface ImplicitPropertyWithSetterOnly
+
+- (void)setX:(int)x;
+
+ at end
+
+void printImplicitPropertyWithSetterOnly(ImplicitPropertyWithSetterOnly *x) {
+ x.x = 313; // CHECK: x.x = 313;
+}
More information about the cfe-commits
mailing list