clang: lib/Sema/SemaLookup.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
40#include "llvm/ADT/STLExtras.h"
41#include "llvm/ADT/STLForwardCompat.h"
42#include "llvm/ADT/SmallPtrSet.h"
43#include "llvm/ADT/TinyPtrVector.h"
44#include "llvm/ADT/edit_distance.h"
45#include "llvm/Support/Casting.h"
46#include "llvm/Support/ErrorHandling.h"
47#include
48#include
49#include
50#include
51#include
52#include
53#include
54
55#include "OpenCLBuiltins.inc"
56
57using namespace clang;
58using namespace sema;
59
60namespace {
61 class UnqualUsingEntry {
62 const DeclContext *Nominated;
63 const DeclContext *CommonAncestor;
64
65 public:
66 UnqualUsingEntry(const DeclContext *Nominated,
67 const DeclContext *CommonAncestor)
68 : Nominated(Nominated), CommonAncestor(CommonAncestor) {
69 }
70
71 const DeclContext *getCommonAncestor() const {
72 return CommonAncestor;
73 }
74
75 const DeclContext *getNominatedNamespace() const {
76 return Nominated;
77 }
78
79
80 struct Comparator {
81 bool operator()(const UnqualUsingEntry &L, const UnqualUsingEntry &R) {
82 return L.getCommonAncestor() < R.getCommonAncestor();
83 }
84
85 bool operator()(const UnqualUsingEntry &E, const DeclContext *DC) {
86 return E.getCommonAncestor() < DC;
87 }
88
89 bool operator()(const DeclContext *DC, const UnqualUsingEntry &E) {
90 return DC < E.getCommonAncestor();
91 }
92 };
93 };
94
95
96
97 class UnqualUsingDirectiveSet {
98 Sema &SemaRef;
99
100 typedef SmallVector<UnqualUsingEntry, 8> ListTy;
101
102 ListTy list;
103 llvm::SmallPtrSet<DeclContext*, 8> visited;
104
105 public:
106 UnqualUsingDirectiveSet(Sema &SemaRef) : SemaRef(SemaRef) {}
107
108 void visitScopeChain(Scope *S, Scope *InnermostFileScope) {
109
110
111
112
113 DeclContext *InnermostFileDC = InnermostFileScope->getEntity();
114 assert(InnermostFileDC && InnermostFileDC->isFileContext());
115
117
118
119
120 DeclContext *Ctx = S->getEntity();
122 visit(Ctx, Ctx);
125 if (SemaRef.isVisible(I))
126 visit(I, InnermostFileDC);
127 }
128 }
129 }
130
131
132
133
134
135
136
137
138 void visit(DeclContext *DC, DeclContext *EffectiveDC) {
139 if (!visited.insert(DC).second)
140 return;
141
142 addUsingDirectives(DC, EffectiveDC);
143 }
144
145
146
147
148 void visit(UsingDirectiveDecl *UD, DeclContext *EffectiveDC) {
150 if (!visited.insert(NS).second)
151 return;
152
153 addUsingDirective(UD, EffectiveDC);
154 addUsingDirectives(NS, EffectiveDC);
155 }
156
157
158
159
160 void addUsingDirectives(DeclContext *DC, DeclContext *EffectiveDC) {
161 SmallVector<DeclContext*, 4> queue;
162 while (true) {
165 if (SemaRef.isVisible(UD) && visited.insert(NS).second) {
166 addUsingDirective(UD, EffectiveDC);
167 queue.push_back(NS);
168 }
169 }
170
171 if (queue.empty())
172 return;
173
174 DC = queue.pop_back_val();
175 }
176 }
177
178
179
180
181
182
183
184
185 void addUsingDirective(UsingDirectiveDecl *UD, DeclContext *EffectiveDC) {
186
187
189 while (!Common->Encloses(EffectiveDC))
192
194 }
195
196 void done() { llvm::sort(list, UnqualUsingEntry::Comparator()); }
197
198 typedef ListTy::const_iterator const_iterator;
199
200 const_iterator begin() const { return list.begin(); }
201 const_iterator end() const { return list.end(); }
202
203 llvm::iterator_range<const_iterator>
204 getNamespacesFor(const DeclContext *DC) const {
205 return llvm::make_range(std::equal_range(begin(), end(),
207 UnqualUsingEntry::Comparator()));
208 }
209 };
210}
211
212
213
217 unsigned IDNS = 0;
218 switch (NameKind) {
229 }
232 break;
233
235
236
237 assert( && "cannot do redeclaration operator lookup");
239 break;
240
244
245
246
247
248
249
252 } else {
254 }
255 break;
256
259 break;
260
265 break;
266
269 break;
270
273 break;
274
276 assert(Redeclaration && "should only be used for redecl lookup");
280 break;
281
284 break;
285
288 break;
289
292 break;
293
298 break;
299 }
300 return IDNS;
301}
302
303void LookupResult::configure() {
306
307
308
309
310 switch (NameInfo.getName().getCXXOverloadedOperator()) {
311 case OO_New:
312 case OO_Delete:
313 case OO_Array_New:
314 case OO_Array_Delete:
316 break;
317
318 default:
319 break;
320 }
321
322
323
324 if (IdentifierInfo *Id = NameInfo.getName().getAsIdentifierInfo()) {
325 if (unsigned BuiltinID = Id->getBuiltinID()) {
327 AllowHidden = true;
328 }
329 }
330}
331
332bool LookupResult::checkDebugAssumptions() const {
333
337 (Decls.size() == 1 &&
340 checkUnresolved());
342 (Decls.size() == 1 &&
345 assert((Paths != nullptr) ==
349 return true;
350}
351
352
353void LookupResult::deletePaths(CXXBasePaths *Paths) {
354 delete Paths;
355}
356
357
358
360
361
362
365 return DC;
366
367
368
370}
371
372
373
377
378
381 return true;
382
385
386
387
388
389
390
391
392
393
394 if (DUnderlying->getCanonicalDecl() != EUnderlying->getCanonicalDecl()) {
397 bool WantTag =
399 return HaveTag != WantTag;
400 }
401
402
403
404
405
406 if (const auto *DFD = dyn_cast(DUnderlying)) {
408 unsigned DMin = DFD->getMinRequiredArguments();
409 unsigned EMin = EFD->getMinRequiredArguments();
410
411 if (DMin != EMin)
412 return DMin < EMin;
413
414
415 }
416
417
418 if (const auto *DTD = dyn_cast(DUnderlying)) {
420 unsigned DMin = DTD->getTemplateParameters()->getMinRequiredArguments();
421 unsigned EMin = ETD->getTemplateParameters()->getMinRequiredArguments();
422
423
424
425 if (DMin != EMin)
426 return DMin < EMin;
427
428
429
430 for (unsigned I = DMin, N = DTD->getTemplateParameters()->size();
431 I != N; ++I) {
433 ETD->getTemplateParameters()->getParam(I)) &&
435 DTD->getTemplateParameters()->getParam(I)))
436 return true;
437 }
438 }
439
440
441
442 if (const auto *DVD = dyn_cast(DUnderlying)) {
444 if (EVD->getType()->isIncompleteType() &&
445 !DVD->getType()->isIncompleteType()) {
446
448 }
449 return false;
450 }
451
452
454
455
457 }
458
459
462 if (Prev == EUnderlying)
463 return true;
464 return false;
465}
466
467
469
470
471
472
473
474
475
476
477
478
479
480
485}
486
487
489 unsigned N = Decls.size();
490
491
492 if (N == 0) {
495 return;
496 }
497
498
499
500 if (N == 1) {
506 return;
507 }
508
509
511 return;
512
513 llvm::SmallDenseMap<const NamedDecl *, unsigned, 16> Unique;
514 llvm::SmallDenseMap<QualType, unsigned, 16> UniqueTypes;
515
517 bool ReferenceToPlaceHolderVariable = false;
518 bool HasTag = false, HasFunction = false;
519 bool HasFunctionTemplate = false, HasUnresolved = false;
520 const NamedDecl *HasNonFunction = nullptr;
521
523 llvm::BitVector RemovedDecls(N);
524
525 for (unsigned I = 0; I < N; I++) {
528
529
530
532 N - RemovedDecls.count() > 1) {
533 RemovedDecls.set(I);
534 continue;
535 }
536
537
538
539
540
541
542
543
545 bool Hidden = false;
546 for (auto *OtherDecl : Decls) {
547 if (canHideTag(OtherDecl) && !OtherDecl->isInvalidDecl() &&
550 RemovedDecls.set(I);
551 Hidden = true;
552 break;
553 }
554 }
555 if (Hidden)
556 continue;
557 }
558
559 std::optional ExistingI;
560
561
562
563
564
565 if (const auto *TD = dyn_cast(D)) {
566 auto UniqueResult = UniqueTypes.insert(
567 std::make_pair(getSema().Context.getCanonicalTypeDeclType(TD), I));
568 if (!UniqueResult.second) {
569
570 ExistingI = UniqueResult.first->second;
571 }
572 }
573
574
575
576 if (!ExistingI) {
577 auto UniqueResult = Unique.insert(std::make_pair(D, I));
578 if (!UniqueResult.second) {
579
580 ExistingI = UniqueResult.first->second;
581 }
582 }
583
584 if (ExistingI) {
585
586
588 Decls[*ExistingI]))
589 Decls[*ExistingI] = Decls[I];
590 RemovedDecls.set(I);
591 continue;
592 }
593
594
595
597 HasUnresolved = true;
599 if (HasTag)
601 HasTag = true;
603 HasFunction = true;
604 HasFunctionTemplate = true;
606 HasFunction = true;
607 } else {
608 if (HasNonFunction) {
609
610
611
612
613 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
614 D)) {
615 EquivalentNonFunctions.push_back(D);
616 RemovedDecls.set(I);
617 continue;
618 }
622 ReferenceToPlaceHolderVariable = true;
623 }
625 }
626 HasNonFunction = D;
627 }
628 }
629
630
631
632 if (!EquivalentNonFunctions.empty() && )
634 getNameLoc(), HasNonFunction, EquivalentNonFunctions);
635
636
637
638
639 for (int I = RemovedDecls.find_last(); I >= 0; I = RemovedDecls.find_prev(I))
640 Decls[I] = Decls[--N];
641 Decls.truncate(N);
642
643 if ((HasNonFunction && (HasFunction || HasUnresolved)) ||
644 (HideTags && HasTag && (HasFunction || HasNonFunction || HasUnresolved)))
646
647 if (Ambiguous && ReferenceToPlaceHolderVariable)
651 else if (HasUnresolved)
653 else if (N > 1 || HasFunctionTemplate)
655 else
657}
658
659void LookupResult::addDeclsFromBasePaths(const CXXBasePaths &P) {
661 for (I = P.begin(), E = P.end(); I != E; ++I)
663 ++DI)
665}
666
669 Paths->swap(P);
670 addDeclsFromBasePaths(*Paths);
673}
674
677 Paths->swap(P);
678 addDeclsFromBasePaths(*Paths);
681}
682
684 Out << Decls.size() << " result(s)";
686 if (Paths) Out << ", base paths present";
687
689 Out << "\n";
690 (*I)->print(Out, 2);
691 }
692}
693
700
701
703 llvm::StringRef Name) {
705 << TypeClass << Name;
707}
708
709
714 if (Result.empty())
720}
721
722
727 if (Result.empty())
733 std::nullopt, Decl);
734}
735
736
737
738
739
740
741
742
743
744
745
746
748 Sema &S, const OpenCLBuiltinStruct &OpenCLBuiltin, unsigned &GenTypeMaxCnt,
751
752 unsigned Sig = SignatureTable[OpenCLBuiltin.SigTableIndex];
753 OCL2Qual(S, TypeTable[Sig], RetTypes);
754 GenTypeMaxCnt = RetTypes.size();
755
756
757
758 for (unsigned Index = 1; Index < OpenCLBuiltin.NumTypes; Index++) {
760 OCL2Qual(S, TypeTable[SignatureTable[OpenCLBuiltin.SigTableIndex + Index]],
761 Ty);
762 GenTypeMaxCnt = (Ty.size() > GenTypeMaxCnt) ? Ty.size() : GenTypeMaxCnt;
763 ArgTypes.push_back(std::move(Ty));
764 }
765}
766
767
768
769
770
771
772
773
774
775
777 ASTContext &Context, unsigned GenTypeMaxCnt,
781 Context.getTargetInfo().getDefaultCallingConv());
783
784
785
786 if (RetTypes.size() == 0)
787 return;
788
789
790 for (unsigned IGenType = 0; IGenType < GenTypeMaxCnt; IGenType++) {
792
793 for (unsigned A = 0; A < ArgTypes.size(); A++) {
794
795 if (ArgTypes[A].size() == 0)
796 return;
797
798
799
800
801 assert(GenTypeMaxCnt % ArgTypes[A].size() == 0 &&
802 "argument type count not compatible with gentype type count");
803 unsigned Idx = IGenType % ArgTypes[A].size();
804 ArgList.push_back(ArgTypes[A][Idx]);
805 }
806
807 FunctionList.push_back(Context.getFunctionType(
808 RetTypes[(RetTypes.size() != 1) ? IGenType : 0], ArgList, PI));
809 }
810}
811
812
813
814
815
816
817
818
819
820
823 const unsigned FctIndex,
824 const unsigned Len) {
825
826 bool HasGenType = false;
827
828
829
830 unsigned GenTypeMaxCnt;
831
833
834 for (unsigned SignatureIndex = 0; SignatureIndex < Len; SignatureIndex++) {
835 const OpenCLBuiltinStruct &OpenCLBuiltin =
836 BuiltinTable[FctIndex + SignatureIndex];
837
838
839
840 if (!isOpenCLVersionContainedInMask(Context.getLangOpts(),
841 OpenCLBuiltin.Versions))
842 continue;
843
844
845
846
847 StringRef Extensions = FunctionExtensionTable[OpenCLBuiltin.Extension];
848 if (!Extensions.empty()) {
850 Extensions.split(ExtVec, " ");
851 bool AllExtensionsDefined = true;
852 for (StringRef Ext : ExtVec) {
854 AllExtensionsDefined = false;
855 break;
856 }
857 }
858 if (!AllExtensionsDefined)
859 continue;
860 }
861
864
865
867 ArgTypes);
868 if (GenTypeMaxCnt > 1) {
869 HasGenType = true;
870 }
871
872
873 std::vector FunctionList;
875 ArgTypes);
876
878 DeclContext *Parent = Context.getTranslationUnitDecl();
880
881 for (const auto &FTy : FunctionList) {
883 Context, Parent, Loc, Loc, II, FTy, nullptr, SC_Extern,
885 FTy->isFunctionProtoType());
887
888
889
892 for (unsigned IParm = 0, e = FP->getNumParams(); IParm != e; ++IParm) {
895 nullptr, FP->getParamType(IParm), nullptr, SC_None, nullptr);
897 ParmList.push_back(Parm);
898 }
899 NewOpenCLBuiltin->setParams(ParmList);
900
901
902 if (OpenCLBuiltin.IsPure)
903 NewOpenCLBuiltin->addAttr(PureAttr::CreateImplicit(Context));
904 if (OpenCLBuiltin.IsConst)
905 NewOpenCLBuiltin->addAttr(ConstAttr::CreateImplicit(Context));
906 if (OpenCLBuiltin.IsConv)
907 NewOpenCLBuiltin->addAttr(ConvergentAttr::CreateImplicit(Context));
908
910 NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context));
911
912 LR.addDecl(NewOpenCLBuiltin);
913 }
914 }
915
916
917 if (Len > 1 || HasGenType)
919}
920
923
924
925
926
930 if (II) {
933#define BuiltinTemplate(BIName)
934#define CPlusPlusBuiltinTemplate(BIName) \
935 if (II == getASTContext().get##BIName##Name()) { \
936 R.addDecl(getASTContext().get##BIName##Decl()); \
937 return true; \
938 }
939#include "clang/Basic/BuiltinTemplates.inc"
940 }
942#define BuiltinTemplate(BIName)
943#define HLSLBuiltinTemplate(BIName) \
944 if (II == getASTContext().get##BIName##Name()) { \
945 R.addDecl(getASTContext().get##BIName##Decl()); \
946 return true; \
947 }
948#include "clang/Basic/BuiltinTemplates.inc"
949 }
950 }
951
952
954 auto Index = isOpenCLBuiltin(II->getName());
955 if (Index.first) {
957 Index.second);
958 return true;
959 }
960 }
961
962 if (RISCV().DeclareRVVBuiltins || RISCV().DeclareSiFiveVectorBuiltins ||
963 RISCV().DeclareAndesVectorBuiltins) {
964 if (().IntrinsicManager)
966
968
969 if (RISCV().IntrinsicManager->CreateIntrinsicIfFound(R, II, PP))
970 return true;
971 }
972
973
974 if (unsigned BuiltinID = II->getBuiltinID()) {
975
976
978 Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
979 return false;
980
985 return true;
986 }
987 }
988 }
989 }
990
991 return false;
992}
993
994
995
996
1003 if (const TagDecl *TD = Result.getAsSingle<TagDecl>())
1004 Context.setObjCSuperType(Context.getCanonicalTagType(TD));
1005}
1006
1008 if (ID == Builtin::BIobjc_msgSendSuper)
1010}
1011
1012
1013
1015
1016 if (!Class->getDefinition() || Class->isDependentContext())
1017 return false;
1018
1019
1020 return !Class->isBeingDefined();
1021}
1022
1025 return;
1026
1027
1028 if (Class->needsImplicitDefaultConstructor())
1030
1031
1032 if (Class->needsImplicitCopyConstructor())
1034
1035
1036 if (Class->needsImplicitCopyAssignment())
1038
1040
1041 if (Class->needsImplicitMoveConstructor())
1043
1044
1045 if (Class->needsImplicitMoveAssignment())
1047 }
1048
1049
1050 if (Class->needsImplicitDestructor())
1052}
1053
1054
1055
1060 return true;
1061
1064
1065 default:
1066 break;
1067 }
1068
1069 return false;
1070}
1071
1072
1073
1078 if (!DC)
1079 return;
1080
1086 if (Record->needsImplicitDefaultConstructor())
1088 if (Record->needsImplicitCopyConstructor())
1091 Record->needsImplicitMoveConstructor())
1093 }
1094 break;
1095
1098 if (Record->getDefinition() && Record->needsImplicitDestructor() &&
1101 break;
1102
1105 break;
1106
1110 if (Record->needsImplicitCopyAssignment())
1113 Record->needsImplicitMoveAssignment())
1115 }
1116 }
1117 break;
1118
1121 break;
1122
1123 default:
1124 break;
1125 }
1126}
1127
1128
1129
1131 bool Found = false;
1132
1133
1136 DC);
1137
1138
1144 }
1145 }
1146
1148 return true;
1149
1155
1156
1157
1158
1159
1161 if (->isCompleteDefinition())
1163
1164
1165
1166
1167 auto *ContainedDeducedType =
1171 ContainedDeducedType && ContainedDeducedType->isUndeducedType())
1173
1175 UEnd = Record->conversion_end(); U != UEnd; ++U) {
1177 if (!ConvTemplate)
1178 continue;
1179
1180
1181
1182
1183
1185 R.addDecl(ConvTemplate);
1187 continue;
1188 }
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1202
1205 assert(ConvProto && "Nonsensical conversion function template type");
1206
1207
1208
1209
1215
1216
1217
1223 }
1224 }
1225
1227}
1228
1229
1232 UnqualUsingDirectiveSet &UDirs) {
1233
1234 assert(NS && NS->isFileContext() && "CppNamespaceLookup() requires namespace!");
1235
1236
1238
1239
1240
1241 for (const UnqualUsingEntry &UUE : UDirs.getNamespacesFor(NS))
1242 if (LookupDirect(S, R, UUE.getNominatedNamespace()))
1244
1246
1248}
1249
1255
1256
1257
1258
1261 if (DeclContext *DC = OuterS->getLookupEntity())
1262 return DC;
1263 return nullptr;
1264}
1265
1266namespace {
1267
1268
1269struct FindLocalExternScope {
1270 FindLocalExternScope(LookupResult &R)
1271 : R(R), OldFindLocalExtern(R.getIdentifierNamespace() &
1272 Decl::IDNS_LocalExtern) {
1275 }
1276 void restore() {
1278 }
1279 ~FindLocalExternScope() {
1280 restore();
1281 }
1282 LookupResult &R;
1283 bool OldFindLocalExtern;
1284};
1285}
1286
1289
1292
1293
1294
1296 for (Scope *PreS = S; PreS; PreS = PreS->getParent())
1297 if (DeclContext *DC = PreS->getEntity())
1299 }
1300
1301
1302
1303
1304
1305
1306
1310 return false;
1311 }
1312
1313
1314
1315
1316 Scope *Initial = S;
1317 IdentifierResolver::iterator
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339 UnqualUsingDirectiveSet UDirs(*this);
1340 bool VisitedUsingDirectives = false;
1341 bool LeftStartingScope = false;
1342
1343
1344 FindLocalExternScope FindLocals(R);
1345
1347 bool SearchNamespaceScope = true;
1348
1349 for (; I != IEnd && S->isDeclScope(*I); ++I) {
1352 !(*I)->isTemplateParameter()) {
1353
1354
1355
1356
1357
1358 if (!LeftStartingScope && !Initial->isDeclScope(*I))
1359 LeftStartingScope = true;
1360
1361
1362
1363 if (LeftStartingScope && !((*I)->hasLinkage())) {
1365 continue;
1366 }
1367 } else {
1368
1369
1370 SearchNamespaceScope = false;
1371 }
1373 }
1374 }
1375 if (!SearchNamespaceScope) {
1378 if (auto *Record = dyn_cast_if_present(S->getEntity()))
1380 return true;
1381 }
1382
1384
1385
1386
1387
1388
1389 return false;
1390 }
1391
1395
1396
1397
1399 continue;
1400
1401
1402
1403
1405
1406
1407 if (ObjCMethodDecl *Method = dyn_cast(Ctx)) {
1409 if (ObjCInterfaceDecl *Class = Method->getClassInterface()) {
1410 ObjCInterfaceDecl *ClassDeclared;
1411 if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(
1413 ClassDeclared)) {
1417 return true;
1418 }
1419 }
1420 }
1421 }
1422
1423 continue;
1424 }
1425
1426
1427
1429
1430 if (!VisitedUsingDirectives) {
1431
1432 for (DeclContext *UCtx = Ctx; UCtx; UCtx = UCtx->getParent()) {
1433 if (UCtx->isTransparentContext())
1434 continue;
1435
1436 UDirs.visit(UCtx, UCtx);
1437 }
1438
1439
1440
1441 Scope *InnermostFileScope = S;
1442 while (InnermostFileScope &&
1444 InnermostFileScope = InnermostFileScope->getParent();
1445 UDirs.visitScopeChain(Initial, InnermostFileScope);
1446
1447 UDirs.done();
1448
1449 VisitedUsingDirectives = true;
1450 }
1451
1454 return true;
1455 }
1456
1457 continue;
1458 }
1459
1460
1461
1462
1463
1464
1465
1467 return true;
1468 }
1469 }
1470 }
1471
1472
1473
1474 if (!S) return false;
1475
1476
1478 return false;
1479
1480
1481
1482
1483
1484
1485 if (!VisitedUsingDirectives) {
1486 UDirs.visitScopeChain(Initial, S);
1487 UDirs.done();
1488 }
1489
1490
1491
1493 FindLocals.restore();
1494
1495
1496
1497
1498
1500
1501 bool Found = false;
1502 for (; I != IEnd && S->isDeclScope(*I); ++I) {
1504
1505
1506
1507
1510 }
1511 }
1512
1515 return true;
1516 }
1517
1519 if (Ctx) {
1522
1523
1524
1526 continue;
1527
1528
1529
1530
1533 "We should have been looking only at file context here already.");
1534
1535
1538 }
1539
1542 return true;
1543 }
1544
1546 return false;
1547 }
1548 }
1549
1551 return false;
1552 }
1553
1554 return !R.empty();
1555}
1556
1559 Context.mergeDefinitionIntoModule(ND, M);
1560 else
1561
1563
1564
1565
1566 if (auto *TD = dyn_cast(ND))
1567 for (auto *Param : *TD->getTemplateParameters())
1569
1570
1571
1572
1573
1574
1575 if (auto *ED = dyn_cast(ND);
1576 ED && ED->isFromGlobalModule() && !ED->isScoped()) {
1577 for (auto *ECD : ED->enumerators()) {
1578 ECD->setVisibleDespiteOwningModule();
1580 if (RedeclCtx->lookup(ECD->getDeclName()).empty())
1582 }
1583 }
1584}
1585
1586
1588 if (FunctionDecl *FD = dyn_cast(Entity)) {
1589
1590
1592 Entity = Pattern;
1593 } else if (CXXRecordDecl *RD = dyn_cast(Entity)) {
1595 Entity = Pattern;
1596 } else if (EnumDecl *ED = dyn_cast(Entity)) {
1597 if (auto *Pattern = ED->getTemplateInstantiationPattern())
1598 Entity = Pattern;
1599 } else if (VarDecl *VD = dyn_cast(Entity)) {
1601 Entity = Pattern;
1602 }
1603
1604
1605
1607 if (Context->isFileContext())
1610}
1611
1615 I != N; ++I) {
1618 nullptr;
1620 M = nullptr;
1622 }
1624}
1625
1626bool Sema::isUsableModule(const Module *M) {
1627 assert(M && "We shouldn't check nullness for module here");
1628
1629 if (UsableModuleUnitsCache.count(M))
1630 return true;
1631
1632
1633
1634
1635
1636
1637 if (M == TheGlobalModuleFragment || M == TheImplicitGlobalModuleFragment) {
1638 UsableModuleUnitsCache.insert(M);
1639 return true;
1640 }
1641
1642
1643
1645 return false;
1646
1648
1649
1650
1651 if (!Current)
1652 return false;
1653
1654
1655
1660
1661
1662
1663
1664
1665
1666
1667 if (llvm::count_if(ModuleScopes,
1668 [&M](const ModuleScope &MS) { return MS.Module == M; }) ||
1670 UsableModuleUnitsCache.insert(M);
1671 return true;
1672 }
1673
1674 return false;
1675}
1676
1678 for (const Module *Merged : Context.getModulesWithMergedDefinition(Def))
1680 return true;
1681 return false;
1682}
1683
1685 for (const Module *Merged : Context.getModulesWithMergedDefinition(Def))
1686 if (isUsableModule(Merged))
1687 return true;
1688 return false;
1689}
1690
1691template
1692static bool
1696 if (!D->hasDefaultArgument())
1697 return false;
1698
1700 while (D && Visited.insert(D).second) {
1701 auto &DefaultArg = D->getDefaultArgStorage();
1702 if (!DefaultArg.isInherited() && S.isAcceptable(D, Kind))
1703 return true;
1704
1705 if (!DefaultArg.isInherited() && Modules) {
1706 auto *NonConstD = const_cast<ParmDecl*>(D);
1708 }
1709
1710
1711
1712 D = DefaultArg.getInheritedFrom();
1713 }
1714 return false;
1715}
1716
1720 if (auto *P = dyn_cast(D))
1721 return ::hasAcceptableDefaultArgument(*this, P, Modules, Kind);
1722
1723 if (auto *P = dyn_cast(D))
1724 return ::hasAcceptableDefaultArgument(*this, P, Modules, Kind);
1725
1726 return ::hasAcceptableDefaultArgument(
1728}
1729
1735
1741
1742template
1743static bool
1747 bool HasFilteredRedecls = false;
1748
1749 for (auto *Redecl : D->redecls()) {
1751 if (!F(R))
1752 continue;
1753
1755 return true;
1756
1757 HasFilteredRedecls = true;
1758
1759 if (Modules)
1760 Modules->push_back(R->getOwningModule());
1761 }
1762
1763
1764 if (HasFilteredRedecls)
1765 return false;
1766
1767 return true;
1768}
1769
1770static bool
1775 S, D, Modules,
1777 if (auto *RD = dyn_cast(D))
1778 return RD->getTemplateSpecializationKind() ==
1780 if (auto *FD = dyn_cast(D))
1781 return FD->getTemplateSpecializationKind() ==
1783 if (auto *VD = dyn_cast(D))
1784 return VD->getTemplateSpecializationKind() ==
1786 llvm_unreachable("unknown explicit specialization kind");
1787 },
1788 Kind);
1789}
1790
1793 return ::hasAcceptableExplicitSpecialization(*this, D, Modules,
1795}
1796
1799 return ::hasAcceptableExplicitSpecialization(*this, D, Modules,
1801}
1802
1803static bool
1808 "not a member specialization");
1810 S, D, Modules,
1812
1813
1814
1815
1816
1817
1818
1819
1821 },
1822 Kind);
1823}
1824
1830
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846bool LookupResult::isAcceptableSlow(Sema &SemaRef, NamedDecl *D,
1849 "should not call this: not in slow case");
1850
1852 assert(DeclModule && "hidden decl has no owning module");
1853
1854
1857 return true;
1858
1859
1860
1861
1862 auto IsEffectivelyFileContext = [](const DeclContext *DC) {
1865 };
1866
1867
1868
1870 if (DC && !IsEffectivelyFileContext(DC)) {
1871
1872
1873
1874
1875
1876
1877
1878 bool AcceptableWithinParent;
1880 bool SearchDefinitions = true;
1881 if (const auto *DCD = dyn_cast(DC)) {
1882 if (const auto *TD = DCD->getDescribedTemplate()) {
1885 SearchDefinitions = Index >= TPL->size() || TPL->getParam(Index) != D;
1886 }
1887 }
1888 if (SearchDefinitions)
1889 AcceptableWithinParent =
1891 else
1892 AcceptableWithinParent =
1898
1899
1900 AcceptableWithinParent = false;
1901 do {
1903 AcceptableWithinParent = true;
1904 break;
1905 }
1907 } while (!IsEffectivelyFileContext(DC));
1908 } else {
1909 AcceptableWithinParent =
1911 }
1912
1915
1916 !SemaRef.getLangOpts().ModulesLocalVisibility) {
1917
1918
1920 }
1921 return AcceptableWithinParent;
1922 }
1923
1925 return false;
1926
1928 "Additional Sema::AcceptableKind?");
1929 return isReachableSlow(SemaRef, D);
1930}
1931
1933
1934
1935 if (ModulePrivate && isUsableModule(M))
1936 return true;
1937
1938
1939
1940 if (!ModulePrivate && VisibleModules.isVisible(M))
1941 return true;
1942
1943
1944
1945
1946
1948 if (LookupModules.empty())
1949 return false;
1950
1951
1952 if (LookupModules.count(M))
1953 return true;
1954
1955
1956
1957
1959 return true;
1960
1961
1962 if (ModulePrivate)
1963 return false;
1964
1965
1966 return llvm::any_of(LookupModules, [&](const Module *LookupM) {
1968 });
1969}
1970
1971
1972
1973bool LookupResult::isReachableSlow(Sema &SemaRef, NamedDecl *D) {
1974 assert((SemaRef, D) && "Shouldn't call the slow case.\n");
1975
1977 assert(DeclModule && "hidden decl has no owning module");
1978
1979
1981 return false;
1982
1984 return true;
1985
1986
1987
1988
1989
1990
1991
1992
1993
1995 return false;
1996
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2018 return true;
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2031
2032
2033
2034
2036 return true;
2037
2038
2039 return false;
2040}
2041
2044}
2045
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056 for (auto *D : R) {
2058 return true;
2060 "should not have hidden, non-externally-declarable result here");
2061 }
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079 return New->isExternallyDeclarable();
2080}
2081
2082
2083
2084
2085
2086
2087
2088
2089
2091 unsigned IDNS) {
2093
2094 for (auto *RD : D->redecls()) {
2095
2096 if (RD == D)
2097 continue;
2098
2100
2101
2102
2103 if (ND->isInIdentifierNamespace(IDNS) &&
2105 return ND;
2106 }
2107
2108 return nullptr;
2109}
2110
2113 assert((D) && "not in slow case");
2115 *this, D, Modules, [](const NamedDecl *) { return true; },
2117}
2118
2121 assert((D) && "not in slow case");
2123 *this, D, Modules, [](const NamedDecl *) { return true; },
2125}
2126
2128 if (auto *ND = dyn_cast(D)) {
2129
2130
2131
2132
2133
2134
2135 auto *Key = ND->getCanonicalDecl();
2136 if (auto *Acceptable = getSema().VisibleNamespaceCache.lookup(Key))
2137 return Acceptable;
2139 ? Key
2141 if (Acceptable)
2143 return Acceptable;
2144 }
2145
2147}
2148
2150
2152 return true;
2153
2154
2155
2157}
2158
2161 return true;
2162
2164}
2165
2167
2169 return true;
2170
2171
2172
2173
2174
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190 if (auto *FD = dyn_cast(ND);
2191 FD && FD->isReservedGlobalPlacementOperator())
2192 return true;
2193
2195
2196
2198 return false;
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208 if (auto *TD = dyn_cast(DC))
2210
2211 return false;
2212}
2213
2215 bool ForceNoCPlusPlus) {
2217 if (!Name) return false;
2218
2220
2222
2223
2225
2229 }
2230
2231
2232 FindLocalExternScope FindLocals(R);
2233
2234
2235
2236
2237
2238 bool LeftStartingScope = false;
2239
2242 I != IEnd; ++I)
2245
2246
2247 if (!LeftStartingScope && !S->isDeclScope(*I))
2248 LeftStartingScope = true;
2249
2250
2251
2252 if (LeftStartingScope && !((*I)->hasLinkage())) {
2254 continue;
2255 }
2256 }
2259 continue;
2260
2262
2263
2264
2265 if (I != IEnd) {
2266
2267
2270
2271
2272
2273
2275 S = nullptr;
2276
2277
2279 if (!S)
2281
2283 for (++LastI; LastI != IEnd; ++LastI) {
2284 if (S) {
2285
2287 break;
2288 } else {
2289
2292 if (!LastDC->Equals(DC))
2293 break;
2294 }
2295
2296
2299 }
2300
2302 }
2303
2304 return true;
2305 }
2306 } else {
2307
2308 if (CppLookupName(R, S))
2309 return true;
2310 }
2311
2312
2313
2314
2316 return true;
2317
2318
2319
2320
2321
2323}
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2354 assert(StartDC->isFileContext() && "start context is not a file context");
2355
2356
2357
2359
2360
2362 Visited.insert(StartDC);
2363
2364
2365
2367 NamespaceDecl *ND = I->getNominatedNamespace()->getFirstDecl();
2368 if (S.isVisible(I) && Visited.insert(ND).second)
2369 Queue.push_back(ND);
2370 }
2371
2372
2373
2374
2375
2376 bool FoundTag = false;
2377 bool FoundNonTag = false;
2378
2380
2381 bool Found = false;
2382 while (!Queue.empty()) {
2384
2385
2386
2387 bool UseLocal = !R.empty();
2388 LookupResult &DirectR = UseLocal ? LocalR : R;
2389 bool FoundDirect = LookupDirect(S, DirectR, ND);
2390
2391 if (FoundDirect) {
2392
2394
2395
2397 FoundTag = true;
2398 else
2399 FoundNonTag = true;
2400
2401
2402 if (UseLocal) {
2405 }
2406 }
2407
2408
2409 if (FoundDirect) {
2411 continue;
2412 }
2413
2415 NamespaceDecl *Nom = I->getNominatedNamespace();
2416 if (S.isVisible(I) && Visited.insert(Nom).second)
2417 Queue.push_back(Nom);
2418 }
2419 }
2420
2422 if (FoundTag && FoundNonTag)
2424 else
2426 }
2427
2429}
2430
2432 bool InUnqualifiedLookup) {
2433 assert(LookupCtx && "Sema::LookupQualifiedName requires a lookup context");
2434
2436 return false;
2437
2438#ifndef NDEBUG
2439
2440 if (const auto *TD = dyn_cast(LookupCtx);
2441 TD && !TD->isDependentType() && TD->getDefinition() == nullptr)
2442 llvm_unreachable("Declaration context must already be complete!");
2443#endif
2444
2445 struct QualifiedLookupInScope {
2446 bool oldVal;
2448
2449 QualifiedLookupInScope(DeclContext *ctx)
2452 }
2453 ~QualifiedLookupInScope() {
2454 Context->setUseQualifiedLookup(oldVal);
2455 }
2456 } QL(LookupCtx);
2457
2458 CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
2459
2460
2461
2463
2464
2465
2466
2467
2468
2469
2470
2475 return false;
2476 }
2477 }
2478
2481 if (LookupRec)
2483 return true;
2484 }
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2496 return false;
2497
2498
2501
2502
2503
2505 return false;
2506
2507
2512 return false;
2513
2514
2515
2516
2517
2518
2522 return false;
2523 }
2524
2525
2526
2529
2530
2531 auto BaseCallback = [Name, IDNS](const CXXBaseSpecifier *Specifier,
2533 CXXRecordDecl *BaseRecord = Specifier->getType()->getAsCXXRecordDecl();
2534
2535
2536 for (Path.Decls = BaseRecord->lookup(Name).begin();
2537 Path.Decls != Path.Decls.end(); ++Path.Decls) {
2538 if ((*Path.Decls)->isInIdentifierNamespace(IDNS))
2539 return true;
2540 }
2541 return false;
2542 };
2543
2546 if (!LookupRec->lookupInBases(BaseCallback, Paths))
2547 return false;
2548
2550
2551
2552
2553
2554
2555
2556
2558 int SubobjectNumber = 0;
2560
2561
2564 if ((*I)->isInIdentifierNamespace(IDNS) && (*I)->isCXXInstanceMember())
2565 return false;
2566 return true;
2567 };
2568
2570
2571
2572
2576 using Result = const void *;
2577
2578 auto Next = [&](Iterator &It, Iterator End) -> Result {
2579 while (It != End) {
2582 continue;
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592 if (TemplateNameLookup)
2594 ND = TD;
2595
2596
2597
2598
2600 return Context.getCanonicalTypeDeclType(TD).getAsOpaquePtr();
2601
2603 }
2604 return nullptr;
2605 };
2606
2607
2608
2609 Iterator AIt = A, BIt = B, AEnd, BEnd;
2610 while (true) {
2613 if (!AResult && !BResult)
2614 return true;
2615 if (!AResult || !BResult)
2616 return false;
2617 if (AResult != BResult) {
2618
2619
2620 llvm::SmallDenseMap<Result, bool, 32> AResults;
2621 for (; AResult; AResult = Next(AIt, AEnd))
2622 AResults.insert({AResult, false});
2623 unsigned Found = 0;
2624 for (; BResult; BResult = Next(BIt, BEnd)) {
2625 auto It = AResults.find(BResult);
2626 if (It == AResults.end())
2627 return false;
2628 if (!It->second) {
2629 It->second = true;
2631 }
2632 }
2633 return AResults.size() == Found;
2634 }
2635 }
2636 };
2637
2639 Path != PathEnd; ++Path) {
2641
2642
2643
2644 SubobjectAccess = std::min(SubobjectAccess, Path->Access);
2645
2646
2647 if (SubobjectType.isNull()) {
2648
2649 SubobjectType = Context.getCanonicalType(PathElement.Base->getType());
2651 continue;
2652 }
2653
2654 if (SubobjectType !=
2656
2657
2658
2659
2660
2661
2662 if (HasOnlyStaticMembers(Path->Decls) &&
2663 HasSameDeclarations(Paths.begin()->Decls, Path->Decls))
2664 continue;
2665
2667 return true;
2668 }
2669
2670
2671
2672
2674
2675
2676
2677
2678
2679
2680 if (HasOnlyStaticMembers(Path->Decls))
2681 continue;
2682
2683
2684
2686 return true;
2687 }
2688 }
2689
2690
2691
2693 I != E; ++I) {
2695 (*I)->getAccess());
2698 }
2700 return true;
2701}
2702
2707 return LookupInSuper(R, Qualifier.getAsMicrosoftSuper());
2709}
2710
2712 QualType ObjectType, bool AllowBuiltinCreation,
2713 bool EnteringContext) {
2714
2716 return false;
2717
2718
2720 bool IsDependent = false;
2721 if (!ObjectType.isNull()) {
2722
2723
2724 assert((!SS || SS->isEmpty()) &&
2725 "ObjectType and scope specifier cannot coexist");
2730 ObjectType->castAs()->getDecl()->isEntityBeingDefined()) &&
2731 "Caller should have completed object type");
2732 } else if (SS && SS->isNotEmpty()) {
2733
2734
2736
2738 return false;
2740
2741
2742
2745 return LookupInSuper(R, Qualifier.getAsMicrosoftSuper());
2746 }
2748 } else {
2749
2750 return LookupName(R, S, AllowBuiltinCreation);
2751 }
2752
2753
2754
2755 if (DC)
2757 else if (IsDependent)
2758
2759
2760
2762 return false;
2763}
2764
2766
2767
2768
2769
2770 for (const auto &BaseSpec : Class->bases()) {
2771 auto *RD = BaseSpec.getType()->castAsCXXRecordDecl();
2775
2776
2777
2778 for (auto I = Result.begin(), E = Result.end(); I != E; ++I) {
2781 I.getAccess()));
2782 }
2783
2784 Result.suppressDiagnostics();
2785 }
2786
2789
2790 return !R.empty();
2791}
2792
2794 assert(Result.isAmbiguous() && "Lookup result must be ambiguous");
2795
2799
2800 switch (Result.getAmbiguityKind()) {
2803 QualType SubobjectType = Paths->front().back().Base->getType();
2804 Diag(NameLoc, diag::err_ambiguous_member_multiple_subobjects)
2806 << LookupRange;
2807
2812
2813 Diag((*Found)->getLocation(), diag::note_ambiguous_member_found);
2814 break;
2815 }
2816
2818 Diag(NameLoc, diag::err_ambiguous_member_multiple_subobject_types)
2819 << Name << LookupRange;
2820
2822 std::set<const NamedDecl *> DeclsPrinted;
2824 PathEnd = Paths->end();
2825 Path != PathEnd; ++Path) {
2826 const NamedDecl *D = *Path->Decls;
2828 continue;
2829 if (DeclsPrinted.insert(D).second) {
2830 if (const auto *TD = dyn_cast(D->getUnderlyingDecl()))
2831 Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
2832 << TD->getUnderlyingType();
2833 else if (const auto *TD = dyn_cast(D->getUnderlyingDecl()))
2834 Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
2835 << Context.getTypeDeclType(TD);
2836 else
2837 Diag(D->getLocation(), diag::note_ambiguous_member_found);
2838 }
2839 }
2840 break;
2841 }
2842
2844 Diag(NameLoc, diag::err_ambiguous_tag_hiding) << Name << LookupRange;
2845
2847
2848 for (auto *D : Result)
2849 if (TagDecl *TD = dyn_cast(D)) {
2850 TagDecls.insert(TD);
2851 Diag(TD->getLocation(), diag::note_hidden_tag);
2852 }
2853
2854 for (auto *D : Result)
2857
2858
2861 if (TagDecls.count(F.next()))
2863 }
2865 break;
2866 }
2867
2869 Diag(NameLoc, diag::err_using_placeholder_variable) << Name << LookupRange;
2871 for (auto *D : Result) {
2872 Diag(D->getLocation(), diag::note_reference_placeholder) << D;
2874 break;
2876 }
2877 break;
2878 }
2879
2881 Diag(NameLoc, diag::err_ambiguous_reference) << Name << LookupRange;
2882
2883 for (auto *D : Result)
2884 Diag(D->getLocation(), diag::note_ambiguous_candidate) << D;
2885 break;
2886 }
2887 }
2888}
2889
2890namespace {
2891 struct AssociatedLookup {
2895 : S(S), Namespaces(Namespaces), Classes(Classes),
2896 InstantiationLoc(InstantiationLoc) {
2897 }
2898
2900 Classes.insert(RD);
2901 return ClassesTransitive.insert(RD);
2902 }
2903
2904 Sema &S;
2907 SourceLocation InstantiationLoc;
2908
2909 private:
2911 };
2912}
2913
2914static void
2916
2917
2918
2919
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2939
2940
2941
2942
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2988 Namespaces.insert(Ctx);
2989 else
2990 Namespaces.insert(PrimaryCtx);
2991}
2992
2993
2994
2995static void
2998
2999
3000 switch (Arg.getKind()) {
3002 break;
3003
3005
3006
3007
3009 break;
3010
3013
3014
3015
3018 = dyn_cast(Template.getAsTemplateDecl())) {
3019 DeclContext *Ctx = ClassTemplate->getDeclContext();
3020 if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
3021 Result.Classes.insert(EnclosingClass);
3022
3024 }
3025 break;
3026 }
3027
3033
3034
3035 break;
3036
3040 break;
3041 }
3042}
3043
3044
3045
3046static void
3049
3050
3051 if (Class->getDeclName() == Result.S.VAListTagName)
3052 return;
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063 DeclContext *Ctx = Class->getDeclContext();
3064 if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
3065 Result.Classes.insert(EnclosingClass);
3066
3067
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3080 = dyn_cast(Class)) {
3081 DeclContext *Ctx = Spec->getSpecializedTemplate()->getDeclContext();
3082 if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
3083 Result.Classes.insert(EnclosingClass);
3084
3086
3088 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
3090 }
3091
3092
3093
3094 if (!Result.addClassTransitive(Class))
3095 return;
3096
3097
3098 if (!Result.S.isCompleteType(Result.InstantiationLoc,
3099 Result.S.Context.getCanonicalTagType(Class)))
3100 return;
3101
3102
3103
3105 Bases.push_back(Class);
3106 while (!Bases.empty()) {
3107
3108 Class = Bases.pop_back_val();
3109
3110
3111 for (const auto &Base : Class->bases()) {
3113
3114
3115
3116
3117
3118
3119 if (!BaseDecl)
3120 continue;
3121 if (Result.addClassTransitive(BaseDecl)) {
3122
3125
3126
3127 if (!BaseDecl->bases().empty())
3128 Bases.push_back(BaseDecl);
3129 }
3130 }
3131 }
3132}
3133
3134
3135
3136
3137static void
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3152
3153 while (true) {
3154 switch (T->getTypeClass()) {
3155
3156#define TYPE(Class, Base)
3157#define DEPENDENT_TYPE(Class, Base) case Type::Class:
3158#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3159#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
3160#define ABSTRACT_TYPE(Class, Base)
3161#include "clang/AST/TypeNodes.inc"
3162
3163
3164
3165
3166
3167 break;
3168
3169
3170
3171 case Type::Pointer:
3173 continue;
3174 case Type::ConstantArray:
3175 case Type::IncompleteArray:
3176 case Type::VariableArray:
3178 continue;
3179
3180
3181
3182 case Type::Builtin:
3183 break;
3184
3185
3186
3187
3188
3189
3190 case Type::Record: {
3191
3193 ->getDefinitionOrSelf();
3195 break;
3196 }
3197
3198
3199
3200
3201
3202 case Type::Enum: {
3203
3204 auto *Enum = T->castAsEnumDecl();
3205
3207 if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
3208 Result.Classes.insert(EnclosingClass);
3209
3210
3212
3213 break;
3214 }
3215
3216
3217
3218
3219 case Type::FunctionProto: {
3221 for (const auto &Arg : Proto->param_types())
3222 Queue.push_back(Arg.getTypePtr());
3223
3224 [[fallthrough]];
3225 }
3226 case Type::FunctionNoProto: {
3229 continue;
3230 }
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241 case Type::MemberPointer: {
3243 if (CXXRecordDecl *Class = MemberPtr->getMostRecentCXXRecordDecl())
3245 T = MemberPtr->getPointeeType().getTypePtr();
3246 continue;
3247 }
3248
3249
3250 case Type::BlockPointer:
3252 continue;
3253
3254
3255
3256 case Type::LValueReference:
3257 case Type::RValueReference:
3259 continue;
3260
3261
3262 case Type::Vector:
3263 case Type::ExtVector:
3264 case Type::ConstantMatrix:
3265 case Type::Complex:
3266 case Type::BitInt:
3267 break;
3268
3269
3270 case Type::Auto:
3271 case Type::DeducedTemplateSpecialization:
3272 break;
3273
3274
3275
3276
3277 case Type::ObjCObject:
3278 case Type::ObjCInterface:
3279 case Type::ObjCObjectPointer:
3280 Result.Namespaces.insert(Result.S.Context.getTranslationUnitDecl());
3281 break;
3282
3283
3284
3285 case Type::Atomic:
3287 continue;
3288 case Type::Pipe:
3290 continue;
3291
3292
3293 case Type::ArrayParameter:
3294 break;
3295
3296 case Type::HLSLAttributedResource:
3298 break;
3299
3300
3301 case Type::HLSLInlineSpirv:
3302 break;
3303 }
3304
3305 if (Queue.empty())
3306 break;
3307 T = Queue.pop_back_val();
3308 }
3309}
3310
3315 AssociatedNamespaces.clear();
3316 AssociatedClasses.clear();
3317
3318 AssociatedLookup Result(*this, InstantiationLoc,
3319 AssociatedNamespaces, AssociatedClasses);
3320
3321
3322
3323
3324
3325
3326
3327
3328 for (unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) {
3329 Expr *Arg = Args[ArgIdx];
3330
3333 continue;
3334 }
3335
3336
3337
3338
3339
3340
3341
3342
3344
3346
3348
3349
3350
3352 }
3353 }
3354}
3355
3360 LookupResult R(*this, Name, Loc, NameKind, Redecl);
3363}
3364
3367
3368
3369
3370
3371
3372
3376
3377 assert(!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous");
3378 Functions.append(Operators.begin(), Operators.end());
3379}
3380
3383 bool ConstArg, bool VolatileArg, bool RValueThis,
3384 bool ConstThis, bool VolatileThis) {
3386 "doing special member lookup into record that isn't fully complete");
3388 if (RValueThis || ConstThis || VolatileThis)
3391 "constructors and destructors always have unqualified lvalue this");
3392 if (ConstArg || VolatileArg)
3395 "parameter-less special members can't have qualified arguments");
3396
3397
3399
3400 llvm::FoldingSetNodeID ID;
3401 ID.AddPointer(RD);
3402 ID.AddInteger(llvm::to_underlying(SM));
3403 ID.AddInteger(ConstArg);
3404 ID.AddInteger(VolatileArg);
3405 ID.AddInteger(RValueThis);
3406 ID.AddInteger(ConstThis);
3407 ID.AddInteger(VolatileThis);
3408
3409 void *InsertPoint;
3412
3413
3416
3420
3424 DeclareImplicitDestructor(RD);
3425 });
3426 }
3428 Result->setMethod(DD);
3433 }
3434
3435
3436
3439 Expr *Arg = nullptr;
3440 unsigned NumArgs;
3441
3444
3446 Name = Context.DeclarationNames.getCXXConstructorName(CanTy);
3447 NumArgs = 0;
3450 DeclareImplicitDefaultConstructor(RD);
3451 });
3452 }
3453 } else {
3456 Name = Context.DeclarationNames.getCXXConstructorName(CanTy);
3459 DeclareImplicitCopyConstructor(RD);
3460 });
3461 }
3464 DeclareImplicitMoveConstructor(RD);
3465 });
3466 }
3467 } else {
3468 Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal);
3471 DeclareImplicitCopyAssignment(RD);
3472 });
3473 }
3476 DeclareImplicitMoveAssignment(RD);
3477 });
3478 }
3479 }
3480
3481 if (ConstArg)
3483 if (VolatileArg)
3485
3486
3487
3488
3489
3490
3491
3492
3496 else
3498 }
3499
3501
3503 NumArgs = 1;
3504 Arg = &FakeArg;
3505 }
3506
3507
3509 if (ConstThis)
3511 if (VolatileThis)
3516
3517
3518
3519
3522
3523 if (R.empty()) {
3524
3525
3526
3527
3529 "lookup for a constructor or assignment operator was empty");
3530 Result->setMethod(nullptr);
3533 }
3534
3535
3536
3538
3539 for (NamedDecl *CandDecl : Candidates) {
3540 if (CandDecl->isInvalidDecl())
3541 continue;
3542
3550 else if (CtorInfo)
3553 true);
3554 else
3556 true);
3562 Classification,
3564 else if (CtorInfo)
3566 CtorInfo.FoundDecl, nullptr,
3568 else
3571 } else {
3573 "illegal Kind of operator = Decl");
3574 }
3575 }
3576
3582 break;
3583
3587 break;
3588
3590 Result->setMethod(nullptr);
3592 break;
3593
3595 Result->setMethod(nullptr);
3597 break;
3598 }
3599
3601}
3602
3606 false, false, false, false, false);
3607
3608 return cast_or_null(Result.getMethod());
3609}
3610
3612 unsigned Quals) {
3614 "non-const, non-volatile qualifiers for copy ctor arg");
3618
3619 return cast_or_null(Result.getMethod());
3620}
3621
3623 unsigned Quals) {
3627
3628 return cast_or_null(Result.getMethod());
3629}
3630
3632
3635 if (Class->needsImplicitDefaultConstructor())
3636 DeclareImplicitDefaultConstructor(Class);
3637 if (Class->needsImplicitCopyConstructor())
3638 DeclareImplicitCopyConstructor(Class);
3639 if (getLangOpts().CPlusPlus11 && Class->needsImplicitMoveConstructor())
3640 DeclareImplicitMoveConstructor(Class);
3641 });
3642 }
3643
3646 return Class->lookup(Name);
3647}
3648
3650 unsigned Quals, bool RValueThis,
3651 unsigned ThisQuals) {
3653 "non-const, non-volatile qualifiers for copy assignment arg");
3655 "non-const, non-volatile qualifiers for copy assignment this");
3660
3661 return Result.getMethod();
3662}
3663
3665 unsigned Quals,
3666 bool RValueThis,
3667 unsigned ThisQuals) {
3669 "non-const, non-volatile qualifiers for copy assignment this");
3674
3675 return Result.getMethod();
3676}
3677
3679 return cast_or_null(
3681 false, false, false)
3682 .getMethod());
3683}
3684
3688 bool AllowTemplate, bool AllowStringTemplatePack,
3689 bool DiagnoseMissing, StringLiteral *StringLit) {
3692 "literal operator lookup can't be ambiguous");
3693
3694
3696
3697 bool AllowCooked = true;
3698 bool FoundRaw = false;
3699 bool FoundTemplate = false;
3700 bool FoundStringTemplatePack = false;
3701 bool FoundCooked = false;
3702
3705 if (UsingShadowDecl *USD = dyn_cast(D))
3706 D = USD->getTargetDecl();
3707
3708
3711 continue;
3712 }
3713
3714 bool IsRaw = false;
3715 bool IsTemplate = false;
3716 bool IsStringTemplatePack = false;
3717 bool IsCooked = false;
3718
3719 if (FunctionDecl *FD = dyn_cast(D)) {
3720 if (FD->getNumParams() == 1 &&
3721 FD->getParamDecl(0)->getType()->getAs<PointerType>())
3722 IsRaw = true;
3723 else if (FD->getNumParams() == ArgTys.size()) {
3724 IsCooked = true;
3725 for (unsigned ArgIdx = 0; ArgIdx != ArgTys.size(); ++ArgIdx) {
3726 QualType ParamTy = FD->getParamDecl(ArgIdx)->getType();
3727 if (.hasSameUnqualifiedType(ArgTys[ArgIdx], ParamTy)) {
3728 IsCooked = false;
3729 break;
3730 }
3731 }
3732 }
3733 }
3736 if (Params->size() == 1) {
3737 IsTemplate = true;
3739
3740
3741
3743 continue;
3744 }
3745
3746
3747
3748 if (StringLit) {
3752 TemplateArgument(StringLit, false), StringLit);
3757 IsTemplate = false;
3758 }
3759 } else {
3760 IsStringTemplatePack = true;
3761 }
3762 }
3763
3764 if (AllowTemplate && StringLit && IsTemplate) {
3765 FoundTemplate = true;
3766 AllowRaw = false;
3767 AllowCooked = false;
3768 AllowStringTemplatePack = false;
3769 if (FoundRaw || FoundCooked || FoundStringTemplatePack) {
3771 FoundRaw = FoundCooked = FoundStringTemplatePack = false;
3772 }
3773 } else if (AllowCooked && IsCooked) {
3774 FoundCooked = true;
3775 AllowRaw = false;
3776 AllowTemplate = StringLit;
3777 AllowStringTemplatePack = false;
3778 if (FoundRaw || FoundTemplate || FoundStringTemplatePack) {
3779
3780
3782 FoundRaw = FoundTemplate = FoundStringTemplatePack = false;
3783 }
3784 } else if (AllowRaw && IsRaw) {
3785 FoundRaw = true;
3786 } else if (AllowTemplate && IsTemplate) {
3787 FoundTemplate = true;
3788 } else if (AllowStringTemplatePack && IsStringTemplatePack) {
3789 FoundStringTemplatePack = true;
3790 } else {
3792 }
3793 }
3794
3796
3797
3798
3799 if (StringLit && FoundTemplate)
3801
3802
3803
3804
3805 if (FoundCooked)
3807
3808
3809
3810 if (FoundRaw && FoundTemplate) {
3815 }
3816
3817 if (FoundRaw)
3819
3820 if (FoundTemplate)
3822
3823 if (FoundStringTemplatePack)
3825
3826
3827 if (DiagnoseMissing) {
3828 Diag(R.getNameLoc(), diag::err_ovl_no_viable_literal_operator)
3829 << R.getLookupName() << (int)ArgTys.size() << ArgTys[0]
3830 << (ArgTys.size() == 2 ? ArgTys[1] : QualType()) << AllowRaw
3831 << (AllowTemplate || AllowStringTemplatePack);
3833 }
3834
3836}
3837
3840
3841
3842
3843 if (Old == nullptr || Old == New) {
3844 Old = New;
3845 return;
3846 }
3847
3848
3851
3853 while (true) {
3854 Cursor = Cursor->getPreviousDecl();
3855
3856
3857
3858 if (!Cursor) return;
3859
3860
3861 if (Cursor == OldFD) break;
3862
3863
3864 }
3865
3866 Old = New;
3867}
3868
3871
3872
3876 AssociatedNamespaces,
3877 AssociatedClasses);
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890 for (auto *NS : AssociatedNamespaces) {
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3909 for (auto *D : R) {
3910 auto *Underlying = D;
3911 if (auto *USD = dyn_cast(D))
3912 Underlying = USD->getTargetDecl();
3913
3916 continue;
3917
3918
3919
3920
3927 break;
3928 }
3929
3932 continue;
3933
3936
3937
3938
3939
3940 assert(FM &&
3943
3944
3946 llvm::any_of(AssociatedClasses, [&](auto *E) {
3947
3948
3949
3950 if (E->getOwningModule() != FM)
3951 return false;
3952
3953
3954 DeclContext *Ctx = E->getDeclContext();
3955 while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
3956 Ctx = Ctx->getParent();
3957 return Ctx == NS;
3958 })) {
3960 break;
3961 }
3962 }
3963 }
3964
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976 if (AssociatedClasses.count(RD) && isReachable(D)) {
3978 break;
3979 }
3980 }
3981 }
3982
3983
3985 Result.insert(Underlying);
3986 }
3987 }
3988}
3989
3990
3991
3992
3994
3996
3997namespace {
3998
3999class ShadowContextRAII;
4000
4001class VisibleDeclsRecord {
4002public:
4003
4004
4005
4006 typedef llvm::TinyPtrVector<NamedDecl*> ShadowMapEntry;
4007
4008private:
4009
4010
4011 typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap;
4012
4013
4014 std::list ShadowMaps;
4015
4016
4018
4019 friend class ShadowContextRAII;
4020
4021public:
4022
4023
4025 return !VisitedContexts.insert(Ctx).second;
4026 }
4027
4028 bool alreadyVisitedContext(DeclContext *Ctx) {
4029 return VisitedContexts.count(Ctx);
4030 }
4031
4032
4033
4034
4035
4036
4037 NamedDecl *checkHidden(NamedDecl *ND);
4038
4039
4040 void add(NamedDecl *ND) {
4041 ShadowMaps.back()[ND->getDeclName()].push_back(ND);
4042 }
4043};
4044
4045
4046class ShadowContextRAII {
4047 VisibleDeclsRecord &Visible;
4048
4049 typedef VisibleDeclsRecord::ShadowMap ShadowMap;
4050
4051public:
4052 ShadowContextRAII(VisibleDeclsRecord &Visible) : Visible(Visible) {
4053 Visible.ShadowMaps.emplace_back();
4054 }
4055
4056 ~ShadowContextRAII() {
4057 Visible.ShadowMaps.pop_back();
4058 }
4059};
4060
4061}
4062
4065 std::list::reverse_iterator SM = ShadowMaps.rbegin();
4066 for (std::list::reverse_iterator SMEnd = ShadowMaps.rend();
4068 ShadowMap::iterator Pos = SM->find(ND->getDeclName());
4069 if (Pos == SM->end())
4070 continue;
4071
4072 for (auto *D : Pos->second) {
4073
4077 continue;
4078
4079
4083 continue;
4084
4085
4086
4087
4090 SM == ShadowMaps.rbegin())
4091 continue;
4092
4093
4094
4097 continue;
4098
4099
4100 return D;
4101 }
4102 }
4103
4104 return nullptr;
4105}
4106
4107namespace {
4108class LookupVisibleHelper {
4109public:
4110 LookupVisibleHelper(VisibleDeclConsumer &Consumer, bool IncludeDependentBases,
4111 bool LoadExternal)
4112 : Consumer(Consumer), IncludeDependentBases(IncludeDependentBases),
4113 LoadExternal(LoadExternal) {}
4114
4116 bool IncludeGlobalScope) {
4117
4118
4119 Scope *Initial = S;
4120 UnqualUsingDirectiveSet UDirs(SemaRef);
4122
4125
4126 UDirs.visitScopeChain(Initial, S);
4127 }
4128 UDirs.done();
4129
4130
4131 LookupResult Result(SemaRef, DeclarationName(), SourceLocation(), Kind);
4132 Result.setAllowHidden(Consumer.includeHiddenDecls());
4133 if (!IncludeGlobalScope)
4135 ShadowContextRAII Shadow(Visited);
4136 lookupInScope(Initial, Result, UDirs);
4137 }
4138
4139 void lookupVisibleDecls(Sema &SemaRef, DeclContext *Ctx,
4141 LookupResult Result(SemaRef, DeclarationName(), SourceLocation(), Kind);
4142 Result.setAllowHidden(Consumer.includeHiddenDecls());
4143 if (!IncludeGlobalScope)
4145
4146 ShadowContextRAII Shadow(Visited);
4147 lookupInDeclContext(Ctx, Result, true,
4148 false);
4149 }
4150
4151private:
4152 void lookupInDeclContext(DeclContext *Ctx, LookupResult &Result,
4153 bool QualifiedNameLookup, bool InBaseClass) {
4154 if (!Ctx)
4155 return;
4156
4157
4159 return;
4160
4161 Consumer.EnteredContext(Ctx);
4162
4163
4165 .getSema().getLangOpts().CPlusPlus) {
4166 auto &S = Result.getSema();
4167 auto &Idents = S.Context.Idents;
4168
4169
4170 if (LoadExternal)
4171 if (IdentifierInfoLookup *External =
4172 Idents.getExternalIdentifierLookup()) {
4173 std::unique_ptr Iter(External->getIdentifiers());
4174 for (StringRef Name = Iter->Next(); !Name.empty();
4175 Name = Iter->Next())
4176 Idents.get(Name);
4177 }
4178
4179
4180 for (const auto &Ident : Idents) {
4181 for (auto I = S.IdResolver.begin(Ident.getValue()),
4182 E = S.IdResolver.end();
4183 I != E; ++I) {
4184 if (S.IdResolver.isDeclInScope(*I, Ctx)) {
4185 if (NamedDecl *ND = Result.getAcceptableDecl(*I)) {
4186 Consumer.FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass);
4187 Visited.add(ND);
4188 }
4189 }
4190 }
4191 }
4192
4193 return;
4194 }
4195
4196 if (CXXRecordDecl *Class = dyn_cast(Ctx))
4197 Result.getSema().ForceDeclarationOfImplicitMembers(Class);
4198
4199 llvm::SmallVector<NamedDecl *, 4> DeclsToVisit;
4200
4201 bool Load = LoadExternal ||
4203
4204 for (DeclContextLookupResult R :
4206 : Ctx->noload_lookups(false))
4207 for (auto *D : R)
4208
4209
4210
4211
4212
4213 DeclsToVisit.push_back(D);
4214
4215 for (auto *D : DeclsToVisit)
4216 if (auto *ND = Result.getAcceptableDecl(D)) {
4217 Consumer.FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass);
4218 Visited.add(ND);
4219 }
4220
4221 DeclsToVisit.clear();
4222
4223
4224 if (QualifiedNameLookup) {
4225 ShadowContextRAII Shadow(Visited);
4227 if (.getSema().isVisible(I))
4228 continue;
4229 lookupInDeclContext(I->getNominatedNamespace(), Result,
4230 QualifiedNameLookup, InBaseClass);
4231 }
4232 }
4233
4234
4235 if (CXXRecordDecl *Record = dyn_cast(Ctx)) {
4236 if (->hasDefinition())
4237 return;
4238
4239 for (const auto &B : Record->bases()) {
4240 QualType BaseType = B.getType();
4241
4242 RecordDecl *RD;
4244 if (!IncludeDependentBases) {
4245
4246
4247 continue;
4248 }
4249 const auto *TST = BaseType->getAs();
4250 if (!TST)
4251 continue;
4253 const auto *TD =
4255 if (!TD)
4256 continue;
4257 RD = TD->getTemplatedDecl();
4258 } else {
4260 if (!RD)
4261 continue;
4262 }
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284 ShadowContextRAII Shadow(Visited);
4285 lookupInDeclContext(RD, Result, QualifiedNameLookup,
4286 true);
4287 }
4288 }
4289
4290
4291 if (ObjCInterfaceDecl *IFace = dyn_cast(Ctx)) {
4292
4293 for (auto *Cat : IFace->visible_categories()) {
4294 ShadowContextRAII Shadow(Visited);
4295 lookupInDeclContext(Cat, Result, QualifiedNameLookup,
4296 false);
4297 }
4298
4299
4300 for (auto *I : IFace->all_referenced_protocols()) {
4301 ShadowContextRAII Shadow(Visited);
4302 lookupInDeclContext(I, Result, QualifiedNameLookup,
4303 false);
4304 }
4305
4306
4307 if (IFace->getSuperClass()) {
4308 ShadowContextRAII Shadow(Visited);
4309 lookupInDeclContext(IFace->getSuperClass(), Result, QualifiedNameLookup,
4310 true);
4311 }
4312
4313
4314
4315 if (IFace->getImplementation()) {
4316 ShadowContextRAII Shadow(Visited);
4317 lookupInDeclContext(IFace->getImplementation(), Result,
4318 QualifiedNameLookup, InBaseClass);
4319 }
4320 } else if (ObjCProtocolDecl *Protocol = dyn_cast(Ctx)) {
4321 for (auto *I : Protocol->protocols()) {
4322 ShadowContextRAII Shadow(Visited);
4323 lookupInDeclContext(I, Result, QualifiedNameLookup,
4324 false);
4325 }
4326 } else if (ObjCCategoryDecl *Category = dyn_cast(Ctx)) {
4327 for (auto *I : Category->protocols()) {
4328 ShadowContextRAII Shadow(Visited);
4329 lookupInDeclContext(I, Result, QualifiedNameLookup,
4330 false);
4331 }
4332
4333
4334 if (Category->getImplementation()) {
4335 ShadowContextRAII Shadow(Visited);
4336 lookupInDeclContext(Category->getImplementation(), Result,
4337 QualifiedNameLookup, true);
4338 }
4339 }
4340 }
4341
4342 void lookupInScope(Scope *S, LookupResult &Result,
4343 UnqualUsingDirectiveSet &UDirs) {
4344
4345
4346 assert(!IncludeDependentBases && "Unsupported flag for lookupInScope");
4347
4348 if (!S)
4349 return;
4350
4352 (!S->getParent() && !Visited.alreadyVisitedContext(S->getEntity())) ||
4354 FindLocalExternScope FindLocals(Result);
4355
4356
4357 SmallVector<Decl *, 8> ScopeDecls(S->decls().begin(), S->decls().end());
4358 for (Decl *D : ScopeDecls) {
4359 if (NamedDecl *ND = dyn_cast(D))
4360 if ((ND = Result.getAcceptableDecl(ND))) {
4361 Consumer.FoundDecl(ND, Visited.checkHidden(ND), nullptr, false);
4362 Visited.add(ND);
4363 }
4364 }
4365 }
4366
4368 if (Entity) {
4369
4370
4371
4373
4374 for (DeclContext *Ctx = Entity; Ctx && !Ctx->Equals(OuterCtx);
4376 if (ObjCMethodDecl *Method = dyn_cast(Ctx)) {
4377 if (Method->isInstanceMethod()) {
4378
4379 LookupResult IvarResult(Result.getSema(), Result.getLookupName(),
4380 Result.getNameLoc(),
4382 if (ObjCInterfaceDecl *IFace = Method->getClassInterface()) {
4383 lookupInDeclContext(IFace, IvarResult,
4384 false,
4385 false);
4386 }
4387 }
4388
4389
4390
4391
4392 break;
4393 }
4394
4396 continue;
4397
4398 lookupInDeclContext(Ctx, Result, false,
4399 false);
4400 }
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412 Entity = Result.getSema().Context.getTranslationUnitDecl();
4413 lookupInDeclContext(Entity, Result, false,
4414 false);
4415 }
4416
4417 if (Entity) {
4418
4419
4420 for (const UnqualUsingEntry &UUE : UDirs.getNamespacesFor(Entity))
4421 lookupInDeclContext(
4422 const_cast<DeclContext *>(UUE.getNominatedNamespace()), Result,
4423 false,
4424 false);
4425 }
4426
4427
4428 ShadowContextRAII Shadow(Visited);
4430 }
4431
4432private:
4433 VisibleDeclsRecord Visited;
4434 VisibleDeclConsumer &Consumer;
4435 bool IncludeDependentBases;
4436 bool LoadExternal;
4437};
4438}
4439
4442 bool IncludeGlobalScope, bool LoadExternal) {
4443 LookupVisibleHelper H(Consumer, false,
4444 LoadExternal);
4445 H.lookupVisibleDecls(*this, S, Kind, IncludeGlobalScope);
4446}
4447
4450 bool IncludeGlobalScope,
4451 bool IncludeDependentBases, bool LoadExternal) {
4452 LookupVisibleHelper H(Consumer, IncludeDependentBases, LoadExternal);
4453 H.lookupVisibleDecls(*this, Ctx, Kind, IncludeGlobalScope);
4454}
4455
4459
4460
4462 return nullptr;
4464}
4465
4468 if (GnuLabelLoc.isValid()) {
4469
4471 Scope *S = CurScope;
4474 }
4475
4476
4478 if (!Res) {
4479
4482 assert(S && "Not in a function?");
4484 }
4485 return Res;
4486}
4487
4488
4489
4490
4491
4497
4503 bool EnteringContext,
4504 bool isObjCIvarLookup,
4505 bool FindHidden);
4506
4507
4508
4509
4512
4513 for (; DI != DE; ++DI)
4515 break;
4516
4517 if (DI == DE) {
4519 return;
4520 }
4521
4523 bool AnyVisibleDecls = !NewDecls.empty();
4524
4525 for (; DI != DE; ++DI) {
4527 if (!AnyVisibleDecls) {
4528
4529 AnyVisibleDecls = true;
4530 NewDecls.clear();
4531 }
4532 NewDecls.push_back(*DI);
4533 } else if (!AnyVisibleDecls && !(*DI)->isModulePrivate())
4534 NewDecls.push_back(*DI);
4535 }
4536
4537 if (NewDecls.empty())
4539 else {
4542 }
4543}
4544
4545
4546
4547
4551 switch (NNS.getKind()) {
4553 Identifiers.clear();
4554 return;
4555
4559 if (const auto *NS = dyn_cast(Namespace);
4560 NS && NS->isAnonymousNamespace())
4561 return;
4562 Identifiers.push_back(Namespace->getIdentifier());
4563 return;
4564 }
4565
4568 switch (T->getTypeClass()) {
4569 case Type::DependentName: {
4572 Identifiers.push_back(DT->getIdentifier());
4573 return;
4574 }
4575 case Type::TemplateSpecialization: {
4581 if (const auto *II = DTN->getName().getIdentifier())
4582 Identifiers.push_back(II);
4583 return;
4584 }
4588 Name = QTN->getUnderlyingTemplate();
4589 }
4590 if (const auto *TD = Name.getAsTemplateDecl(true))
4591 Identifiers.push_back(TD->getIdentifier());
4592 return;
4593 }
4594 case Type::SubstTemplateTypeParm:
4596 ->getReplacementType()
4597 .getTypePtr();
4598 continue;
4599 case Type::TemplateTypeParm:
4601 return;
4602 case Type::Decltype:
4603 return;
4604 case Type::Enum:
4605 case Type::Record:
4606 case Type::InjectedClassName: {
4609 Identifiers.push_back(TT->getDecl()->getIdentifier());
4610 return;
4611 }
4612 case Type::Typedef: {
4615 Identifiers.push_back(TT->getDecl()->getIdentifier());
4616 return;
4617 }
4618 case Type::Using: {
4621 Identifiers.push_back(TT->getDecl()->getIdentifier());
4622 return;
4623 }
4624 case Type::UnresolvedUsing: {
4627 Identifiers.push_back(TT->getDecl()->getIdentifier());
4628 return;
4629 }
4630 default:
4631 Identifiers.push_back(QualType(T, 0).getBaseTypeIdentifier());
4632 return;
4633 }
4634 }
4635 break;
4636 }
4637
4640 return;
4641 }
4642}
4643
4646
4647 if (Hiding)
4648 return;
4649
4650
4651
4652
4654 if (!Name)
4655 return;
4656
4657
4658
4660 return;
4661
4663}
4664
4666
4667
4668 addName(Name, nullptr);
4669}
4670
4672
4673
4674 addName(Keyword, nullptr, std::nullopt, true);
4675}
4676
4677void TypoCorrectionConsumer::addName(StringRef Name, NamedDecl *ND,
4679
4680
4681 StringRef TypoStr = Typo->getName();
4682 unsigned MinED = abs((int)Name.size() - (int)TypoStr.size());
4683 if (MinED && TypoStr.size() / MinED < 3)
4684 return;
4685
4686
4687
4688 unsigned UpperBound = (TypoStr.size() + 2) / 3;
4689 unsigned ED = TypoStr.edit_distance(Name, true, UpperBound);
4690 if (ED > UpperBound) return;
4691
4693 if (isKeyword) TC.makeKeyword();
4694 TC.setCorrectionRange(nullptr, Result.getLookupNameInfo());
4696}
4697
4699
4701 StringRef TypoStr = Typo->getName();
4703
4704
4705
4706
4707 if (TypoStr.size() < 3 &&
4708 (Name != TypoStr || Correction.getEditDistance(true) > TypoStr.size()))
4709 return;
4710
4711
4714 if (!Correction || (*CorrectionValidator, Correction))
4715 return;
4716 }
4717
4718 TypoResultList &CList =
4719 CorrectionResults[Correction.getEditDistance(false)][Name];
4720
4721 if (!CList.empty() && !CList.back().isResolved())
4722 CList.pop_back();
4724 auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &TypoCorr) {
4726 });
4727 if (RI != CList.end()) {
4728
4729
4730
4731 auto IsDeprecated = [](Decl *D) {
4732 while (D) {
4734 return true;
4735 D = llvm::dyn_cast_or_null(D->getDeclContext());
4736 }
4737 return false;
4738 };
4739
4740
4741
4742 std::pair<bool, std::string> NewKey = {
4744 Correction.getAsString(SemaRef.getLangOpts())};
4745
4746 std::pair<bool, std::string> PrevKey = {
4747 IsDeprecated(RI->getFoundDecl()),
4748 RI->getAsString(SemaRef.getLangOpts())};
4749
4750 if (NewKey < PrevKey)
4751 *RI = Correction;
4752 return;
4753 }
4754 }
4755 if (CList.empty() || Correction.isResolved())
4756 CList.push_back(Correction);
4757
4759 CorrectionResults.erase(std::prev(CorrectionResults.end()));
4760}
4761
4763 const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces) {
4764 SearchNamespaces = true;
4765
4766 for (auto KNPair : KnownNamespaces)
4767 Namespaces.addNameSpecifier(KNPair.first);
4768
4769 bool SSIsTemplate = false;
4770 if (NestedNameSpecifier NNS = (SS ? SS->getScopeRep() : std::nullopt)) {
4772 SSIsTemplate =
4774 }
4775
4776
4777
4778 auto &Types = SemaRef.getASTContext().getTypes();
4779 for (unsigned I = 0; I != Types.size(); ++I) {
4780 const auto *TI = Types[I];
4781 if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) {
4782 CD = CD->getCanonicalDecl();
4783 if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() &&
4784 !CD->isUnion() && CD->getIdentifier() &&
4786 (CD->isBeingDefined() || CD->isCompleteDefinition()))
4787 Namespaces.addNameSpecifier(CD);
4788 }
4789 }
4790}
4791
4793 if (++CurrentTCIndex < ValidatedCorrections.size())
4794 return ValidatedCorrections[CurrentTCIndex];
4795
4796 CurrentTCIndex = ValidatedCorrections.size();
4797 while (!CorrectionResults.empty()) {
4798 auto DI = CorrectionResults.begin();
4799 if (DI->second.empty()) {
4800 CorrectionResults.erase(DI);
4801 continue;
4802 }
4803
4804 auto RI = DI->second.begin();
4805 if (RI->second.empty()) {
4806 DI->second.erase(RI);
4807 performQualifiedLookups();
4808 continue;
4809 }
4810
4813 ValidatedCorrections.push_back(TC);
4814 return ValidatedCorrections[CurrentTCIndex];
4815 }
4816 }
4817 return ValidatedCorrections[0];
4818}
4819
4820bool TypoCorrectionConsumer::resolveCorrection(TypoCorrection &Candidate) {
4822 DeclContext *TempMemberContext = MemberContext;
4824retry_lookup:
4826 EnteringContext,
4827 CorrectionValidator->IsObjCIvarLookup,
4829 switch (Result.getResultKind()) {
4833 if (TempSS) {
4834
4835 TempSS = nullptr;
4837 goto retry_lookup;
4838 }
4839 if (TempMemberContext) {
4840 if (SS && !TempSS)
4841 TempSS = SS.get();
4842 TempMemberContext = nullptr;
4843 goto retry_lookup;
4844 }
4845 if (SearchNamespaces)
4846 QualifiedResults.push_back(Candidate);
4847 break;
4848
4850
4851 break;
4852
4855
4856 for (auto *TRD : Result)
4860 if (SearchNamespaces)
4861 QualifiedResults.push_back(Candidate);
4862 break;
4863 }
4865 return true;
4866 }
4867 return false;
4868}
4869
4870void TypoCorrectionConsumer::performQualifiedLookups() {
4871 unsigned TypoLen = Typo->getName().size();
4872 for (const TypoCorrection &QR : QualifiedResults) {
4873 for (const auto &NSI : Namespaces) {
4874 DeclContext *Ctx = NSI.DeclCtx;
4875 CXXRecordDecl *NamingClass = NSI.NameSpecifier.getAsRecordDecl();
4876
4877
4878
4879
4880
4881 if (NamingClass &&
4882 NamingClass->getIdentifier() == QR.getCorrectionAsIdentifierInfo())
4883 continue;
4884
4885 TypoCorrection TC(QR);
4886 TC.ClearCorrectionDecls();
4887 TC.setCorrectionSpecifier(NSI.NameSpecifier);
4888 TC.setQualifierDistance(NSI.EditDistance);
4889 TC.setCallbackDistance(0);
4890
4891
4892
4893
4894 unsigned TmpED = TC.getEditDistance(true);
4895 if (QR.getCorrectionAsIdentifierInfo() != Typo && TmpED &&
4896 TypoLen / TmpED < 3)
4897 continue;
4898
4899 Result.clear();
4900 Result.setLookupName(QR.getCorrectionAsIdentifierInfo());
4901 if (!SemaRef.LookupQualifiedName(Result, Ctx))
4902 continue;
4903
4904
4905
4906 switch (Result.getResultKind()) {
4909 if (SS && SS->isValid()) {
4910 std::string NewQualified = TC.getAsString(SemaRef.getLangOpts());
4911 std::string OldQualified;
4912 llvm::raw_string_ostream OldOStream(OldQualified);
4913 SS->getScopeRep().print(OldOStream, SemaRef.getPrintingPolicy());
4914 OldOStream << Typo->getName();
4915
4916
4917
4918 if (OldOStream.str() == NewQualified)
4919 break;
4920 }
4922 TRD != TRDEnd; ++TRD) {
4923 if (SemaRef.CheckMemberAccess(TC.getCorrectionRange().getBegin(),
4924 NamingClass,
4926 TC.addCorrectionDecl(*TRD);
4927 }
4928 if (TC.isResolved()) {
4929 TC.setCorrectionRange(SS.get(), Result.getLookupNameInfo());
4931 }
4932 break;
4933 }
4938 break;
4939 }
4940 }
4941 }
4942 QualifiedResults.clear();
4943}
4944
4945TypoCorrectionConsumer::NamespaceSpecifierSet::NamespaceSpecifierSet(
4947 : Context(Context), CurContextChain(buildContextChain(CurContext)) {
4948 if (NestedNameSpecifier NNS =
4949 CurScopeSpec ? CurScopeSpec->getScopeRep() : std::nullopt) {
4950 llvm::raw_string_ostream SpecifierOStream(CurNameSpecifier);
4951 NNS.print(SpecifierOStream, Context.getPrintingPolicy());
4952
4953 getNestedNameSpecifierIdentifiers(NNS, CurNameSpecifierIdentifiers);
4954 }
4955
4956
4957
4958 for (DeclContext *C : llvm::reverse(CurContextChain)) {
4959 if (auto *ND = dyn_cast_or_null(C))
4960 CurContextIdentifiers.push_back(ND->getIdentifier());
4961 }
4962
4963
4966 DistanceMap[1].push_back(SI);
4967}
4968
4969auto TypoCorrectionConsumer::NamespaceSpecifierSet::buildContextChain(
4970 DeclContext *Start) -> DeclContextList {
4971 assert(Start && "Building a context chain from a null context");
4972 DeclContextList Chain;
4975 NamespaceDecl *ND = dyn_cast_or_null(DC);
4979 }
4980 return Chain;
4981}
4982
4983unsigned
4984TypoCorrectionConsumer::NamespaceSpecifierSet::buildNestedNameSpecifier(
4986 unsigned NumSpecifiers = 0;
4987 for (DeclContext *C : llvm::reverse(DeclChain)) {
4988 if (auto *ND = dyn_cast_or_null(C)) {
4989 NNS = NestedNameSpecifier(Context, ND, NNS);
4990 ++NumSpecifiers;
4991 } else if (auto *RD = dyn_cast_or_null(C)) {
4993 false);
4994 NNS = NestedNameSpecifier(T.getTypePtr());
4995 ++NumSpecifiers;
4996 }
4997 }
4998 return NumSpecifiers;
4999}
5000
5001void TypoCorrectionConsumer::NamespaceSpecifierSet::addNameSpecifier(
5002 DeclContext *Ctx) {
5003 NestedNameSpecifier NNS = std::nullopt;
5004 unsigned NumSpecifiers = 0;
5005 DeclContextList NamespaceDeclChain(buildContextChain(Ctx));
5006 DeclContextList FullNamespaceDeclChain(NamespaceDeclChain);
5007
5008
5009 for (DeclContext *C : llvm::reverse(CurContextChain)) {
5010 if (NamespaceDeclChain.empty() || NamespaceDeclChain.back() != C)
5011 break;
5012 NamespaceDeclChain.pop_back();
5013 }
5014
5015
5016 NumSpecifiers = buildNestedNameSpecifier(NamespaceDeclChain, NNS);
5017
5018
5019 if (NamespaceDeclChain.empty()) {
5020
5022 NumSpecifiers =
5023 buildNestedNameSpecifier(FullNamespaceDeclChain, NNS);
5024 } else if (NamedDecl *ND =
5025 dyn_cast_or_null(NamespaceDeclChain.back())) {
5027 bool SameNameSpecifier = false;
5028 if (llvm::is_contained(CurNameSpecifierIdentifiers, Name)) {
5029 std::string NewNameSpecifier;
5030 llvm::raw_string_ostream SpecifierOStream(NewNameSpecifier);
5031 SmallVector<const IdentifierInfo *, 4> NewNameSpecifierIdentifiers;
5034 SameNameSpecifier = NewNameSpecifier == CurNameSpecifier;
5035 }
5036 if (SameNameSpecifier || llvm::is_contained(CurContextIdentifiers, Name)) {
5037
5039 NumSpecifiers =
5040 buildNestedNameSpecifier(FullNamespaceDeclChain, NNS);
5041 }
5042 }
5043
5044
5045
5046
5047
5048 if (NNS && !CurNameSpecifierIdentifiers.empty()) {
5049 SmallVector<const IdentifierInfo*, 4> NewNameSpecifierIdentifiers;
5051 NumSpecifiers =
5052 llvm::ComputeEditDistance(llvm::ArrayRef(CurNameSpecifierIdentifiers),
5053 llvm::ArrayRef(NewNameSpecifierIdentifiers));
5054 }
5055
5056 SpecifierInfo SI = {Ctx, NNS, NumSpecifiers};
5057 DistanceMap[NumSpecifiers].push_back(SI);
5058}
5059
5060
5066 bool EnteringContext,
5067 bool isObjCIvarLookup,
5068 bool FindHidden) {
5073 if (MemberContext) {
5074 if (ObjCInterfaceDecl *Class = dyn_cast(MemberContext)) {
5075 if (isObjCIvarLookup) {
5076 if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(Name)) {
5079 return;
5080 }
5081 }
5082
5083 if (ObjCPropertyDecl *Prop = Class->FindPropertyDeclaration(
5087 return;
5088 }
5089 }
5090
5092 return;
5093 }
5094
5097 false, EnteringContext);
5098
5099
5100
5102 if (Method->isInstanceMethod() && Method->getClassInterface() &&
5107 = Method->getClassInterface()->lookupInstanceVariable(Name)) {
5110 }
5111 }
5112 }
5113}
5114
5115
5119 bool AfterNestedNameSpecifier) {
5120 if (AfterNestedNameSpecifier) {
5121
5125 return;
5126 }
5127
5130
5132
5133 static const char *const CTypeSpecs[] = {
5134 "char", "const", "double", "enum", "float", "int", "long", "short",
5135 "signed", "struct", "union", "unsigned", "void", "volatile",
5136 "_Complex",
5137
5138 "extern", "inline", "static", "typedef"
5139 };
5140
5141 for (const auto *CTS : CTypeSpecs)
5143
5146
5153
5158
5159 if (SemaRef.getLangOpts().CPlusPlus11) {
5165 }
5166 }
5167
5171 static const char *const CastableTypeSpecs[] = {
5172 "char", "double", "float", "int", "long", "short",
5173 "signed", "unsigned", "void"
5174 };
5175 for (auto *kw : CastableTypeSpecs)
5177 }
5178
5184 }
5185
5191 }
5192
5194 static const char *const CXXExprs[] = {
5195 "delete", "new", "operator", "throw", "typeid"
5196 };
5197 for (const auto *CE : CXXExprs)
5199
5203
5204 if (SemaRef.getLangOpts().CPlusPlus11) {
5207 }
5208 }
5209
5211
5212
5214 }
5215 }
5216
5219
5220 static const char *const CStmts[] = {
5221 "do", "else", "for", "goto", "if", "return", "switch", "while" };
5222 for (const auto *CS : CStmts)
5224
5228 }
5229
5232
5235
5240 }
5241 } else {
5245 }
5246
5255 }
5256 }
5257
5260
5263 }
5264 }
5265}
5266
5267std::unique_ptr Sema::makeTypoCorrectionConsumer(
5269 Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC,
5270 DeclContext *MemberContext, bool EnteringContext,
5271 const ObjCObjectPointerType *OPT, bool ErrorRecovery) {
5272
5273 if (Diags.hasFatalErrorOccurred() || !getLangOpts().SpellChecking ||
5274 DisableTypoCorrection)
5275 return nullptr;
5276
5277
5278
5279
5282 return nullptr;
5283
5284
5286 if (!Typo)
5287 return nullptr;
5288
5289
5290
5291 if (SS && SS->isInvalid())
5292 return nullptr;
5293
5294
5295 if (!CodeSynthesisContexts.empty())
5296 return nullptr;
5297
5298
5299 if (S && S->isInObjcMethodScope() && Typo == getSuperIdentifier())
5300 return nullptr;
5301
5302
5303 IdentifierSourceLocations::iterator locs = TypoCorrectionFailures.find(Typo);
5304 if (locs != TypoCorrectionFailures.end() &&
5305 locs->second.count(TypoName.getLoc()))
5306 return nullptr;
5307
5308
5309
5310
5311 if ((getLangOpts().AltiVec || getLangOpts().ZVector) && Typo->isStr("vector"))
5312 return nullptr;
5313
5314
5315
5316
5317 unsigned Limit = getDiagnostics().getDiagnosticOptions().SpellCheckingLimit;
5318 if (Limit && TyposCorrected >= Limit)
5319 return nullptr;
5320 ++TyposCorrected;
5321
5322
5323
5325 getLangOpts().ModulesSearchAll) {
5326
5327 getModuleLoader().lookupMissingImports(Typo->getName(),
5329 }
5330
5331
5332
5333
5334
5335 std::unique_ptr ClonedCCC = CCC.clone();
5336 auto Consumer = std::make_unique(
5337 *this, TypoName, LookupKind, S, SS, std::move(ClonedCCC), MemberContext,
5338 EnteringContext);
5339
5340
5341 bool IsUnqualifiedLookup = false;
5342 DeclContext *QualifiedDC = MemberContext;
5343 if (MemberContext) {
5344 LookupVisibleDecls(MemberContext, LookupKind, *Consumer);
5345
5346
5347 if (OPT) {
5348 for (auto *I : OPT->quals())
5349 LookupVisibleDecls(I, LookupKind, *Consumer);
5350 }
5351 } else if (SS && SS->isSet()) {
5352 QualifiedDC = computeDeclContext(*SS, EnteringContext);
5353 if (!QualifiedDC)
5354 return nullptr;
5355
5356 LookupVisibleDecls(QualifiedDC, LookupKind, *Consumer);
5357 } else {
5358 IsUnqualifiedLookup = true;
5359 }
5360
5361
5362
5363 bool SearchNamespaces
5364 = getLangOpts().CPlusPlus &&
5365 (IsUnqualifiedLookup || (SS && SS->isSet()));
5366
5367 if (IsUnqualifiedLookup || SearchNamespaces) {
5368
5369
5370
5371 for (const auto &I : Context.Idents)
5372 Consumer->FoundName(I.getKey());
5373
5374
5375
5376 if (IdentifierInfoLookup *External
5378 std::unique_ptr Iter(External->getIdentifiers());
5379 do {
5380 StringRef Name = Iter->Next();
5381 if (Name.empty())
5382 break;
5383
5384 Consumer->FoundName(Name);
5385 } while (true);
5386 }
5387 }
5388
5390 *Consumer->getCorrectionValidator(),
5391 SS && SS->isNotEmpty());
5392
5393
5394
5395 if (SearchNamespaces) {
5396
5397 if (ExternalSource && !LoadedExternalKnownNamespaces) {
5398 SmallVector<NamespaceDecl *, 4> ExternalKnownNamespaces;
5399 LoadedExternalKnownNamespaces = true;
5400 ExternalSource->ReadKnownNamespaces(ExternalKnownNamespaces);
5401 for (auto *N : ExternalKnownNamespaces)
5402 KnownNamespaces[N] = true;
5403 }
5404
5405 Consumer->addNamespaces(KnownNamespaces);
5406 }
5407
5408 return Consumer;
5409}
5410
5417 bool EnteringContext,
5419 bool RecordFailure) {
5420
5421
5424 ExternalSource->CorrectTypo(TypoName, LookupKind, S, SS, CCC,
5425 MemberContext, EnteringContext, OPT))
5426 return Correction;
5427 }
5428
5429
5430
5431
5432
5434
5436 auto Consumer = makeTypoCorrectionConsumer(
5437 TypoName, LookupKind, S, SS, CCC, MemberContext, EnteringContext, OPT,
5439
5442
5443
5445 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5446
5447
5448
5449 unsigned ED = Consumer->getBestEditDistance(true);
5450 unsigned TypoLen = Typo->getName().size();
5451 if (ED > 0 && TypoLen / ED < 3)
5452 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5453
5456 if (!BestTC)
5457 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5458
5460
5461 if (TypoLen >= 3 && ED > 0 && TypoLen / ED < 3) {
5462
5463
5464
5465 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5466 }
5467
5468
5469 if (!SecondBestTC ||
5472
5473
5474
5475 if (ED == 0 && Result.isKeyword())
5476 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5477
5481 return TC;
5482 } else if (SecondBestTC && ObjCMessageReceiver) {
5483
5484
5485
5488 BestTC = SecondBestTC;
5489 else if ((*Consumer)["super"].front().isKeyword())
5490 BestTC = (*Consumer)["super"].front();
5491 }
5492
5493
5496 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure);
5497
5499 return BestTC;
5500 }
5501
5502
5503
5504
5505 return FailedCorrection(Typo, TypoName.getLoc(), RecordFailure && !SecondBestTC);
5506}
5507
5509 if (!CDecl) return;
5510
5512 CorrectionDecls.clear();
5513
5514 CorrectionDecls.push_back(CDecl);
5515
5516 if (!CorrectionName)
5518}
5519
5521 if (CorrectionNameSpec) {
5522 std::string tmpBuffer;
5523 llvm::raw_string_ostream PrefixOStream(tmpBuffer);
5524 CorrectionNameSpec.print(PrefixOStream, PrintingPolicy(LO));
5525 PrefixOStream << CorrectionName;
5526 return PrefixOStream.str();
5527 }
5528
5530}
5531
5535 return true;
5536
5540
5541 bool HasNonType = false;
5542 bool HasStaticMethod = false;
5543 bool HasNonStaticMethod = false;
5544 for (Decl *D : candidate) {
5546 D = FTD->getTemplatedDecl();
5548 if (Method->isStatic())
5549 HasStaticMethod = true;
5550 else
5551 HasNonStaticMethod = true;
5552 }
5554 HasNonType = true;
5555 }
5556
5559 return false;
5560
5562}
5563
5565 bool HasExplicitTemplateArgs,
5567 : NumArgs(NumArgs), HasExplicitTemplateArgs(HasExplicitTemplateArgs),
5568 CurContext(SemaRef.CurContext), MemberFn(ME) {
5571 !HasExplicitTemplateArgs && NumArgs == 1;
5574}
5575
5579
5580 for (auto *C : candidate) {
5582 NamedDecl *ND = C->getUnderlyingDecl();
5584 FD = FTD->getTemplatedDecl();
5585 if (!HasExplicitTemplateArgs && !FD) {
5586 if (!(FD = dyn_cast(ND)) && isa(ND)) {
5587
5588
5589
5591 if (ValType.isNull())
5592 continue;
5596 if (FPT->getNumParams() == NumArgs)
5597 return true;
5598 }
5599 }
5600
5601
5604 CurContext->getParentASTContext().getLangOpts().CPlusPlus)
5605
5606 return NumArgs <= 1 || HasExplicitTemplateArgs || isa(ND);
5607
5608
5609
5610 if (!FD || !(FD->getNumParams() >= NumArgs &&
5612 continue;
5613
5614
5615
5616
5617
5618 if (const auto *MD = dyn_cast(FD)) {
5619 if (MemberFn || !MD->isStatic()) {
5620 const auto *CurMD =
5621 MemberFn
5622 ? dyn_cast_if_present(MemberFn->getMemberDecl())
5623 : dyn_cast_if_present(CurContext);
5625 CurMD ? CurMD->getParent()->getCanonicalDecl() : nullptr;
5627 if (!CurRD || (CurRD != RD && !CurRD->isDerivedFrom(RD)))
5628 continue;
5629 }
5630 }
5631 return true;
5632 }
5633 return false;
5634}
5635
5642
5643
5644
5646 if (const auto *VD = dyn_cast(D))
5647 return VD->getDefinition();
5648 if (const auto *FD = dyn_cast(D))
5649 return FD->getDefinition();
5650 if (const auto *TD = dyn_cast(D))
5651 return TD->getDefinition();
5652 if (const auto *ID = dyn_cast(D))
5653 return ID->getDefinition();
5654 if (const auto *PD = dyn_cast(D))
5655 return PD->getDefinition();
5656 if (const auto *TD = dyn_cast(D))
5657 if (const NamedDecl *TTD = TD->getTemplatedDecl())
5659 return nullptr;
5660}
5661
5664
5665
5667 if (!Def)
5669
5671 assert(Owner && "definition of hidden declaration is not in a module");
5672
5674 OwningModules.push_back(Owner);
5675 auto Merged = Context.getModulesWithMergedDefinition(Def);
5676 llvm::append_range(OwningModules, Merged);
5677
5679 Recover);
5680}
5681
5682
5683
5685 llvm::StringRef IncludingFile) {
5686 bool IsAngled = false;
5688 E, IncludingFile, &IsAngled);
5689 return (IsAngled ? '<' : '"') + Path + (IsAngled ? '>' : '"');
5690}
5691
5696 assert(!Modules.empty());
5697
5698
5699
5701 return;
5702
5703 auto NotePrevious = [&] {
5704
5705
5706
5707 Diag(DeclLoc, diag::note_unreachable_entity) << (int)MIK;
5708 };
5709
5710
5712 llvm::SmallDenseSet<Module*, 8> UniqueModuleSet;
5713 for (auto *M : Modules) {
5715 continue;
5716 if (UniqueModuleSet.insert(M).second)
5717 UniqueModules.push_back(M);
5718 }
5719
5720
5721 std::string HeaderName;
5723 PP.getHeaderToIncludeForDiagnostics(UseLoc, DeclLoc)) {
5726 HeaderName =
5728 }
5729
5730
5731
5732 if (!HeaderName.empty() || UniqueModules.empty()) {
5733
5734
5735 Diag(UseLoc, diag::err_module_unimported_use_header)
5736 << (int)MIK << Decl << !HeaderName.empty() << HeaderName;
5737
5738 NotePrevious();
5739 if (Recover)
5741 return;
5742 }
5743
5744 Modules = UniqueModules;
5745
5746 auto GetModuleNameForDiagnostic = [this](const Module *M) -> std::string {
5749
5752
5753
5754
5755
5758 else
5760 };
5761
5762 if (Modules.size() > 1) {
5763 std::string ModuleList;
5764 unsigned N = 0;
5765 for (const auto *M : Modules) {
5766 ModuleList += "\n ";
5767 if (++N == 5 && N != Modules.size()) {
5768 ModuleList += "[...]";
5769 break;
5770 }
5771 ModuleList += GetModuleNameForDiagnostic(M);
5772 }
5773
5774 Diag(UseLoc, diag::err_module_unimported_use_multiple)
5775 << (int)MIK << Decl << ModuleList;
5776 } else {
5777
5778 Diag(UseLoc, diag::err_module_unimported_use)
5779 << (int)MIK << Decl << GetModuleNameForDiagnostic(Modules[0]);
5780 }
5781
5782 NotePrevious();
5783
5784
5785 if (Recover)
5787}
5788
5797
5798
5801 assert(Decl && "import required but no declaration to import");
5802
5805 return;
5806 }
5807
5810
5813
5814
5815
5816 if (const auto *FD = dyn_cast_if_present(ChosenDecl);
5817 FD && FD->getBuiltinID() &&
5818 PrevNote.getDiagID() == diag::note_previous_decl &&
5820 ChosenDecl = nullptr;
5821 }
5822
5823 if (PrevNote.getDiagID() && ChosenDecl)
5824 Diag(ChosenDecl->getLocation(), PrevNote)
5826
5827
5830}
5831
5841
5845
5847
5848
5849
5850
5854}
Defines the clang::ASTContext interface.
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
FormatToken * Next
The next token in the unwrapped line.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
static StringRef getIdentifier(const Token &Tok)
Defines the clang::Preprocessor interface.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
@ NotForRedeclaration
The lookup is a reference to this name that is not for the purpose of redeclaring the name.
@ ForExternalRedeclaration
The lookup results will be used for redeclaration of a name with external linkage; non-visible lookup...
@ ForVisibleRedeclaration
The lookup results will be used for redeclaration of a name, if an entity by that name already exists...
static Module * getDefiningModule(Sema &S, Decl *Entity)
Find the module in which the given declaration was defined.
Definition SemaLookup.cpp:1587
static bool isPreferredLookupResult(Sema &S, Sema::LookupNameKind Kind, const NamedDecl *D, const NamedDecl *Existing)
Determine whether D is a better lookup result than Existing, given that they declare the same entity.
Definition SemaLookup.cpp:374
static bool CanDeclareSpecialMemberFunction(const CXXRecordDecl *Class)
Determine whether we can declare a special member function within the class at this point.
Definition SemaLookup.cpp:1014
static bool canHideTag(const NamedDecl *D)
Determine whether D can hide a tag declaration.
Definition SemaLookup.cpp:468
static std::string getHeaderNameForHeader(Preprocessor &PP, FileEntryRef E, llvm::StringRef IncludingFile)
Get a "quoted.h" or <angled.h> include path to use in a diagnostic suggesting the addition of a inclu...
Definition SemaLookup.cpp:5684
static void addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType T)
Definition SemaLookup.cpp:3138
static QualType getOpenCLTypedefType(Sema &S, llvm::StringRef Name)
Lookup an OpenCL typedef type.
Definition SemaLookup.cpp:723
static DeclContext * findOuterContext(Scope *S)
Find the outer declaration context from this scope.
Definition SemaLookup.cpp:1259
static void LookupPotentialTypoResult(Sema &SemaRef, LookupResult &Res, IdentifierInfo *Name, Scope *S, CXXScopeSpec *SS, DeclContext *MemberContext, bool EnteringContext, bool isObjCIvarLookup, bool FindHidden)
Perform name lookup for a possible result for typo correction.
Definition SemaLookup.cpp:5061
static void checkCorrectionVisibility(Sema &SemaRef, TypoCorrection &TC)
Check whether the declarations found for a typo correction are visible.
Definition SemaLookup.cpp:4510
static bool isNamespaceOrTranslationUnitScope(Scope *S)
Definition SemaLookup.cpp:1250
static bool LookupQualifiedNameInUsingDirectives(Sema &S, LookupResult &R, DeclContext *StartDC)
Perform qualified name lookup in the namespaces nominated by using directives by the given context.
Definition SemaLookup.cpp:2352
static bool LookupDirect(Sema &S, LookupResult &R, const DeclContext *DC)
Definition SemaLookup.cpp:1130
static QualType getOpenCLEnumType(Sema &S, llvm::StringRef Name)
Lookup an OpenCL enum type.
Definition SemaLookup.cpp:710
static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet &Namespaces, DeclContext *Ctx)
Definition SemaLookup.cpp:2920
static bool hasAcceptableDefaultArgument(Sema &S, const ParmDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
Definition SemaLookup.cpp:1693
static bool isImplicitlyDeclaredMemberFunctionName(DeclarationName Name)
Determine whether this is the name of an implicitly-declared special member function.
Definition SemaLookup.cpp:1056
static void getNestedNameSpecifierIdentifiers(NestedNameSpecifier NNS, SmallVectorImpl< const IdentifierInfo * > &Identifiers)
Definition SemaLookup.cpp:4548
static void DeclareImplicitMemberFunctionsWithName(Sema &S, DeclarationName Name, SourceLocation Loc, const DeclContext *DC)
If there are any implicit member functions with the given name that need to be declared in the given ...
Definition SemaLookup.cpp:1074
static void AddKeywordsToConsumer(Sema &SemaRef, TypoCorrectionConsumer &Consumer, Scope *S, CorrectionCandidateCallback &CCC, bool AfterNestedNameSpecifier)
Add keywords to the consumer as possible typo corrections.
Definition SemaLookup.cpp:5116
static void GetQualTypesForOpenCLBuiltin(Sema &S, const OpenCLBuiltinStruct &OpenCLBuiltin, unsigned &GenTypeMaxCnt, SmallVector< QualType, 1 > &RetTypes, SmallVector< SmallVector< QualType, 1 >, 5 > &ArgTypes)
Get the QualType instances of the return type and arguments for an OpenCL builtin function signature.
Definition SemaLookup.cpp:747
static QualType diagOpenCLBuiltinTypeError(Sema &S, llvm::StringRef TypeClass, llvm::StringRef Name)
Diagnose a missing builtin type.
Definition SemaLookup.cpp:702
static bool hasAcceptableMemberSpecialization(Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
Definition SemaLookup.cpp:1804
static bool hasAcceptableDeclarationImpl(Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Filter F, Sema::AcceptableKind Kind)
Definition SemaLookup.cpp:1744
static bool isCandidateViable(CorrectionCandidateCallback &CCC, TypoCorrection &Candidate)
Definition SemaLookup.cpp:4492
static const DeclContext * getContextForScopeMatching(const Decl *D)
Get a representative context for a declaration such that two declarations will have the same context ...
Definition SemaLookup.cpp:359
static NamedDecl * findAcceptableDecl(Sema &SemaRef, NamedDecl *D, unsigned IDNS)
Retrieve the visible declaration corresponding to D, if any.
Definition SemaLookup.cpp:2090
static void GetOpenCLBuiltinFctOverloads(ASTContext &Context, unsigned GenTypeMaxCnt, std::vector< QualType > &FunctionList, SmallVector< QualType, 1 > &RetTypes, SmallVector< SmallVector< QualType, 1 >, 5 > &ArgTypes)
Create a list of the candidate function overloads for an OpenCL builtin function.
Definition SemaLookup.cpp:776
static const unsigned MaxTypoDistanceResultSets
Definition SemaLookup.cpp:4698
static const NamedDecl * getDefinitionToImport(const NamedDecl *D)
Find which declaration we should import to provide the definition of the given declaration.
Definition SemaLookup.cpp:5645
static bool hasAcceptableExplicitSpecialization(Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
Definition SemaLookup.cpp:1771
static unsigned getIDNS(Sema::LookupNameKind NameKind, bool CPlusPlus, bool Redeclaration)
Definition SemaLookup.cpp:214
static void InsertOCLBuiltinDeclarationsFromTable(Sema &S, LookupResult &LR, IdentifierInfo *II, const unsigned FctIndex, const unsigned Len)
When trying to resolve a function name, if isOpenCLBuiltin() returns a non-null <Index,...
Definition SemaLookup.cpp:821
static void LookupPredefedObjCSuperType(Sema &Sema, Scope *S)
Looks up the declaration of "struct objc_super" and saves it for later use in building builtin declar...
Definition SemaLookup.cpp:997
static bool CppNamespaceLookup(Sema &S, LookupResult &R, ASTContext &Context, const DeclContext *NS, UnqualUsingDirectiveSet &UDirs)
Definition SemaLookup.cpp:1230
This file declares semantic analysis functions specific to RISC-V.
__DEVICE__ long long abs(long long __n)
A class for storing results from argument-dependent lookup.
void insert(NamedDecl *D)
Adds a new ADL candidate to this map.
Definition SemaLookup.cpp:3838
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
Builtin::Context & BuiltinInfo
bool isInSameModule(const Module *M1, const Module *M2) const
If the two module M1 and M2 are in the same module.
const clang::PrintingPolicy & getPrintingPolicy() const
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
CanQualType getCanonicalTagType(const TagDecl *TD) const
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
DeclContext::lookup_iterator Decls
The declarations found inside this base class subobject.
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
void setOrigin(const CXXRecordDecl *Rec)
std::list< CXXBasePath >::iterator paths_iterator
std::list< CXXBasePath >::const_iterator const_paths_iterator
void swap(CXXBasePaths &Other)
Swap this data structure's contents with another CXXBasePaths object.
Represents a base class of a C++ class.
QualType getType() const
Retrieves the type of the base class.
Represents a C++ constructor within a class.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation.
bool needsImplicitDefaultConstructor() const
Determine if we need to declare a default constructor for this class.
bool needsImplicitMoveConstructor() const
Determine whether this class should get an implicit move constructor or if any existing special membe...
CXXRecordDecl * getDefinition() const
static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, AccessSpecifier DeclAccess)
Calculates the access of a decl that is reached along a path.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, bool LookupInDependent=false) const
Look for entities within the base classes of this C++ class, transitively searching all base class su...
bool needsImplicitCopyConstructor() const
Determine whether this class needs an implicit copy constructor to be lazily declared.
bool needsImplicitDestructor() const
Determine whether this class needs an implicit destructor to be lazily declared.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
UnresolvedSetIterator conversion_iterator
bool needsImplicitMoveAssignment() const
Determine whether this class should get an implicit move assignment operator or if any existing speci...
bool needsImplicitCopyAssignment() const
Determine whether this class needs an implicit copy assignment operator to be lazily declared.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
SourceRange getRange() const
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool isEmpty() const
No scope specifier.
Declaration of a class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
bool WantExpressionKeywords
virtual unsigned RankCandidate(const TypoCorrection &candidate)
Method used by Sema::CorrectTypo to assign an "edit distance" rank to a candidate (where a lower valu...
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
Definition SemaLookup.cpp:5532
bool WantFunctionLikeCasts
bool WantRemainingKeywords
virtual std::unique_ptr< CorrectionCandidateCallback > clone()=0
Clone this CorrectionCandidateCallback.
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
DeclListNode::iterator iterator
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
lookup_result::iterator lookup_iterator
bool isFileContext() const
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
lookups_range noload_lookups(bool PreserveInternalState) const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
lookups_range lookups() const
bool shouldUseQualifiedLookup() const
void setUseQualifiedLookup(bool use=true) const
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
bool isInlineNamespace() const
bool isFunctionOrMethod() const
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context semantically encloses the declaration context DC.
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
ASTContext & getASTContext() const LLVM_READONLY
bool isInNamedModule() const
Whether this declaration comes from a named module.
bool isUnconditionallyVisible() const
Determine whether this declaration is definitely visible to name lookup, independent of whether the o...
bool isInIdentifierNamespace(unsigned NS) const
bool isInvisibleOutsideTheOwningModule() const
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
bool isInAnotherModuleUnit() const
Whether this declaration comes from another module unit.
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
bool isInvalidDecl() const
unsigned getIdentifierNamespace() const
SourceLocation getLocation() const
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
@ IDNS_TagFriend
This declaration is a friend class.
@ IDNS_Ordinary
Ordinary names.
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
@ IDNS_OMPReduction
This declaration is an OpenMP user defined reduction construction.
@ IDNS_Label
Labels, declared with 'x:' and referenced with 'goto x'.
@ IDNS_Member
Members, declared with object declarations within tag definitions.
@ IDNS_OMPMapper
This declaration is an OpenMP user defined mapper.
@ IDNS_ObjCProtocol
Objective C @protocol.
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
@ IDNS_OrdinaryFriend
This declaration is a friend function.
@ IDNS_Using
This declaration is a using declaration.
@ IDNS_LocalExtern
This declaration is a function-local extern declaration of a variable or function.
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
bool isDeprecated(std::string *Message=nullptr) const
Determine whether this declaration is marked 'deprecated'.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack.
void setImplicit(bool I=true)
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
DeclContext * getDeclContext()
bool hasTagIdentifierNamespace() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
std::string getAsString() const
Retrieve the human-readable string for this name.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
The return type of classify().
This represents one expression.
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
bool isFPConstrained() const
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Cached information about one file (either on disk or in the virtual file system).
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
Definition SemaLookup.cpp:5576
FunctionCallFilterCCC(Sema &SemaRef, unsigned NumArgs, bool HasExplicitTemplateArgs, MemberExpr *ME=nullptr)
Definition SemaLookup.cpp:5564
Represents a function declaration or definition.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, const AssociatedConstraint &TrailingRequiresClause={})
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
bool isDeleted() const
Whether this function has been deleted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Represents a prototype with parameter type info, e.g.
ExtProtoInfo getExtProtoInfo() const
ArrayRef< QualType > param_types() const
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
ExtInfo withCallingConv(CallingConv cc) const
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getReturnType() const
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
StringRef getName() const
Return the actual identifier string.
iterator - Iterate over the decls of a specified declaration name.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
Represents the declaration of a label.
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A class for iterating through a result set and possibly filtering out results.
void restart()
Restart the iteration.
void erase()
Erase the last element returned from this iterator.
Represents the results of name lookup.
void addAllDecls(const LookupResult &Other)
Add all the declarations from another set of lookup results.
void setShadowed()
Note that we found and ignored a declaration while performing lookup.
static bool isAvailableForLookup(Sema &SemaRef, NamedDecl *ND)
Determine whether this lookup is permitted to see the declaration.
Definition SemaLookup.cpp:2166
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
void setFindLocalExtern(bool FindLocalExtern)
void setAllowHidden(bool AH)
Specify whether hidden declarations are visible, e.g., for recovery reasons.
DeclClass * getAsSingle() const
void setContextRange(SourceRange SR)
Sets a 'context' source range.
static bool isAcceptable(Sema &SemaRef, NamedDecl *D, Sema::AcceptableKind Kind)
void setAmbiguousQualifiedTagHiding()
Make these results show that the name was found in different contexts and a tag decl was hidden by an...
void dump()
Definition SemaLookup.cpp:694
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
bool isTemplateNameLookup() const
void setAmbiguousBaseSubobjects(CXXBasePaths &P)
Make these results show that the name was found in distinct base classes of the same type.
Definition SemaLookup.cpp:667
bool isSingleTagDecl() const
Asks if the result is a single tag decl.
void setLookupName(DeclarationName Name)
Sets the name to look up.
bool empty() const
Return true if no decls were found.
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition SemaLookup.cpp:488
SourceLocation getNameLoc() const
Gets the location of the identifier.
void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P)
Make these results show that the name was found in base classes of different types.
Definition SemaLookup.cpp:675
Filter makeFilter()
Create a filter for this result set.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
void setHideTags(bool Hide)
Sets whether tag declarations should be hidden by non-tag declarations during resolution.
NamedDecl * getAcceptableDecl(NamedDecl *D) const
Retrieve the accepted (re)declaration of the given declaration, if there is one.
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
unsigned getIdentifierNamespace() const
Returns the identifier namespace mask for this lookup.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
UnresolvedSetImpl::iterator iterator
void setNamingClass(CXXRecordDecl *Record)
Sets the 'naming class' for this lookup.
LookupResultKind getResultKind() const
void print(raw_ostream &)
Definition SemaLookup.cpp:683
static bool isReachable(Sema &SemaRef, NamedDecl *D)
Definition SemaLookup.cpp:2159
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
bool isForRedeclaration() const
True if this lookup is just looking for an existing declaration.
DeclarationName getLookupName() const
Gets the name to look up.
void setNotFoundInCurrentInstantiation()
Note that while no result was found in the current instantiation, there were dependent base classes t...
static bool isVisible(Sema &SemaRef, NamedDecl *D)
Determine whether the given declaration is visible to the program.
Definition SemaLookup.cpp:2149
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
A pointer to member type per C++ 8.3.3 - Pointers to members.
Describes a module or submodule.
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
bool isPrivateModule() const
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
bool isModuleVisible(const Module *M) const
Determine whether the specified module would be visible to a lookup at the end of this module.
bool isModuleInterfaceUnit() const
bool isModuleMapModule() const
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isExplicitGlobalModule() const
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
bool isImplicitGlobalModule() const
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
bool isPlaceholderVar(const LangOptions &LangOpts) const
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
NamedDecl * getMostRecentDecl()
bool isExternallyDeclarable() const
Determine whether this declaration can be redeclared in a different translation unit.
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Represents a C++ nested name specifier, such as "\::std::vector::".
static constexpr NestedNameSpecifier getGlobal()
NamespaceAndPrefix getAsNamespaceAndPrefix() const
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false, bool PrintFinalScopeResOp=true) const
Print this nested name specifier to the given output stream.
const Type * getAsType() const
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Type
A type, stored as a Type*.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Represents an ObjC class declaration.
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents a pointer to an Objective C object.
Represents one property declaration in an Objective-C interface.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
@ CSK_Normal
Normal lookup.
SmallVectorImpl< OverloadCandidate >::iterator iterator
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
llvm::iterator_range< decls_iterator > decls() const
Represents a parameter to a function.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
unsigned getDiagID() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool isMacroDefined(StringRef Id)
HeaderSearch & getHeaderSearchInfo() const
A (possibly-)qualified type.
void addConst()
Add the const type qualifier to this QualType.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void addVolatile()
Add the volatile type qualifier to this QualType.
Represents a template name as written in source code.
Scope - A scope is a transient data structure that is used while parsing the program.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
unsigned getFlags() const
getFlags - Return the flags for this scope.
DeclContext * getLookupEntity() const
Get the DeclContext in which to continue unqualified lookup after a lookup in this scope.
using_directives_range using_directives()
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by.
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
DeclContext * getEntity() const
Get the entity corresponding to this scope.
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
@ DeclScope
This is a scope that can contain a declaration.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
std::unique_ptr< sema::RISCVIntrinsicManager > IntrinsicManager
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
SpecialMemberOverloadResult - The overloading result for a special member function.
Sema - This implements semantic analysis and AST building for C.
void DeclareGlobalNewDelete()
DeclareGlobalNewDelete - Declare the global forms of operator new and delete.
bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a reachable definition.
CXXConstructorDecl * DeclareImplicitDefaultConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit default constructor for the given class.
llvm::DenseSet< Module * > LookupModulesCache
Cache of additional modules that should be used for name lookup within the current template instantia...
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
llvm::DenseSet< Module * > & getLookupModules()
Get the set of additional modules that should be checked during name lookup.
Definition SemaLookup.cpp:1612
LookupNameKind
Describes the kind of name lookup to perform.
@ LookupLabel
Label name lookup.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupUsingDeclName
Look up all declarations in a scope with the given name, including resolved using declarations.
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
@ LookupOMPReductionName
Look up the name of an OpenMP user-defined reduction operation.
@ LookupLocalFriendName
Look up a friend of a local class.
@ LookupObjCProtocolName
Look up the name of an Objective-C protocol.
@ LookupRedeclarationWithLinkage
Look up an ordinary name that is going to be redeclared as a name with linkage.
@ LookupOperatorName
Look up of an operator name (e.g., operator+) for use with operator overloading.
@ LookupObjCImplicitSelfParam
Look up implicit 'self' parameter of an objective-c method.
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
@ LookupDestructorName
Look up a name following ~ in a destructor name.
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
@ LookupOMPMapperName
Look up the name of an OpenMP user-defined mapper.
@ LookupAnyName
Look up any declaration with any name.
bool hasReachableDeclarationSlow(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Definition SemaLookup.cpp:2119
MissingImportKind
Kinds of missing import.
void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class)
Force the declaration of any implicitly-declared members of this class.
Definition SemaLookup.cpp:1023
bool hasVisibleDeclarationSlow(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules)
Definition SemaLookup.cpp:2111
void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID)
Definition SemaLookup.cpp:1007
bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class)
Perform qualified name lookup into all base classes of the given class.
Definition SemaLookup.cpp:2765
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
Preprocessor & getPreprocessor() const
CXXConstructorDecl * DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit move constructor for the given class.
static NamedDecl * getAsTemplateNameDecl(NamedDecl *D, bool AllowFunctionTemplates=true, bool AllowDependent=true)
Try to interpret the lookup result D as a template-name.
LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef< QualType > ArgTys, bool AllowRaw, bool AllowTemplate, bool AllowStringTemplate, bool DiagnoseMissing, StringLiteral *StringLit=nullptr)
LookupLiteralOperator - Determine which literal operator should be used for a user-defined literal,...
Definition SemaLookup.cpp:3686
bool hasVisibleExplicitSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if there is a visible declaration of D that is an explicit specialization declaration for a...
Definition SemaLookup.cpp:1791
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
Look up a name, looking for a single declaration.
Definition SemaLookup.cpp:3356
@ CTAK_Specified
The template argument was specified in the code or was instantiated with some deduced template argume...
llvm::DenseMap< NamedDecl *, NamedDecl * > VisibleNamespaceCache
Map from the most recent declaration of a namespace to the most recent visible declaration of that na...
bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def)
Definition SemaLookup.cpp:1684
bool LookupBuiltin(LookupResult &R)
Lookup a builtin function, when name lookup would otherwise fail.
Definition SemaLookup.cpp:921
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, UnresolvedSetImpl &Functions)
Definition SemaLookup.cpp:3365
bool hasVisibleDefaultArgument(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if the template parameter D has a visible default argument.
Definition SemaLookup.cpp:1730
NamedDecl * LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc)
LazilyCreateBuiltin - The specified Builtin-ID was first used at file scope.
ASTContext & getASTContext() const
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
Definition SemaLookup.cpp:3678
llvm::SmallSetVector< CXXRecordDecl *, 16 > AssociatedClassSet
std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths)
Builds a string representing ambiguous paths from a specific derived class to different subobjects of...
Module * getOwningModule(const Decl *Entity)
Get the module owning an entity.
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, ArrayRef< Expr * > Args, AssociatedNamespaceSet &AssociatedNamespaces, AssociatedClassSet &AssociatedClasses)
Find the associated classes and namespaces for argument-dependent lookup for a call with the given se...
Definition SemaLookup.cpp:3311
void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, TemplateArgumentListInfo *ExplicitTemplateArgs, QualType ObjectType, Expr::Classification ObjectClassification, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, OverloadCandidateParamOrder PO={})
Add a C++ member function template as a candidate to the candidate set, using template argument deduc...
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, CheckTemplateArgumentInfo &CTAI, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, OverloadCandidateParamOrder PO={}, bool AggregateCandidateDeduction=false)
Add a C++ function template specialization as a candidate in the candidate set, using template argume...
FPOptions & getCurFPFeatures()
CXXConstructorDecl * LookupDefaultConstructor(CXXRecordDecl *Class)
Look up the default constructor for the given class.
Definition SemaLookup.cpp:3603
const LangOptions & getLangOpts() const
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
Definition SemaLookup.cpp:5411
void LookupVisibleDecls(Scope *S, LookupNameKind Kind, VisibleDeclConsumer &Consumer, bool IncludeGlobalScope=true, bool LoadExternal=true)
Definition SemaLookup.cpp:4440
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, QualType ObjectType, bool AllowBuiltinCreation=false, bool EnteringContext=false)
Performs name lookup for a name that was parsed in the source code, and may contain a C++ scope speci...
Definition SemaLookup.cpp:2711
bool hasVisibleMemberSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if there is a visible declaration of D that is a member specialization declaration (as oppo...
Definition SemaLookup.cpp:1825
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, bool AllowExplicitConversion=false, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, ConversionSequenceList EarlyConversions={}, OverloadCandidateParamOrder PO={}, bool AggregateCandidateDeduction=false, bool StrictPackMatch=false)
AddOverloadCandidate - Adds the given function to the set of candidate functions, using the given fun...
bool isReachable(const NamedDecl *D)
Determine whether a declaration is reachable.
llvm::SmallSetVector< DeclContext *, 16 > AssociatedNamespaceSet
CXXMethodDecl * DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl)
Declare the implicit move assignment operator for the given class.
NamedDecl * getCurFunctionOrMethodDecl() const
getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method or C function we're in,...
sema::FunctionScopeInfo * getCurFunction() const
bool isVisible(const NamedDecl *D)
Determine whether a declaration is visible to name lookup.
Module * getCurrentModule() const
Get the module unit whose scope we are currently within.
void NoteOverloadCandidate(const NamedDecl *Found, const FunctionDecl *Fn, OverloadCandidateRewriteKind RewriteKind=OverloadCandidateRewriteKind(), QualType DestType=QualType(), bool TakingAddress=false)
bool hasReachableDefaultArgument(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if the template parameter D has a reachable default argument.
Definition SemaLookup.cpp:1736
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, ArrayRef< Expr * > Args, ADLResult &Functions)
Definition SemaLookup.cpp:3869
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
CXXMethodDecl * LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, bool RValueThis, unsigned ThisQuals)
Look up the moving assignment operator for the given class.
Definition SemaLookup.cpp:3664
CXXMethodDecl * DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl)
Declare the implicit copy assignment operator for the given class.
CXXConstructorDecl * LookupMovingConstructor(CXXRecordDecl *Class, unsigned Quals)
Look up the moving constructor for the given class.
Definition SemaLookup.cpp:3622
bool isAcceptable(const NamedDecl *D, AcceptableKind Kind)
Determine whether a declaration is acceptable (visible/reachable).
CXXMethodDecl * LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, bool RValueThis, unsigned ThisQuals)
Look up the copying assignment operator for the given class.
Definition SemaLookup.cpp:3649
bool isModuleVisible(const Module *M, bool ModulePrivate=false)
Definition SemaLookup.cpp:1932
void AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType, Expr::Classification ObjectClassification, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversion=false, OverloadCandidateParamOrder PO={})
AddMethodCandidate - Adds a named decl (which is some kind of method) as a method candidate to the gi...
bool hasVisibleMergedDefinition(const NamedDecl *Def)
Definition SemaLookup.cpp:1677
void DeclareImplicitDeductionGuides(TemplateDecl *Template, SourceLocation Loc)
Declare implicit deduction guides for a class template if we've not already done so.
void diagnoseEquivalentInternalLinkageDeclarations(SourceLocation Loc, const NamedDecl *D, ArrayRef< const NamedDecl * > Equiv)
llvm::FoldingSet< SpecialMemberOverloadResultEntry > SpecialMemberCache
A cache of special member function overload resolution results for C++ records.
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
LookupOrCreateLabel - Do a name lookup of a label with the specified name.
Definition SemaLookup.cpp:4466
void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, MissingImportKind MIK, bool Recover=true)
Diagnose that the specified declaration needs to be visible but isn't, and suggest a module import th...
Definition SemaLookup.cpp:5662
bool hasReachableMemberSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if there is a reachable declaration of D that is a member specialization declaration (as op...
Definition SemaLookup.cpp:1831
RedeclarationKind forRedeclarationInCurContext() const
Definition SemaLookup.cpp:5846
CXXConstructorDecl * LookupCopyingConstructor(CXXRecordDecl *Class, unsigned Quals)
Look up the copying constructor for the given class.
Definition SemaLookup.cpp:3611
IntrusiveRefCntPtr< ExternalSemaSource > ExternalSource
Source of additional semantic information.
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
Definition SemaLookup.cpp:5636
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
void DiagnoseAmbiguousLookup(LookupResult &Result)
Produce a diagnostic describing the ambiguity that resulted from name lookup.
Definition SemaLookup.cpp:2793
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Definition SemaLookup.cpp:2431
void makeMergedDefinitionVisible(NamedDecl *ND)
Make a merged definition of an existing hidden definition ND visible at the specified location.
Definition SemaLookup.cpp:1557
bool isDependentScopeSpecifier(const CXXScopeSpec &SS)
SourceManager & SourceMgr
bool hasReachableExplicitSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine if there is a reachable declaration of D that is an explicit specialization declaration for...
Definition SemaLookup.cpp:1797
CXXConstructorDecl * DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit copy constructor for the given class.
SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, CXXSpecialMemberKind SM, bool ConstArg, bool VolatileArg, bool RValueThis, bool ConstThis, bool VolatileThis)
Definition SemaLookup.cpp:3382
bool hasAcceptableDefaultArgument(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
Determine if the template parameter D has a reachable default argument.
Definition SemaLookup.cpp:1717
SmallVector< Module *, 16 > CodeSynthesisContextLookupModules
Extra modules inspected when performing a lookup during a template instantiation.
llvm::BumpPtrAllocator BumpAlloc
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, ArrayRef< TemplateArgument > TemplateArgs, sema::TemplateDeductionInfo &Info)
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, AcceptableKind Kind, bool OnlyNeedComplete=false)
LiteralOperatorLookupResult
The possible outcomes of name lookup for a literal operator.
@ LOLR_ErrorNoDiagnostic
The lookup found no match but no diagnostic was issued.
@ LOLR_Raw
The lookup found a single 'raw' literal operator, which expects a string literal containing the spell...
@ LOLR_Error
The lookup resulted in an error.
@ LOLR_Cooked
The lookup found a single 'cooked' literal operator, which expects a normal literal to be built and p...
@ LOLR_StringTemplatePack
The lookup found an overload set of literal operator templates, which expect the character type and c...
@ LOLR_Template
The lookup found an overload set of literal operator templates, which expect the characters of the sp...
void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II)
Called on pragma clang __debug dump II.
Definition SemaLookup.cpp:5832
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
Definition SemaLookup.cpp:2214
IdentifierResolver IdResolver
LabelDecl * LookupExistingLabel(IdentifierInfo *II, SourceLocation IdentLoc)
Perform a name lookup for a label with the specified name; this does not create a new label if the lo...
Definition SemaLookup.cpp:4456
DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class)
Look up the constructors for the given class.
Definition SemaLookup.cpp:3631
CXXDestructorDecl * DeclareImplicitDestructor(CXXRecordDecl *ClassDecl)
Declare the implicit destructor for the given class.
void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, Module *Mod)
Create an implicit import of the given module at the given source location, for error recovery,...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
void dump() const
Dumps the specified AST fragment and all subtrees to llvm::errs().
StringLiteral - This represents a string literal expression, e.g.
Represents the declaration of a struct/union/class/enum.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Location wrapper for a TemplateArgument.
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
Represents a declaration of a type.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
const T * castAs() const
Member-template castAs.
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
QualType getCanonicalTypeInternal() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isAnyPointerType() const
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs'.
Base class for declarations which introduce a typedef-name.
void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass) override
Invoked each time Sema::LookupVisibleDecls() finds a declaration visible from the current scope or co...
Definition SemaLookup.cpp:4644
void addKeywordResult(StringRef Keyword)
Definition SemaLookup.cpp:4671
void addCorrection(TypoCorrection Correction)
Definition SemaLookup.cpp:4700
const TypoCorrection & getNextCorrection()
Return the next typo correction that passes all internal filters and is deemed valid by the consumer'...
Definition SemaLookup.cpp:4792
void FoundName(StringRef Name)
Definition SemaLookup.cpp:4665
void addNamespaces(const llvm::MapVector< NamespaceDecl *, bool > &KnownNamespaces)
Set-up method to add to the consumer the set of namespaces to use in performing corrections to nested...
Definition SemaLookup.cpp:4762
Simple class containing the result of Sema::CorrectTypo.
IdentifierInfo * getCorrectionAsIdentifierInfo() const
ArrayRef< PartialDiagnostic > getExtraDiagnostics() const
static const unsigned InvalidDistance
void addCorrectionDecl(NamedDecl *CDecl)
Add the given NamedDecl to the list of NamedDecls that are the declarations associated with the Decla...
Definition SemaLookup.cpp:5508
void setCorrectionDecls(ArrayRef< NamedDecl * > Decls)
Clears the list of NamedDecls and adds the given set.
std::string getAsString(const LangOptions &LO) const
Definition SemaLookup.cpp:5520
bool requiresImport() const
Returns whether this typo correction is correcting to a declaration that was declared in a module tha...
void setCorrectionRange(CXXScopeSpec *SS, const DeclarationNameInfo &TypoName)
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
SourceRange getCorrectionRange() const
void WillReplaceSpecifier(bool ForceReplacement)
void setCallbackDistance(unsigned ED)
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
unsigned getEditDistance(bool Normalized=true) const
Gets the "edit distance" of the typo correction from the typo.
SmallVectorImpl< NamedDecl * >::iterator decl_iterator
void setRequiresImport(bool Req)
std::string getQuoted(const LangOptions &LO) const
NestedNameSpecifier getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
NamedDecl * getFoundDecl() const
Get the correction declaration found by name lookup (before we looked through using shadow declaratio...
A set of unresolved declarations.
void append(iterator I, iterator E)
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Represents a variable declaration or definition.
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Consumes visible declarations found when searching for all visible names within a given scope or cont...
virtual bool includeHiddenDecls() const
Determine whether hidden declarations (from unimported modules) should be given to this consumer.
Definition SemaLookup.cpp:3995
virtual ~VisibleDeclConsumer()
Destroys the visible declaration consumer.
Definition SemaLookup.cpp:3993
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
Provides information about an attempted template argument deduction, whose success or failure was des...
Defines the clang::TargetInfo interface.
bool Load(InterpState &S, CodePtr OpPC)
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
bool isa(CodeGen::Address addr)
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
@ OR_Deleted
Succeeded, but refers to a deleted function.
@ OR_Success
Overload resolution succeeded.
@ OR_Ambiguous
Ambiguous candidates found.
@ OR_No_Viable_Function
No viable function found.
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ NotFound
No entity found met the criteria.
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
@ Found
Name lookup found a single declaration that met the criteria.
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
@ Redeclaration
Merge availability attributes for a redeclaration, which requires an exact match.
std::unique_ptr< sema::RISCVIntrinsicManager > CreateRISCVIntrinsicManager(Sema &S)
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ AmbiguousBaseSubobjects
Name lookup results in an ambiguity because multiple nonstatic entities that meet the lookup criteria...
@ AmbiguousTagHiding
Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an...
@ AmbiguousReferenceToPlaceholderVariable
Name lookup results in an ambiguity because multiple placeholder variables were found in the same sco...
@ AmbiguousReference
Name lookup results in an ambiguity because multiple definitions of entity that meet the lookup crite...
@ AmbiguousBaseSubobjectTypes
Name lookup results in an ambiguity because multiple entities that meet the lookup criteria were foun...
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
TemplateDecl * getAsTypeTemplateDecl(Decl *D)
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
const FunctionProtoType * T
llvm::Expected< QualType > ExpectedType
@ Template
We are parsing a template declaration.
@ Keyword
The name has been typo-corrected to a keyword.
CXXSpecialMemberKind
Kinds of C++ special members.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
for(const auto &A :T->param_types())
@ Success
Template argument deduction was successful.
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
U cast(CodeGen::Address addr)
ConstructorInfo getConstructorInfo(NamedDecl *ND)
@ None
No keyword precedes the qualified type name.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ EST_None
no exception specification
Represents an element in a path from a derived class to a base class.
int SubobjectNumber
Identifies which base class subobject (of type Base->getType()) this base path element refers to.
const CXXBaseSpecifier * Base
The base specifier that states the link from a derived class to a base class, which will be followed ...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
Extra information about a function prototype.
ExceptionSpecInfo ExceptionSpec
FunctionType::ExtInfo ExtInfo
OverloadExpr * Expression
Describes how types, statements, expressions, and declarations should be printed.