@@ -716,20 +716,18 @@ llvm::SmallVector<ReferenceLoc> refInStmt(const Stmt *S,
716
716
if (!D.isFieldDesignator ())
717
717
continue ;
718
718
719
- llvm::SmallVector<const NamedDecl *, 1 > Targets;
720
- if (D.getField ())
721
- Targets.push_back (D.getField ());
722
- Refs.push_back (ReferenceLoc{NestedNameSpecifierLoc (), D.getFieldLoc (),
723
- /* IsDecl=*/ false , std::move (Targets)});
719
+ Refs.push_back (ReferenceLoc{NestedNameSpecifierLoc (),
720
+ D.getFieldLoc (),
721
+ /* IsDecl=*/ false ,
722
+ {D.getField ()}});
724
723
}
725
724
}
726
725
727
726
void VisitGotoStmt (const GotoStmt *GS) {
728
- llvm::SmallVector<const NamedDecl *, 1 > Targets;
729
- if (const auto *L = GS->getLabel ())
730
- Targets.push_back (L);
731
- Refs.push_back (ReferenceLoc{NestedNameSpecifierLoc (), GS->getLabelLoc (),
732
- /* IsDecl=*/ false , std::move (Targets)});
727
+ Refs.push_back (ReferenceLoc{NestedNameSpecifierLoc (),
728
+ GS->getLabelLoc (),
729
+ /* IsDecl=*/ false ,
730
+ {GS->getLabel ()}});
733
731
}
734
732
735
733
void VisitLabelStmt (const LabelStmt *LS) {
@@ -882,17 +880,15 @@ class ExplicitReferenceCollector
882
880
// TemplateArgumentLoc is the only way to get locations for references to
883
881
// template template parameters.
884
882
bool TraverseTemplateArgumentLoc (TemplateArgumentLoc A) {
885
- llvm::SmallVector<const NamedDecl *, 1 > Targets;
886
883
switch (A.getArgument ().getKind ()) {
887
884
case TemplateArgument::Template:
888
885
case TemplateArgument::TemplateExpansion:
889
- if (const auto *D = A.getArgument ()
890
- .getAsTemplateOrTemplatePattern ()
891
- .getAsTemplateDecl ())
892
- Targets.push_back (D);
893
886
reportReference (ReferenceLoc{A.getTemplateQualifierLoc (),
894
887
A.getTemplateNameLoc (),
895
- /* IsDecl=*/ false , Targets},
888
+ /* IsDecl=*/ false ,
889
+ {A.getArgument ()
890
+ .getAsTemplateOrTemplatePattern ()
891
+ .getAsTemplateDecl ()}},
896
892
DynTypedNode::create (A.getArgument ()));
897
893
break ;
898
894
case TemplateArgument::Declaration:
@@ -975,11 +971,14 @@ class ExplicitReferenceCollector
975
971
}
976
972
977
973
void visitNode (DynTypedNode N) {
978
- for (const auto &R : explicitReference (N))
979
- reportReference (R , N);
974
+ for (auto &R : explicitReference (N))
975
+ reportReference (std::move (R) , N);
980
976
}
981
977
982
- void reportReference (const ReferenceLoc &Ref, DynTypedNode N) {
978
+ void reportReference (ReferenceLoc &&Ref, DynTypedNode N) {
979
+ // Strip null targets that can arise from invalid code.
980
+ // (This avoids having to check for null everywhere we insert)
981
+ llvm::erase_value (Ref.Targets , nullptr );
983
982
// Our promise is to return only references from the source code. If we lack
984
983
// location information, skip these nodes.
985
984
// Normally this should not happen in practice, unless there are bugs in the
0 commit comments