aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-18 22:29:55 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-18 22:29:55 +0000
commit813d8346529bf094eb2b249648906ba7fd226688 (patch)
treeb9917a37b5e050662f3c952de8d182a594965b1e /lib
parent35eaa281af2ef2b5172746b35bac1509e17d513c (diff)
Selector::getIdentifierInfoForSlot() can return NULL values, a fact
that was ignored in a few places (most notably, code completion). Introduce Selector::getNameForSlot() for the common case where we only care about the name. Audit all uses of getIdentifierInfoForSlot(), switching many over to getNameForSlot(), fixing a few crashers. Fixed <rdar://problem/8939352>, a code-completion crasher. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125977 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/DeclarationName.cpp6
-rw-r--r--lib/AST/StmtPrinter.cpp2
-rw-r--r--lib/Basic/IdentifierTable.cpp5
-rw-r--r--lib/Sema/SemaCodeComplete.cpp24
-rw-r--r--lib/Sema/SemaExpr.cpp6
5 files changed, 21 insertions, 22 deletions
diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp
index ac3989bbb8..cef54e97c9 100644
--- a/lib/AST/DeclarationName.cpp
+++ b/lib/AST/DeclarationName.cpp
@@ -94,10 +94,8 @@ int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) {
Selector RHSSelector = RHS.getObjCSelector();
unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs();
for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
- IdentifierInfo *LHSId = LHSSelector.getIdentifierInfoForSlot(I);
- IdentifierInfo *RHSId = RHSSelector.getIdentifierInfoForSlot(I);
-
- switch (LHSId->getName().compare(RHSId->getName())) {
+ switch (LHSSelector.getNameForSlot(I).compare(
+ RHSSelector.getNameForSlot(I))) {
case -1: return true;
case 1: return false;
default: break;
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index a67e269790..1cdd220881 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -1311,7 +1311,7 @@ void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
OS << ' ';
Selector selector = Mess->getSelector();
if (selector.isUnarySelector()) {
- OS << selector.getIdentifierInfoForSlot(0)->getName();
+ OS << selector.getNameForSlot(0);
} else {
for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
if (i < selector.getNumArgs()) {
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp
index 48a5f49914..ef11d658ed 100644
--- a/lib/Basic/IdentifierTable.cpp
+++ b/lib/Basic/IdentifierTable.cpp
@@ -326,6 +326,11 @@ IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
return SI->getIdentifierInfoForSlot(argIndex);
}
+llvm::StringRef Selector::getNameForSlot(unsigned int argIndex) const {
+ IdentifierInfo *II = getIdentifierInfoForSlot(argIndex);
+ return II? II->getName() : llvm::StringRef();
+}
+
std::string MultiKeywordSelector::getName() const {
llvm::SmallString<256> Str;
llvm::raw_svector_ostream OS(Str);
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index 703734e247..a65d5fd6fc 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -2391,11 +2391,11 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S,
Selector Sel = Method->getSelector();
if (Sel.isUnarySelector()) {
Result.AddTypedTextChunk(Result.getAllocator().CopyString(
- Sel.getIdentifierInfoForSlot(0)->getName()));
+ Sel.getNameForSlot(0)));
return Result.TakeString();
}
- std::string SelName = Sel.getIdentifierInfoForSlot(0)->getName().str();
+ std::string SelName = Sel.getNameForSlot(0).str();
SelName += ':';
if (StartParameter == 0)
Result.AddTypedTextChunk(Result.getAllocator().CopyString(SelName));
@@ -4531,10 +4531,10 @@ static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword,
if (Sel.isUnarySelector()) {
if (NeedSuperKeyword)
Builder.AddTextChunk(Builder.getAllocator().CopyString(
- Sel.getIdentifierInfoForSlot(0)->getName()));
+ Sel.getNameForSlot(0)));
else
Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(
- Sel.getIdentifierInfoForSlot(0)->getName()));
+ Sel.getNameForSlot(0)));
} else {
ObjCMethodDecl::param_iterator CurP = CurMethod->param_begin();
for (unsigned I = 0, N = Sel.getNumArgs(); I != N; ++I, ++CurP) {
@@ -4544,17 +4544,17 @@ static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword,
if (I < NumSelIdents)
Builder.AddInformativeChunk(
Builder.getAllocator().CopyString(
- Sel.getIdentifierInfoForSlot(I)->getName().str() + ":"));
+ Sel.getNameForSlot(I) + ":"));
else if (NeedSuperKeyword || I > NumSelIdents) {
Builder.AddTextChunk(
Builder.getAllocator().CopyString(
- Sel.getIdentifierInfoForSlot(I)->getName().str() + ":"));
+ Sel.getNameForSlot(I) + ":"));
Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
(*CurP)->getIdentifier()->getName()));
} else {
Builder.AddTypedTextChunk(
Builder.getAllocator().CopyString(
- Sel.getIdentifierInfoForSlot(I)->getName().str() + ":"));
+ Sel.getNameForSlot(I) + ":"));
Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
(*CurP)->getIdentifier()->getName()));
}
@@ -5002,7 +5002,7 @@ void Sema::CodeCompleteObjCSelector(Scope *S, IdentifierInfo **SelIdents,
CodeCompletionBuilder Builder(Results.getAllocator());
if (Sel.isUnarySelector()) {
Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(
- Sel.getIdentifierInfoForSlot(0)->getName()));
+ Sel.getNameForSlot(0)));
Results.AddResult(Builder.TakeString());
continue;
}
@@ -5017,7 +5017,7 @@ void Sema::CodeCompleteObjCSelector(Scope *S, IdentifierInfo **SelIdents,
}
}
- Accumulator += Sel.getIdentifierInfoForSlot(I)->getName().str();
+ Accumulator += Sel.getNameForSlot(I).str();
Accumulator += ':';
}
Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Accumulator));
@@ -6115,7 +6115,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,
// Add the first part of the selector to the pattern.
Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(
- Sel.getIdentifierInfoForSlot(0)->getName()));
+ Sel.getNameForSlot(0)));
// Add parameters to the pattern.
unsigned I = 0;
@@ -6128,9 +6128,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,
else if (I < Sel.getNumArgs()) {
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddTypedTextChunk(
- Builder.getAllocator().CopyString(
- (Sel.getIdentifierInfoForSlot(I)->getName()
- + ":").str()));
+ Builder.getAllocator().CopyString(Sel.getNameForSlot(I) + ":"));
} else
break;
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index d5e6e77c3e..7e6eee7fb7 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -9487,13 +9487,11 @@ void Sema::DiagnoseAssignmentAsCondition(Expr *E) {
Selector Sel = ME->getSelector();
// self = [<foo> init...]
- if (isSelfExpr(Op->getLHS())
- && Sel.getIdentifierInfoForSlot(0)->getName().startswith("init"))
+ if (isSelfExpr(Op->getLHS()) && Sel.getNameForSlot(0).startswith("init"))
diagnostic = diag::warn_condition_is_idiomatic_assignment;
// <foo> = [<bar> nextObject]
- else if (Sel.isUnarySelector() &&
- Sel.getIdentifierInfoForSlot(0)->getName() == "nextObject")
+ else if (Sel.isUnarySelector() && Sel.getNameForSlot(0) == "nextObject")
diagnostic = diag::warn_condition_is_idiomatic_assignment;
}