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
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index 703734e..a65d5fd 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -2391,11 +2391,11 @@
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 @@
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 @@
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 @@
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 @@
}
}
- Accumulator += Sel.getIdentifierInfoForSlot(I)->getName().str();
+ Accumulator += Sel.getNameForSlot(I).str();
Accumulator += ':';
}
Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Accumulator));
@@ -6115,7 +6115,7 @@
// 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 @@
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;