clang: lib/Sema/Sema.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
74#include "llvm/ADT/DenseMap.h"
75#include "llvm/ADT/STLExtras.h"
76#include "llvm/ADT/SmallPtrSet.h"
77#include "llvm/Support/TimeProfiler.h"
78#include
79
80using namespace clang;
81using namespace sema;
82
86
89 bool IncludeComments,
90 std::optionaltok::TokenKind ExpectedToken) {
93 std::optional NextToken =
95 if (!NextToken)
97 if (ExpectedToken && NextToken->getKind() != *ExpectedToken)
103 if (!IncludeMacros && (TokenStart.isMacroID() || TokenEnd.isMacroID()))
105
106 return SourceRange(TokenStart, TokenEnd);
107}
108
110
113 StringRef Platform) {
115 if (!SDKInfo && !WarnedDarwinSDKInfoMissing) {
116 Diag(Loc, diag::warn_missing_sdksettings_for_availability_checking)
117 << Platform;
118 WarnedDarwinSDKInfoMissing = true;
119 }
120 return SDKInfo;
121}
122
124 if (CachedDarwinSDKInfo)
125 return CachedDarwinSDKInfo->get();
127 PP.getFileManager().getVirtualFileSystem(),
128 PP.getHeaderSearchInfo().getHeaderSearchOpts().Sysroot);
129 if (SDKInfo && *SDKInfo) {
130 CachedDarwinSDKInfo = std::make_unique(std::move(**SDKInfo));
131 return CachedDarwinSDKInfo->get();
132 }
133 if (!SDKInfo)
134 llvm::consumeError(SDKInfo.takeError());
135 CachedDarwinSDKInfo = std::unique_ptr();
136 return nullptr;
137}
138
140 const IdentifierInfo *ParamName, unsigned int Index) {
141 std::string InventedName;
142 llvm::raw_string_ostream OS(InventedName);
143
144 if (!ParamName)
145 OS << "auto:" << Index + 1;
146 else
147 OS << ParamName->getName() << ":auto";
148
149 return &Context.Idents.get(OS.str());
150}
151
155
156
157 Policy.Bool = Context.getLangOpts().Bool;
158 if (!Policy.Bool) {
159 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
160 Policy.Bool = BoolMacro->isObjectLike() &&
161 BoolMacro->getNumTokens() == 1 &&
162 BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
163 }
164 }
165
166
168
169 return Policy;
170}
171
176
178namespace sema {
179
181 Sema *S = nullptr;
184
185public:
187
188 void reset() { S = nullptr; }
189
192 FileID PrevFID) override {
193 if (!S)
194 return;
195 switch (Reason) {
199 if (IncludeLoc.isValid()) {
200 if (llvm::timeTraceProfilerEnabled()) {
202 ProfilerStack.push_back(llvm::timeTraceAsyncProfilerBegin(
203 "Source", FE ? FE->getName() : StringRef("")));
204 }
205
206 IncludeStack.push_back(IncludeLoc);
207 S->DiagnoseNonDefaultPragmaAlignPack(
209 IncludeLoc);
210 }
211 break;
212 }
214 if (!IncludeStack.empty()) {
215 if (llvm::timeTraceProfilerEnabled())
216 llvm::timeTraceProfilerEnd(ProfilerStack.pop_back_val());
217
218 S->DiagnoseNonDefaultPragmaAlignPack(
220 IncludeStack.pop_back_val());
221 }
222 break;
223 default:
224 break;
225 }
226 }
229
230
231
232
236 StringRef Group = Str.substr(2);
237
238 if (S->PP.getDiagnostics().getDiagnosticIDs()->getDiagnosticsInGroup(
239 Flavor, Group, GroupDiags))
240 return;
241
243
244
246 S->AnalysisWarnings.getPolicyOverrides();
247 switch (K) {
248 default: break;
249 case diag::warn_unreachable:
250 case diag::warn_unreachable_break:
251 case diag::warn_unreachable_return:
252 case diag::warn_unreachable_loop_increment:
253 Override.enableCheckUnreachable = true;
254 break;
255 case diag::warn_double_lock:
256 Override.enableThreadSafetyAnalysis = true;
257 break;
258 case diag::warn_use_in_invalid_state:
259 Override.enableConsumedAnalysis = true;
260 break;
261 }
262 }
263 }
264};
265
266}
267}
268
271
282 ARMPtr(std::make_unique<SemaARM>(*this)),
283 AVRPtr(std::make_unique<SemaAVR>(*this)),
284 BPFPtr(std::make_unique<SemaBPF>(*this)),
285 CodeCompletionPtr(
287 CUDAPtr(std::make_unique<SemaCUDA>(*this)),
289 HLSLPtr(std::make_unique<SemaHLSL>(*this)),
292 M68kPtr(std::make_unique<SemaM68k>(*this)),
293 MIPSPtr(std::make_unique<SemaMIPS>(*this)),
295 NVPTXPtr(std::make_unique<SemaNVPTX>(*this)),
296 ObjCPtr(std::make_unique<SemaObjC>(*this)),
300 PPCPtr(std::make_unique<SemaPPC>(*this)),
302 RISCVPtr(std::make_unique<SemaRISCV>(*this)),
303 SPIRVPtr(std::make_unique<SemaSPIRV>(*this)),
304 SYCLPtr(std::make_unique<SemaSYCL>(*this)),
305 SwiftPtr(std::make_unique<SemaSwift>(*this)),
307 WasmPtr(std::make_unique<SemaWasm>(*this)),
308 X86Ptr(std::make_unique<SemaX86>(*this)),
310 LangOpts.getMSPointerToMemberRepresentationMethod()),
320 FullyCheckedComparisonCategories(
329
330 LoadedExternalKnownNamespaces = false;
333
336
339
340
342
343
344
345
349
350
351 OpenMP().InitDataSharingAttributesStack();
352
353 std::unique_ptrsema::SemaPPCallbacks Callbacks =
354 std::make_uniquesema::SemaPPCallbacks();
355 SemaPPCallbackHandler = Callbacks.get();
356 PP.addPPCallbacks(std::move(Callbacks));
357 SemaPPCallbackHandler->set(*this);
358
359 CurFPFeatures.setFPEvalMethod(PP.getCurrentFPEvalMethod());
360}
361
362
363void Sema::anchor() {}
364
370
372
373
374
375 if (Context.getTargetInfo().hasBuiltinMSVaList())
376 (void)Context.getBuiltinMSVaListDecl();
377 (void)Context.getBuiltinVaListDecl();
378
380 SC->InitializeSema(*this);
381
382
384 = dyn_cast_or_null(Context.getExternalSource()))
385 ExternalSema->InitializeSema(*this);
386
387
388
390
392 return;
393
394
395 if (Context.getTargetInfo().hasInt128Type() ||
396 (Context.getAuxTargetInfo() &&
397 Context.getAuxTargetInfo()->hasInt128Type())) {
398
399
403
407 }
408
409
410
412
413
417
418
419
423
424
428
429
433 }
434
435
439
440
445
447 }
448
449
450
457 if (OCLCompatibleVersion >= 200) {
461 }
469
470
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486 auto AddPointerSizeDependentTypes = [&]() {
487 auto AtomicSizeT = Context.getAtomicType(Context.getSizeType());
488 auto AtomicIntPtrT = Context.getAtomicType(Context.getIntPtrType());
489 auto AtomicUIntPtrT = Context.getAtomicType(Context.getUIntPtrType());
490 auto AtomicPtrDiffT =
496 };
497
498 if (Context.getTypeSize(Context.getSizeType()) == 32) {
499 AddPointerSizeDependentTypes();
500 }
501
503 auto AtomicHalfT = Context.getAtomicType(Context.HalfTy);
505 }
506
507 std::vector Atomic64BitTypes;
508 if (getOpenCLOptions().isSupported("cl_khr_int64_base_atomics",
510 getOpenCLOptions().isSupported("cl_khr_int64_extended_atomics",
513 auto AtomicDoubleT = Context.getAtomicType(Context.DoubleTy);
515 Atomic64BitTypes.push_back(AtomicDoubleT);
516 }
517 auto AtomicLongT = Context.getAtomicType(Context.LongTy);
518 auto AtomicULongT = Context.getAtomicType(Context.UnsignedLongTy);
521
522
523 if (Context.getTypeSize(Context.getSizeType()) == 64) {
524 AddPointerSizeDependentTypes();
525 }
526 }
527 }
528
529#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
530 if (getOpenCLOptions().isSupported(#Ext, getLangOpts())) { \
531 addImplicitTypedef(#ExtType, Context.Id##Ty); \
532 }
533#include "clang/Basic/OpenCLExtensionTypes.def"
534 }
535
536 if (Context.getTargetInfo().hasAArch64ACLETypes() ||
537 (Context.getAuxTargetInfo() &&
538 Context.getAuxTargetInfo()->hasAArch64ACLETypes())) {
539#define SVE_TYPE(Name, Id, SingletonId) \
540 addImplicitTypedef(#Name, Context.SingletonId);
541#define NEON_VECTOR_TYPE(Name, BaseType, ElBits, NumEls, VectorKind) \
542 addImplicitTypedef( \
543 #Name, Context.getVectorType(Context.BaseType, NumEls, VectorKind));
544#include "clang/Basic/AArch64ACLETypes.def"
545 }
546
547 if (Context.getTargetInfo().getTriple().isPPC64()) {
548#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
549 addImplicitTypedef(#Name, Context.Id##Ty);
550#include "clang/Basic/PPCTypes.def"
551#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
552 addImplicitTypedef(#Name, Context.Id##Ty);
553#include "clang/Basic/PPCTypes.def"
554 }
555
556 if (Context.getTargetInfo().hasRISCVVTypes()) {
557#define RVV_TYPE(Name, Id, SingletonId) \
558 addImplicitTypedef(Name, Context.SingletonId);
559#include "clang/Basic/RISCVVTypes.def"
560 }
561
562 if (Context.getTargetInfo().getTriple().isWasm() &&
563 Context.getTargetInfo().hasFeature("reference-types")) {
564#define WASM_TYPE(Name, Id, SingletonId) \
565 addImplicitTypedef(Name, Context.SingletonId);
566#include "clang/Basic/WebAssemblyReferenceTypes.def"
567 }
568
569 if (Context.getTargetInfo().getTriple().isAMDGPU() ||
570 (Context.getAuxTargetInfo() &&
571 Context.getAuxTargetInfo()->getTriple().isAMDGPU())) {
572#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
573 addImplicitTypedef(Name, Context.SingletonId);
574#include "clang/Basic/AMDGPUTypes.def"
575 }
576
577 if (Context.getTargetInfo().hasBuiltinMSVaList()) {
581 }
582
586}
587
590 "failed to clean up an InstantiatingTemplate?");
591
593
594
596 delete FSI;
597
598
600 SC->ForgetSema();
601
602
604 = dyn_cast_or_null(Context.getExternalSource()))
605 ExternalSema->ForgetSema();
606
607
608 std::vector<ConstraintSatisfaction *> Satisfactions;
609 Satisfactions.reserve(SatisfactionCache.size());
610 for (auto &Node : SatisfactionCache)
611 Satisfactions.push_back(&Node);
612 for (auto *Node : Satisfactions)
613 delete Node;
614
616
617
618 OpenMP().DestroyDataSharingAttributesStack();
619
620
621
622 SemaPPCallbackHandler->reset();
623}
624
626 llvm::function_ref<void()> Fn) {
627 StackHandler.runWithSufficientStackSpace(Loc, Fn);
628}
629
631 UnavailableAttr::ImplicitReason reason) {
632
634 if (!fn) return false;
635
636
638 return false;
639
640
641 if (.getSourceManager().isInSystemHeader(loc))
642 return false;
643
644
645 if (fn->hasAttr()) return true;
646
647 fn->addAttr(UnavailableAttr::CreateImplicit(Context, "", reason, loc));
648 return true;
649}
650
654
656 assert(E && "Cannot use with NULL ptr");
657
660 return;
661 }
662
663 if (auto *Ex = dyn_cast(ExternalSource.get()))
664 Ex->AddSource(std::move(E));
665 else
666 ExternalSource = llvm::makeIntrusiveRefCnt(
668}
669
671 llvm::errs() << "\n*** Semantic Analysis Stats:\n";
673 llvm::errs() << int(Trap->hasErrorOccurred())
674 << " SFINAE diagnostics trapped.\n";
675
678}
679
683 std::optional ExprNullability = SrcType->getNullability();
686 return;
687
688 std::optional TypeNullability = DstType->getNullability();
690 return;
691
692 Diag(Loc, diag::warn_nullability_lost) << SrcType << DstType;
693}
694
695
700 if (SrcFX != DstFX) {
702 if (Diff.shouldDiagnoseConversion(SrcType, SrcFX, DstType, DstFX))
703 Diag(Loc, diag::warn_invalid_add_func_effects) << Diff.effectName();
704 }
705 }
706}
707
709
711 return;
712
713 if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
714 return;
715
718 return;
720 return;
721
722 if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
724 return;
725
726
727
731 return;
732
733
736 return;
737 }
738
739
740
741
742
744 if (Diags.getSuppressSystemWarnings() &&
745 SourceMgr.isInSystemMacro(MaybeMacroLoc) &&
747 return;
748
749 Diag(E->getBeginLoc(), diag::warn_zero_as_null_pointer_constant)
751}
752
753
754
755
760#ifndef NDEBUG
762 switch (Kind) {
763 default:
764 llvm_unreachable(
765 ("can't implicitly cast glvalue to prvalue with this cast "
766 "kind: " +
768 .c_str());
769 case CK_Dependent:
770 case CK_LValueToRValue:
771 case CK_ArrayToPointerDecay:
772 case CK_FunctionToPointerDecay:
773 case CK_ToVoid:
774 case CK_NonAtomicToAtomic:
775 case CK_HLSLArrayRValue:
776 case CK_HLSLAggregateSplatCast:
777 break;
778 }
779 }
781 "can't cast prvalue to glvalue");
782#endif
783
786 if (Context.hasAnyFunctionEffects() && (CCK) &&
787 Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
789
792
793
794
795
796
797
801
802 if (ExprTy == TypeTy)
803 return E;
804
805 if (Kind == CK_ArrayToPointerDecay) {
806
807
809
814 E = Materialized.get();
815 }
816
817
818
819
820
821
822
823
825 if (const auto *DRE = dyn_cast(E)) {
826 if (const auto *VD = dyn_cast(DRE->getDecl())) {
827 if (VD->getStorageClass() == SC_Register) {
828 Diag(E->getExprLoc(), diag::err_typecheck_address_of)
831 }
832 }
833 }
834 }
835 }
836
837 if (ImplicitCastExpr *ImpCast = dyn_cast(E)) {
838 if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) {
839 ImpCast->setType(Ty);
840 ImpCast->setValueKind(VK);
841 return E;
842 }
843 }
844
847}
848
861 }
862 llvm_unreachable("unknown scalar type kind");
863}
864
865
868 return true;
869
871 return true;
872
873 if (const FunctionDecl *FD = dyn_cast(D)) {
874
875
877 for (const auto *Spec : Template->specializations())
879 return true;
880
881
882
884 if (FD->hasBody(DeclToCheck))
886
887
888
890 if (DeclToCheck != FD)
892 }
893
894 if (const VarDecl *VD = dyn_cast(D)) {
895
896
897
898
899
900 if (VD->isReferenced() &&
901 VD->mightBeUsableInConstantExpressions(SemaRef->Context))
902 return true;
903
905
906
907 for (const auto *Spec : Template->specializations())
909 return true;
910
911
912
914 if (DeclToCheck)
916
917
918
920 if (DeclToCheck != VD)
922 }
923
924 return false;
925}
926
928 if (const auto *FD = dyn_cast(ND))
929 return FD->isExternC();
931}
932
933
934
943
944
945
949 NamedDecl *ND = UndefinedUse.first;
950
951
953
954
955 if (ND->hasAttr()) continue;
956
958 continue;
959
960 if (ND->hasAttr() || ND->hasAttr()) {
961
962
963
964 continue;
965 }
966
967 if (const auto *FD = dyn_cast(ND)) {
968 if (FD->isDefined())
969 continue;
970 if (FD->isExternallyVisible() &&
972 !FD->getMostRecentDecl()->isInlined() &&
973 !FD->hasAttr())
974 continue;
975 if (FD->getBuiltinID())
976 continue;
977 } else {
980 continue;
981 if (VD->isExternallyVisible() &&
983 !VD->getMostRecentDecl()->isInline() &&
984 !VD->hasAttr())
985 continue;
986
987
988
989 if (VD->isKnownToBeDefined())
990 continue;
991 }
992
993 Undefined.push_back(std::make_pair(ND, UndefinedUse.second));
994 }
995}
996
997
998
1001
1002
1007
1008 for (const auto &Undef : Undefined) {
1011
1013
1014
1015
1016
1017
1018
1019
1020
1021
1023 ? diag::ext_undefined_internal_type
1024 : diag::err_undefined_internal_type)
1027
1028
1029
1030 bool IsImplicitBase = false;
1031 if (const auto *BaseD = dyn_cast(VD)) {
1032 auto *DVAttr = BaseD->getAttr();
1033 if (DVAttr && !DVAttr->getTraitInfo().isExtensionActive(
1034 llvm::omp::TraitProperty::
1035 implementation_extension_disable_implicit_base)) {
1038 IsImplicitBase = BaseD->isImplicit() &&
1039 Func->getIdentifier()->isMangledOpenMPVariantName();
1040 }
1041 }
1042 if (!S.getLangOpts().OpenMP || !IsImplicitBase)
1043 S.Diag(VD->getLocation(), diag::warn_undefined_internal)
1045 } else if (auto *FD = dyn_cast(VD)) {
1046 (void)FD;
1047 assert(FD->getMostRecentDecl()->isInlined() &&
1048 "used object requires definition but isn't inline or internal?");
1049
1050 S.Diag(VD->getLocation(), diag::warn_undefined_inline) << VD;
1051 } else {
1052 assert(cast(VD)->getMostRecentDecl()->isInline() &&
1053 "used var requires definition but isn't inline or internal?");
1054 S.Diag(VD->getLocation(), diag::err_undefined_inline_var) << VD;
1055 }
1057 S.Diag(UseLoc, diag::note_used_here);
1058 }
1059}
1060
1063 return;
1064
1066 ExternalSource->ReadWeakUndeclaredIdentifiers(WeakIDs);
1067 for (auto &WeakID : WeakIDs)
1069}
1070
1071
1073
1074
1075
1076
1077
1078
1081 RecordCompleteMap::iterator Cache = MNCComplete.find(RD);
1082 if (Cache != MNCComplete.end())
1083 return Cache->second;
1085 return false;
1090 if (const CXXMethodDecl *M = dyn_cast(*I))
1091 Complete = M->isDefined() || M->isDefaulted() ||
1093 else if (const FunctionTemplateDecl *F = dyn_cast(*I))
1094
1095
1096
1097
1098 Complete = !F->getTemplatedDecl()->isLateTemplateParsed() &&
1099 F->getTemplatedDecl()->isDefined();
1100 else if (const CXXRecordDecl *R = dyn_cast(*I)) {
1101 if (R->isInjectedClassName())
1102 continue;
1103 if (R->hasDefinition())
1105 MNCComplete);
1106 else
1108 }
1109 }
1112}
1113
1114
1115
1116
1117
1118
1119
1120
1124 RecordCompleteMap::iterator Cache = RecordsComplete.find(RD);
1125 if (Cache != RecordsComplete.end())
1126 return Cache->second;
1131
1133
1134 if (CXXRecordDecl *FriendD = TSI->getType()->getAsCXXRecordDecl())
1136 else
1138 } else {
1139
1141 dyn_cast((*I)->getFriendDecl()))
1143 else
1144
1146 }
1147 }
1148 RecordsComplete[RD] = Complete;
1150}
1151
1154 ExternalSource->ReadUnusedLocalTypedefNameCandidates(
1157 if (TD->isReferenced())
1158 continue;
1159 Diag(TD->getLocation(), diag::warn_unused_local_typedef)
1161 }
1163}
1164
1168 HandleStartOfHeaderUnit();
1169}
1170
1173
1174
1175 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
1177 return;
1178 }
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1193
1194
1195
1196
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1209
1212 for (auto PII : Pending)
1213 if (auto Func = dyn_cast(PII.first))
1214 Func->setInstantiationIsPending(true);
1216 Pending.begin(), Pending.end());
1217 }
1218
1219 {
1220 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
1222 }
1223
1225
1227 "end of TU template instantiation should not create more "
1228 "late-parsed templates");
1229}
1230
1233 && "reached end of translation unit with a pool attached?");
1234
1235
1236
1237 if (PP.isCodeCompletionEnabled())
1238 return;
1239
1240
1241
1244
1246 !ModuleScopes.empty() && ModuleScopes.back().Module->Kind ==
1250
1252 } else {
1253
1254
1255
1256
1257
1262
1263 if (LangOpts.PCHInstantiateTemplates) {
1264 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
1266 }
1267 }
1268
1273
1274
1275
1278
1279
1282
1283
1288 return ShouldRemoveFromUnused(this, DD);
1289 }),
1291
1293
1294 if (.isIncrementalProcessingEnabled())
1296 return;
1297 }
1298
1299
1302 if (WeakIDs.second.empty())
1303 continue;
1304
1307 if (PrevDecl != nullptr &&
1309 for (const auto &WI : WeakIDs.second)
1310 Diag(WI.getLocation(), diag::warn_attribute_wrong_decl_type)
1312 else
1313 for (const auto &WI : WeakIDs.second)
1314 Diag(WI.getLocation(), diag::warn_weak_identifier_undeclared)
1315 << WeakIDs.first;
1316 }
1317
1321
1322 if (.hasErrorOccurred()) {
1326 }
1327
1328
1329 if (!ModuleScopes.empty() && ModuleScopes.back().Module->Kind ==
1331 Diag(ModuleScopes.back().BeginLoc,
1332 diag::err_module_declaration_missing_after_global_module_introducer);
1333 } else if (getLangOpts().getCompilingModule() ==
1335
1336
1338
1339
1340
1341
1344 diag::err_module_declaration_missing);
1345 }
1346
1347
1350 auto DoesModNeedInit = [this](Module *M) {
1351 if (().getModuleInitializers(M).empty())
1352 return true;
1353 for (auto [Exported, _] : M->Exports)
1354 if (Exported->isNamedModuleInterfaceHasInit())
1355 return true;
1358 return true;
1359
1360 return false;
1361 };
1362
1363 CurrentModule->NamedModuleHasInit =
1364 DoesModNeedInit(CurrentModule) ||
1365 llvm::any_of(CurrentModule->submodules(), DoesModNeedInit);
1366 }
1367
1369
1370
1371 if (Module *CurrentModule = PP.getCurrentModule()) {
1372 ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap();
1373
1375 Stack.push_back(CurrentModule);
1376 while (!Stack.empty()) {
1377 Module *Mod = Stack.pop_back_val();
1378
1379
1380
1381
1382
1384 ModMap.resolveUses(Mod, false);
1386
1387
1388 auto SubmodulesRange = Mod->submodules();
1389 Stack.append(SubmodulesRange.begin(), SubmodulesRange.end());
1390 }
1391 }
1392
1393
1394
1396 }
1397
1398
1399
1400
1401 if (!PendingInlineFuncDecls.empty()) {
1402 for (auto *D : PendingInlineFuncDecls) {
1403 if (auto *FD = dyn_cast(D)) {
1404 bool DefInPMF = false;
1405 if (auto *FDD = FD->getDefinition()) {
1406 DefInPMF = FDD->getOwningModule()->isPrivateModule();
1407 if (!DefInPMF)
1408 continue;
1409 }
1410 Diag(FD->getLocation(), diag::err_export_inline_not_defined)
1411 << DefInPMF;
1412
1413 if (DefInPMF &&
1415 Diag(ModuleScopes.back().BeginLoc,
1416 diag::note_private_module_fragment);
1417 }
1418 }
1419 }
1420 PendingInlineFuncDecls.clear();
1421 }
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1435 for (TentativeDefinitionsType::iterator
1440
1441
1442
1443
1444 if (!VD || VD->isInvalidDecl() || !Seen.insert(VD).second)
1445 continue;
1446
1448 = Context.getAsIncompleteArrayType(VD->getType())) {
1449
1450 Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
1451 llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true);
1456 diag::err_tentative_def_incomplete_type))
1458
1459
1461
1462
1463
1467 unsigned DiagID = diag::warn_default_init_const_unsafe;
1470 DiagID = diag::warn_default_init_const;
1471
1472 bool EmitCppCompat = .isIgnored(
1473 diag::warn_cxx_compat_hack_fake_diagnostic_do_not_emit,
1475
1477 }
1478
1479
1481 Consumer.CompleteTentativeDefinition(VD);
1482 }
1483
1484
1485
1486
1487 if (PP.isIncrementalProcessingEnabled())
1490
1492 if (!D || D->isInvalidDecl() || D->getPreviousDecl() || !D->isUsed())
1493 continue;
1494
1495 Consumer.CompleteExternalDeclaration(D);
1496 }
1497
1503
1504
1505
1506
1507
1509
1510 for (UnusedFileScopedDeclsType::iterator
1513 I != E; ++I) {
1515 continue;
1516
1517 if (const FunctionDecl *FD = dyn_cast(*I)) {
1519 if (!FD->hasBody(DiagD))
1520 DiagD = FD;
1522 continue;
1526 DiagRange.setEnd(ASTTAL->RAngleLoc);
1529 Diag(DiagD->getLocation(), diag::warn_unneeded_member_function)
1530 << DiagD << DiagRange;
1531 else {
1532 if (FD->getStorageClass() == SC_Static &&
1533 !FD->isInlineSpecified() &&
1535 SourceMgr.getExpansionLoc(FD->getLocation())))
1537 diag::warn_unneeded_static_internal_decl)
1538 << DiagD << DiagRange;
1539 else
1540 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
1541 << 0 << DiagD << DiagRange;
1542 }
1543 } else if (!FD->isTargetMultiVersion() ||
1544 FD->isTargetMultiVersionDefault()) {
1545 if (FD->getDescribedFunctionTemplate())
1547 << 0 << DiagD << DiagRange;
1548 else
1550 ? diag::warn_unused_member_function
1551 : diag::warn_unused_function)
1552 << DiagD << DiagRange;
1553 }
1554 } else {
1556 if (!DiagD)
1559 if (const auto *VTSD = dyn_cast(DiagD)) {
1561 VTSD->getTemplateArgsAsWritten())
1562 DiagRange.setEnd(ASTTAL->RAngleLoc);
1563 }
1565 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
1566 << 1 << DiagD << DiagRange;
1569 << 1 << DiagD << DiagRange;
1572 if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) ||
1573 .getLangOpts().IsHeaderFile)
1574 Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
1575 << DiagD << DiagRange;
1576 } else {
1578 << DiagD << DiagRange;
1579 }
1580 }
1581 }
1582
1584 }
1585
1586 if (.isIgnored(diag::warn_unused_private_field, SourceLocation())) {
1587
1588
1592 const CXXRecordDecl *RD = dyn_cast(D->getDeclContext());
1593 if (RD && !RD->isUnion() &&
1595 Diag(D->getLocation(), diag::warn_unused_private_field)
1596 << D->getDeclName();
1597 }
1598 }
1599 }
1600
1601 if (.isIgnored(diag::warn_mismatched_delete_new, SourceLocation())) {
1604 for (const auto &DeletedFieldInfo : DeleteExprs) {
1605 for (const auto &DeleteExprLoc : DeletedFieldInfo.second) {
1606 AnalyzeDeleteExprMismatch(DeletedFieldInfo.first, DeleteExprLoc.first,
1608 }
1609 }
1610 }
1611
1613
1614 if (Context.hasAnyFunctionEffects())
1616
1617
1618
1619
1621 "Didn't unmark var as having its initializer parsed");
1622
1623 if (.isIncrementalProcessingEnabled())
1625
1626 checkExposure(Context.getTranslationUnitDecl());
1627}
1628
1629
1630
1631
1632
1633
1636
1637 while (true) {
1645 } else break;
1646 }
1647
1648 return DC;
1649}
1650
1651
1652
1653
1656 return dyn_cast(DC);
1657}
1658
1663 return dyn_cast(DC);
1664}
1665
1670 return nullptr;
1671}
1672
1678
1680
1681
1682
1683
1684
1685
1686
1692
1693 break;
1694
1696
1697
1698 Trap->setErrorOccurred();
1699
1700
1701
1706
1707 Diags.setLastDiagnosticIgnored(true);
1708 return;
1709
1711
1712
1713
1714
1716 break;
1717
1719
1720
1721 Trap->setErrorOccurred();
1722
1723
1724
1729
1730 Diags.setLastDiagnosticIgnored(true);
1731
1732
1733 Diag(Loc, diag::warn_cxx98_compat_sfinae_access_control);
1734
1735
1736
1737 Diags.setLastDiagnosticIgnored(true);
1738 return;
1739 }
1740
1745 return;
1746
1747
1748 if (Info) {
1752 if (.getDiagnosticIDs()->isNote(DiagID))
1755 });
1756 }
1757
1758
1759 Diags.setLastDiagnosticIgnored(true);
1760 return;
1761 }
1762 }
1763
1764
1765
1767
1768
1769 if (.EmitDiagnostic(DB))
1770 return;
1771
1772
1773
1774
1775
1776 if (.getDiagnosticIDs()->isNote(DiagID))
1778}
1779
1782 return true;
1783 auto *FD = dyn_cast(CurContext);
1784 if (!FD)
1785 return false;
1788 return false;
1789 for (auto PDAt : Loc->second) {
1790 if (Diags.getDiagnosticIDs()->isDefaultMappingAsError(
1791 PDAt.second.getDiagID()))
1792 return true;
1793 }
1794 return false;
1795}
1796
1797
1798
1802
1804 return;
1806 S.Diags.Report(FnIt->second.Loc, diag::note_called_by));
1807 Builder << FnIt->second.FD;
1809 }
1810}
1811
1812namespace {
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841class DeferredDiagnosticsEmitter
1843public:
1844 typedef UsedDeclVisitor Inherited;
1845
1846
1847 llvm::SmallPtrSet<CanonicalDeclPtr, 4> InUsePath;
1848
1849
1850 llvm::SmallVector<CanonicalDeclPtr, 4> UsePath;
1851
1852
1853
1854
1855
1856 llvm::SmallPtrSet<CanonicalDeclPtr, 4> DoneMap[2];
1857
1858
1859 bool ShouldEmitRootNode;
1860
1861
1862
1863
1864 unsigned InOMPDeviceContext;
1865
1866 DeferredDiagnosticsEmitter(Sema &S)
1867 : Inherited(S), ShouldEmitRootNode(false), InOMPDeviceContext(0) {}
1868
1869 bool shouldVisitDiscardedStmt() const { return false; }
1870
1871 void VisitOMPTargetDirective(OMPTargetDirective *Node) {
1872 ++InOMPDeviceContext;
1873 Inherited::VisitOMPTargetDirective(Node);
1874 --InOMPDeviceContext;
1875 }
1876
1877 void visitUsedDecl(SourceLocation Loc, Decl *D) {
1879 return;
1880 if (auto *FD = dyn_cast(D))
1881 checkFunc(Loc, FD);
1882 else
1883 Inherited::visitUsedDecl(Loc, D);
1884 }
1885
1886
1887 void VisitCalledDestructors(CXXDestructorDecl *DD) {
1888 const CXXRecordDecl *RD = DD->getParent();
1889
1890
1891 for (const FieldDecl *FD : RD->fields()) {
1892 QualType FT = FD->getType();
1894 ClassDecl &&
1895 (ClassDecl->isBeingDefined() || ClassDecl->isCompleteDefinition()))
1896 if (CXXDestructorDecl *MemberDtor = ClassDecl->getDestructor())
1897 asImpl().visitUsedDecl(MemberDtor->getLocation(), MemberDtor);
1898 }
1899
1900
1901 for (const auto &Base : RD->bases()) {
1902 QualType BaseType = Base.getType();
1904 BaseDecl &&
1905 (BaseDecl->isBeingDefined() || BaseDecl->isCompleteDefinition()))
1906 if (CXXDestructorDecl *BaseDtor = BaseDecl->getDestructor())
1907 asImpl().visitUsedDecl(BaseDtor->getLocation(), BaseDtor);
1908 }
1909 }
1910
1911 void VisitDeclStmt(DeclStmt *DS) {
1912
1913 for (auto *D : DS->decls())
1914 if (auto *VD = dyn_cast(D))
1915 if (VD->isThisDeclarationADefinition() &&
1916 VD->needsDestruction(S.Context)) {
1917 QualType VT = VD->getType();
1919 ClassDecl && (ClassDecl->isBeingDefined() ||
1920 ClassDecl->isCompleteDefinition()))
1921 if (CXXDestructorDecl *Dtor = ClassDecl->getDestructor())
1922 asImpl().visitUsedDecl(Dtor->getLocation(), Dtor);
1923 }
1924
1925 Inherited::VisitDeclStmt(DS);
1926 }
1927 void checkVar(VarDecl *VD) {
1929 "Should only check file-scope variables");
1931 auto DevTy = OMPDeclareTargetDeclAttr::getDeviceType(VD);
1932 bool IsDev = DevTy && (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost ||
1933 *DevTy == OMPDeclareTargetDeclAttr::DT_Any);
1934 if (IsDev)
1935 ++InOMPDeviceContext;
1936 this->Visit(Init);
1937 if (IsDev)
1938 --InOMPDeviceContext;
1939 }
1940 }
1941
1942 void checkFunc(SourceLocation Loc, FunctionDecl *FD) {
1943 auto &Done = DoneMap[InOMPDeviceContext > 0 ? 1 : 0];
1944 FunctionDecl *Caller = UsePath.empty() ? nullptr : UsePath.back();
1945 if ((!ShouldEmitRootNode && !S.getLangOpts().OpenMP && !Caller) ||
1946 S.shouldIgnoreInHostDeviceCheck(FD) || InUsePath.count(FD))
1947 return;
1948
1949 if (Caller && S.LangOpts.OpenMP && UsePath.size() == 1 &&
1950 (ShouldEmitRootNode || InOMPDeviceContext))
1951 S.OpenMP().finalizeOpenMPDelayedAnalysis(Caller, FD, Loc);
1952 if (Caller)
1953 S.CUDA().DeviceKnownEmittedFns[FD] = {Caller, Loc};
1954
1955
1956
1957 if (ShouldEmitRootNode || InOMPDeviceContext)
1958 emitDeferredDiags(FD, Caller);
1959
1960
1961 if (!Done.insert(FD).second)
1962 return;
1963 InUsePath.insert(FD);
1964 UsePath.push_back(FD);
1965 if (auto *S = FD->getBody()) {
1966 this->Visit(S);
1967 }
1968 if (CXXDestructorDecl *Dtor = dyn_cast(FD))
1969 asImpl().VisitCalledDestructors(Dtor);
1970 UsePath.pop_back();
1971 InUsePath.erase(FD);
1972 }
1973
1974 void checkRecordedDecl(Decl *D) {
1975 if (auto *FD = dyn_cast(D)) {
1976 ShouldEmitRootNode = S.getEmissionStatus(FD, true) ==
1977 Sema::FunctionEmissionStatus::Emitted;
1978 checkFunc(SourceLocation(), FD);
1979 } else
1981 }
1982
1983
1984 void emitDeferredDiags(FunctionDecl *FD, bool ShowCallStack) {
1985 auto It = S.DeviceDeferredDiags.find(FD);
1986 if (It == S.DeviceDeferredDiags.end())
1987 return;
1988 bool HasWarningOrError = false;
1989 bool FirstDiag = true;
1991
1992 if (S.Diags.hasFatalErrorOccurred())
1993 return;
1994 const SourceLocation &Loc = PDAt.first;
1995 const PartialDiagnostic &PD = PDAt.second;
1996 HasWarningOrError |=
1997 S.getDiagnostics().getDiagnosticLevel(PD.getDiagID(), Loc) >=
1999 {
2000 DiagnosticBuilder Builder(S.Diags.Report(Loc, PD.getDiagID()));
2001 PD.Emit(Builder);
2002 }
2003
2004
2005 if (FirstDiag && HasWarningOrError && ShowCallStack) {
2007 FirstDiag = false;
2008 }
2009 }
2010 }
2011};
2012}
2013
2018
2021 return;
2022
2023 DeferredDiagnosticsEmitter DDE(*this);
2025 DDE.checkRecordedDecl(D);
2026}
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(Kind K, SourceLocation Loc,
2053 unsigned DiagID,
2056 : S(S), Loc(Loc), DiagID(DiagID), Fn(Fn),
2057 ShowCallStack(K == K_ImmediateWithCallStack || K == K_Deferred) {
2058 switch (K) {
2059 case K_Nop:
2060 break;
2061 case K_Immediate:
2062 case K_ImmediateWithCallStack:
2063 ImmediateDiag.emplace(
2064 ImmediateDiagBuilder(S.Diags.Report(Loc, DiagID), S, DiagID));
2065 break;
2066 case K_Deferred:
2067 assert(Fn && "Must have a function to attach the deferred diag to.");
2069 PartialDiagId.emplace(Diags.size());
2070 Diags.emplace_back(Loc, S.PDiag(DiagID));
2071 break;
2072 }
2073}
2074
2075Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D)
2076 : S(D.S), Loc(D.Loc), DiagID(D.DiagID), Fn(D.Fn),
2077 ShowCallStack(D.ShowCallStack), ImmediateDiag(D.ImmediateDiag),
2078 PartialDiagId(D.PartialDiagId) {
2079
2080 D.ShowCallStack = false;
2081 D.ImmediateDiag.reset();
2082 D.PartialDiagId.reset();
2083}
2084
2085Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() {
2086 if (ImmediateDiag) {
2087
2088
2089 ImmediateDiag.reset();
2090
2091 if (ShowCallStack) {
2092 bool IsWarningOrError = S.getDiagnostics().getDiagnosticLevel(
2094 if (IsWarningOrError)
2096 }
2097 } else {
2098 assert((!PartialDiagId || ShowCallStack) &&
2099 "Must always show call stack for deferred diags.");
2100 }
2101}
2102
2103Sema::SemaDiagnosticBuilder
2107 return LangOpts.OpenMPIsTargetDevice
2108 ? OpenMP().diagIfOpenMPDeviceCode(Loc, DiagID, FD)
2109 : OpenMP().diagIfOpenMPHostCode(Loc, DiagID, FD);
2111 return getLangOpts().CUDAIsDevice ? CUDA().DiagIfDeviceCode(Loc, DiagID)
2112 : CUDA().DiagIfHostCode(Loc, DiagID);
2113
2115 return SYCL().DiagIfDeviceCode(Loc, DiagID);
2116
2118 FD, *this);
2119}
2120
2123 return;
2124
2125
2126
2127
2128
2129 if (D && LangOpts.SYCLIsDevice) {
2130 llvm::DenseSet Visited;
2131 SYCL().deepTypeCheckForDevice(Loc, Visited, D);
2132 }
2133
2135
2136
2137
2138 if (const auto *MD = dyn_cast(C)) {
2139 if ((MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()) &&
2140 MD->isTrivial())
2141 return;
2142
2143 if (const auto *Ctor = dyn_cast(MD))
2144 if (Ctor->isCopyOrMoveConstructor() && Ctor->isTrivial())
2145 return;
2146 }
2147
2148
2149
2152 : dyn_cast_or_null(D);
2153
2154 auto CheckDeviceType = [&](QualType Ty) {
2156 return;
2157
2159 if (.getTargetInfo().hasBitIntType()) {
2161 if (D)
2162 PD << D;
2163 else
2164 PD << "expression";
2166 << false << 0 << false
2167 << Ty << Context.getTargetInfo().getTriple().str();
2168 }
2169 return;
2170 }
2171
2172
2173
2174 bool LongDoubleMismatched = false;
2176 const llvm::fltSemantics &Sem = Context.getFloatTypeSemantics(Ty);
2177 if ((&Sem != &llvm::APFloat::PPCDoubleDouble() &&
2178 .getTargetInfo().hasFloat128Type()) ||
2179 (&Sem == &llvm::APFloat::PPCDoubleDouble() &&
2180 .getTargetInfo().hasIbm128Type()))
2181 LongDoubleMismatched = true;
2182 }
2183
2188 .getTargetInfo().hasInt128Type()) ||
2191 LongDoubleMismatched) {
2193 if (D)
2194 PD << D;
2195 else
2196 PD << "expression";
2197
2199 << true
2200 << static_cast<unsigned>(Context.getTypeSize(Ty)) << Ty
2201 << false << Context.getTargetInfo().getTriple().str()) {
2202 if (D)
2203 D->setInvalidDecl();
2204 }
2205 if (D)
2206 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2207 }
2208 };
2209
2210 auto CheckType = [&](QualType Ty, bool IsRetTy = false) {
2211 if (LangOpts.SYCLIsDevice ||
2214 CheckDeviceType(Ty);
2215
2220 if (D)
2221 PD << D;
2222 else
2223 PD << "expression";
2224
2225 if (Diag(Loc, PD) << false << 0 << Ty
2226 << false
2228 if (D)
2229 D->setInvalidDecl();
2230 }
2231 if (D)
2232 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2233 }
2234
2235 bool IsDouble = UnqualTy == Context.DoubleTy;
2236 bool IsFloat = UnqualTy == Context.FloatTy;
2237 if (IsRetTy && !TI.hasFPReturn() && (IsDouble || IsFloat)) {
2239 if (D)
2240 PD << D;
2241 else
2242 PD << "expression";
2243
2244 if (Diag(Loc, PD) << false << 0 << Ty << true
2246 if (D)
2247 D->setInvalidDecl();
2248 }
2249 if (D)
2250 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2251 }
2252
2254 llvm::StringMap CallerFeatureMap;
2255 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
2256 RISCV().checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
2257 }
2258
2259
2261 llvm::StringMap CallerFeatureMap;
2262 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
2263 ARM().checkSVETypeSupport(Ty, Loc, FD, CallerFeatureMap);
2264 }
2265
2267 VT && FD &&
2273 Diag(Loc, diag::err_sve_fixed_vector_in_streaming_function)
2274 << Ty << 0;
2276 if (FTy->getAArch64SMEAttributes() &
2278 Diag(Loc, diag::err_sve_fixed_vector_in_streaming_function)
2279 << Ty << 1;
2280 }
2281 }
2282 }
2283 };
2284
2285 CheckType(Ty);
2286 if (const auto *FPTy = dyn_cast(Ty)) {
2287 for (const auto &ParamTy : FPTy->param_types())
2288 CheckType(ParamTy);
2289 CheckType(FPTy->getReturnType(), true);
2290 }
2291 if (const auto *FNPTy = dyn_cast(Ty))
2292 CheckType(FNPTy->getReturnType(), true);
2293}
2294
2297 if (!loc.isMacroID()) return false;
2298
2299
2300
2302
2303
2305 if (getPreprocessor().getSpelling(loc, buffer) == name) {
2306 locref = loc;
2307 return true;
2308 }
2309 return false;
2310}
2311
2313
2314 if (!Ctx)
2315 return nullptr;
2316
2319
2320
2322 if (DeclContext *Entity = S->getEntity())
2324 return S;
2325 }
2326
2327 return nullptr;
2328}
2329
2330
2333
2336 } else {
2338 }
2340 OpenMP().pushOpenMPFunctionRegion();
2341}
2342
2345 BlockScope, Block));
2347}
2348
2355
2358 LSI->AutoTemplateParameterDepth = Depth;
2359 return;
2360 }
2361 llvm_unreachable(
2362 "Remove assertion if intentionally called in a non-lambda context.");
2363}
2364
2365
2366
2367
2368
2369
2375 Expr *VarRef =
2383 } else {
2386 VarRef);
2387 }
2388
2389 if (!Result.isInvalid()) {
2393 }
2394
2395
2396
2397 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
2401 }
2402}
2403
2405
2406
2409 VarDecl *VD = BC.getVariable();
2410 if (VD->hasAttr()) {
2411
2412
2414 continue;
2416 }
2417
2418
2419 QualType CapType = BC.getVariable()->getType();
2426 }
2427 }
2428
2430
2432 continue;
2433
2434
2435
2436
2439 }
2440}
2441
2445 assert(.empty() && "mismatched push/pop!");
2446
2448
2451
2453 OpenMP().popOpenMPFunctionRegion(Scope.get());
2454
2455
2456 if (WP && D) {
2459 } else
2460 for (const auto &PUD : Scope->PossiblyUnreachableDiags)
2461 Diag(PUD.Loc, PUD.PD);
2462
2464}
2465
2468 if (->isPlainFunction())
2469 Self->CapturingFunctionScopes--;
2470
2471 if (Scope->isPlainFunction() && !Self->CachedFunctionScope)
2472 Self->CachedFunctionScope.reset(Scope);
2473 else
2475}
2476
2481
2484 assert(!CurFunction->CompoundScopes.empty() && "mismatched push/pop");
2485
2487}
2488
2492
2497
2502
2507
2512
2515 return nullptr;
2516
2517 auto CurBSI = dyn_cast(FunctionScopes.back());
2518 if (CurBSI && CurBSI->TheDecl &&
2519 !CurBSI->TheDecl->Encloses(CurContext)) {
2520
2522 return nullptr;
2523 }
2524
2525 return CurBSI;
2526}
2527
2530 return nullptr;
2531
2532 for (int e = FunctionScopes.size() - 1; e >= 0; --e) {
2534 continue;
2536 }
2537 return nullptr;
2538}
2539
2542 if (auto *CSI = dyn_cast(Scope)) {
2543 auto *LSI = dyn_cast(CSI);
2544 if (LSI && LSI->Lambda && !LSI->Lambda->Encloses(CurContext) &&
2545 LSI->AfterParameterList) {
2546
2547
2548
2550 return nullptr;
2551 }
2552 return CSI;
2553 }
2554 }
2555 return nullptr;
2556}
2557
2560 return nullptr;
2561
2563 if (IgnoreNonLambdaCapturingScope) {
2566 ++I;
2567 if (I == E)
2568 return nullptr;
2569 }
2570 auto *CurLSI = dyn_cast(*I);
2571 if (CurLSI && CurLSI->Lambda && CurLSI->CallOperator &&
2572 !CurLSI->Lambda->Encloses(CurContext) && CurLSI->AfterParameterList) {
2573
2575 return nullptr;
2576 }
2577
2578 return CurLSI;
2579}
2580
2581
2582
2585 return (LSI->TemplateParams.size() ||
2586 LSI->GLTemplateParameterList) ? LSI : nullptr;
2587 }
2588 return nullptr;
2589}
2590
2591
2593 if (.RetainCommentsFromSystemHeaders &&
2595 return;
2600 StringRef MagicMarkerText;
2603 MagicMarkerText = "///<";
2604 break;
2606 MagicMarkerText = "/**<";
2607 break;
2609
2610
2611 Diag(Comment.getBegin(), diag::warn_splice_in_doxygen_comment);
2612 return;
2613 default:
2614 llvm_unreachable("if this is an almost Doxygen comment, "
2615 "it should be ordinary");
2616 }
2617 Diag(Comment.getBegin(), diag::warn_not_a_doxygen_trailing_member_comment) <<
2619 }
2621}
2622
2623
2625char ExternalSemaSource::ID;
2626
2629
2633
2635 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {}
2636
2639
2642 ZeroArgCallReturnTy = QualType();
2644
2646 bool IsMemExpr = false;
2649
2650
2652 return false;
2653
2656 Overloads = dyn_cast(E.IgnoreParens());
2657 IsMemExpr = true;
2658 }
2659
2661 bool IsMV = false;
2662
2663 if (Overloads) {
2665 DeclsEnd = Overloads->decls_end(); it != DeclsEnd; ++it) {
2667
2668
2669
2670 if (IsMemExpr)
2671 continue;
2673 = dyn_cast((*it)->getUnderlyingDecl())) {
2674 if (OverloadDecl->getMinRequiredArguments() == 0) {
2676 (!IsMV || !(OverloadDecl->isCPUDispatchMultiVersion() ||
2677 OverloadDecl->isCPUSpecificMultiVersion()))) {
2678 ZeroArgCallReturnTy = QualType();
2680 } else {
2681 ZeroArgCallReturnTy = OverloadDecl->getReturnType();
2682 IsMV = OverloadDecl->isCPUDispatchMultiVersion() ||
2683 OverloadDecl->isCPUSpecificMultiVersion();
2684 }
2685 }
2686 }
2687 }
2688
2689
2690 if (!IsMemExpr)
2691 return !ZeroArgCallReturnTy.isNull();
2692 }
2693
2694
2695
2696
2702 ZeroArgCallReturnTy = R.get()->getType();
2703 return true;
2704 }
2705 return false;
2706 }
2707
2708 if (const auto *DeclRef = dyn_cast(E.IgnoreParens())) {
2709 if (const auto *Fun = dyn_cast(DeclRef->getDecl())) {
2710 if (Fun->getMinRequiredArguments() == 0)
2711 ZeroArgCallReturnTy = Fun->getReturnType();
2712 return true;
2713 }
2714 }
2715
2716
2717
2721 if (!PointeeTy.isNull())
2723 if (!FunTy)
2725
2726 if (const auto *FPT = dyn_cast_if_present(FunTy)) {
2727 if (FPT->getNumParams() == 0)
2729 return true;
2730 }
2731 return false;
2732}
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2748 unsigned ShownOverloads = 0;
2749 unsigned SuppressedOverloads = 0;
2751 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
2753 ++SuppressedOverloads;
2754 continue;
2755 }
2756
2757 const NamedDecl *Fn = (*It)->getUnderlyingDecl();
2758
2759 if (const auto *FD = Fn->getAsFunction()) {
2761 !FD->getAttr()->isDefaultVersion())
2762 continue;
2764 !FD->getAttr()->isDefaultVersion())
2765 continue;
2766 }
2767 S.Diag(Fn->getLocation(), diag::note_possible_target_of_call);
2768 ++ShownOverloads;
2769 }
2770
2772
2773 if (SuppressedOverloads)
2774 S.Diag(FinalNoteLoc, diag::note_ovl_too_many_candidates)
2775 << SuppressedOverloads;
2776}
2777
2780 bool (*IsPlausibleResult)(QualType)) {
2781 if (!IsPlausibleResult)
2783
2786 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
2788 QualType OverloadResultTy = OverloadDecl->getReturnType();
2789 if (IsPlausibleResult(OverloadResultTy))
2790 PlausibleOverloads.addDecl(It.getDecl());
2791 }
2793}
2794
2795
2796
2797
2798
2806
2808 if (const auto *UO = dyn_cast(E))
2809 E = UO->getSubExpr();
2810
2811 if (const auto *ULE = dyn_cast(E)) {
2812 if (ULE->getNumDecls() == 0)
2813 return false;
2814
2815 const NamedDecl *ND = *ULE->decls_begin();
2816 if (const auto *FD = dyn_cast(ND))
2818 }
2819 return false;
2820}
2821
2823 bool ForceComplain,
2824 bool (*IsPlausibleResult)(QualType)) {
2828
2829
2830
2834 !ZeroArgCallTy.isNull() &&
2835 (!IsPlausibleResult || IsPlausibleResult(ZeroArgCallTy))) {
2836
2837
2838
2839
2842 Diag(Loc, PD) << 1 << IsMV << Range
2845 "()")
2847 if (!IsMV)
2849
2850
2851
2853 Range.getEnd().getLocWithOffset(1));
2854 return true;
2855 }
2856 }
2857 if (!ForceComplain) return false;
2858
2860 Diag(Loc, PD) << 0 << IsMV << Range;
2861 if (!IsMV)
2864 return true;
2865}
2866
2868 if (!Ident_super)
2869 Ident_super = &Context.Idents.get("super");
2870 return Ident_super;
2871}
2872
2875 unsigned OpenMPCaptureLevel) {
2879 ? OpenMP().getOpenMPNestingLevel()
2880 : 0,
2881 OpenMPCaptureLevel);
2882 CSI->ReturnType = Context.VoidTy;
2885}
2886
2889 return nullptr;
2890
2891 return dyn_cast(FunctionScopes.back());
2892}
2893
2894const llvm::MapVector<FieldDecl *, Sema::DeleteLocs> &
2898
2902 OldEvalMethod(S.PP.getCurrentFPEvalMethod()),
2903 OldFPPragmaLocation(S.PP.getLastFPEvalPragmaLocation()) {}
2904
2906 S.CurFPFeatures = OldFPFeaturesState;
2907 S.FpPragmaStack.CurrentValue = OldOverrides;
2908 S.PP.setCurrentFPEvalMethod(OldFPPragmaLocation, OldEvalMethod);
2909}
2910
2913 "can only be called for qualified names");
2914
2919 if (!DC)
2920 return false;
2921
2923 bool Result = llvm::all_of(LR, [](Decl *Dcl) {
2924 if (NamedDecl *ND = dyn_cast(Dcl)) {
2925 ND = ND->getUnderlyingDecl();
2928 }
2929 return false;
2930 });
2932}
2933
2936
2937 auto *A = AnnotateAttr::Create(Context, Annot, Args.data(), Args.size(), CI);
2940 return nullptr;
2941 }
2942 return A;
2943}
2944
2946
2947
2948 StringRef Str;
2950 return nullptr;
2951
2954 for (unsigned Idx = 1; Idx < AL.getNumArgs(); Idx++) {
2957 }
2958
2960}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::Preprocessor interface.
This file declares semantic analysis functions specific to AMDGPU.
This file declares semantic analysis functions specific to ARM.
This file declares semantic analysis functions specific to AVR.
This file declares semantic analysis functions specific to BPF.
This file declares semantic analysis for CUDA constructs.
This file declares facilities that support code completion.
This file declares semantic analysis for DirectX constructs.
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis functions specific to Hexagon.
This file declares semantic analysis functions specific to LoongArch.
This file declares semantic analysis functions specific to M68k.
This file declares semantic analysis functions specific to MIPS.
This file declares semantic analysis functions specific to MSP430.
This file declares semantic analysis functions specific to NVPTX.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenACC constructs and clauses.
This file declares semantic analysis routines for OpenCL.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis functions specific to PowerPC.
This file declares semantic analysis for expressions involving.
This file declares semantic analysis functions specific to RISC-V.
This file declares semantic analysis for SPIRV constructs.
This file declares semantic analysis for SYCL constructs.
This file declares semantic analysis functions specific to Swift.
This file declares semantic analysis functions specific to SystemZ.
This file declares semantic analysis functions specific to Wasm.
This file declares semantic analysis functions specific to X86.
static void checkEscapingByref(VarDecl *VD, Sema &S)
Definition Sema.cpp:2370
static bool IsCPUDispatchCPUSpecificMultiVersion(const Expr *E)
Definition Sema.cpp:2807
llvm::DenseMap< const CXXRecordDecl *, bool > RecordCompleteMap
Definition Sema.cpp:1072
static bool IsCallableWithAppend(const Expr *E)
Determine whether the given expression can be called by just putting parentheses after it.
Definition Sema.cpp:2799
static bool MethodsAndNestedClassesComplete(const CXXRecordDecl *RD, RecordCompleteMap &MNCComplete)
Returns true, if all methods and nested classes of the given CXXRecordDecl are defined in this transl...
Definition Sema.cpp:1079
static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads, const SourceLocation FinalNoteLoc)
Give notes for a set of overloads.
Definition Sema.cpp:2746
static bool isFunctionOrVarDeclExternC(const NamedDecl *ND)
Definition Sema.cpp:927
static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S)
Definition Sema.cpp:2404
static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D)
Used to prune the decls of Sema's UnusedFileScopedDecls vector.
Definition Sema.cpp:866
static void emitCallStackNotes(Sema &S, const FunctionDecl *FD)
Definition Sema.cpp:1799
static void notePlausibleOverloads(Sema &S, SourceLocation Loc, const UnresolvedSetImpl &Overloads, bool(*IsPlausibleResult)(QualType))
Definition Sema.cpp:2778
static void checkUndefinedButUsed(Sema &S)
checkUndefinedButUsed - Check for undefined objects with internal linkage or that are inline.
Definition Sema.cpp:999
static bool IsRecordFullyDefined(const CXXRecordDecl *RD, RecordCompleteMap &RecordsComplete, RecordCompleteMap &MNCComplete)
Returns true, if the given CXXRecordDecl is fully defined in this translation unit,...
Definition Sema.cpp:1121
Defines the SourceManager interface.
Allows QualTypes to be sorted and hence used in maps and sets.
TypePropertyCache< Private > Cache
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
virtual ASTMutationListener * GetASTMutationListener()
If the consumer is interested in entities getting modified after their initial creation,...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
LangAS getDefaultOpenCLPointeeAddrSpace()
Returns default address space based on OpenCL version and enabled features.
void setBlockVarCopyInit(const VarDecl *VD, Expr *CopyExpr, bool CanThrow)
Set the copy initialization expression of a block var decl.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Attr - This represents one attribute.
A class which contains all the information about a particular captured value.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
ArrayRef< Capture > captures() const
SourceLocation getCaretLocation() const
bool doesNotEscape() const
Represents a C++ destructor within a class.
CXXFieldCollector - Used to keep track of CXXFieldDecls during parsing of C++ classes.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
An iterator over the friend declarations of a class.
Represents a C++ struct/union/class.
friend_iterator friend_begin() const
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
friend_iterator friend_end() const
bool isSet() const
Deprecated.
Represents the body of a CapturedStmt, and serves as its DeclContext.
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
static const char * getCastKindName(CastKind CK)
Abstract interface for a consumer of code-completion information.
The information about the darwin SDK that was used during this compilation.
decl_iterator - Iterates through the declarations stored within this context.
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.
decl_iterator decls_end() const
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
decl_iterator decls_begin() const
A reference to a declared variable, function, enum, etc.
FriendSpecified isFriendSpecified() const
Decl - This represents one declaration (or definition), e.g.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isReferenced() const
Whether any declaration of this entity was referenced.
bool isInvalidDecl() const
SourceLocation getLocation() const
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
Information about one declarator, including the parsed type information and the identifier.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
SourceLocation getBeginLoc() const LLVM_READONLY
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
const IdentifierInfo * getIdentifier() const
A little helper class used to produce diagnostics.
static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID)
Determines whether the given built-in diagnostic ID is for an error that is suppressed if it occurs d...
@ SFINAE_SubstitutionFailure
The diagnostic should not be reported, but it should cause template argument deduction to fail.
@ SFINAE_Suppress
The diagnostic should be suppressed entirely.
@ SFINAE_AccessControl
The diagnostic is an access-control diagnostic, which will be substitution failures in some contexts ...
@ SFINAE_Report
The diagnostic should be reported.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
const SourceLocation & getLocation() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
void overloadCandidatesShown(unsigned N)
Call this after showing N overload candidates.
unsigned getNumOverloadCandidatesToShow() const
When a call or operator fails, print out up to this many candidate overloads as suggestions.
Level
The level of the diagnostic, after it has been through mapping.
bool hasFatalErrorOccurred() const
RAII object that enters a new expression evaluation context.
This represents one expression.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
An abstract interface that should be implemented by external AST sources that also provide informatio...
virtual void updateOutOfDateSelector(Selector Sel)
Load the contents of the global method pool for a given selector if necessary.
Definition Sema.cpp:2628
virtual void ReadMethodPool(Selector Sel)
Load the contents of the global method pool for a given selector.
Definition Sema.cpp:2627
virtual void ReadUndefinedButUsed(llvm::MapVector< NamedDecl *, SourceLocation > &Undefined)
Load the set of used but not defined functions or variables with internal linkage,...
Definition Sema.cpp:2634
~ExternalSemaSource() override
Definition Sema.cpp:2624
virtual void ReadKnownNamespaces(SmallVectorImpl< NamespaceDecl * > &Namespaces)
Load the set of namespaces that are known to the external source, which will be used during typo corr...
Definition Sema.cpp:2630
virtual void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 > > &)
Definition Sema.cpp:2637
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
StringRef getName() const
The name of this FileEntry.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
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.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Represents a function declaration or definition.
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
bool isDeleted() const
Whether this function has been deleted.
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
bool isDefaulted() const
Whether this function is defaulted.
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
static FunctionEffectsRef get(QualType QT)
Extract the effects from a Type if it is a function, block, or member function pointer,...
Represents a prototype with parameter type info, e.g.
Declaration of a template function.
FunctionType - C99 6.7.5.3 - Function Declarators.
@ SME_PStateSMCompatibleMask
QualType getReturnType() const
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Represents a C array with an unspecified size.
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type)
@ CMK_HeaderUnit
Compiling a module header unit.
@ CMK_ModuleInterface
Compiling a C++ modules interface unit.
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
static std::optional< Token > findNextToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeComments=false)
Finds the token that comes right after the given location.
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Represents the results of name lookup.
Encapsulates the data about a macro definition (e.g.
Abstract interface for a module loader.
bool resolveExports(Module *Mod, bool Complain)
Resolve all of the unresolved exports in the given module.
bool resolveConflicts(Module *Mod, bool Complain)
Resolve all of the unresolved conflicts in the given module.
bool resolveUses(Module *Mod, bool Complain)
Resolve all of the unresolved uses in the given module.
Describes a module or submodule.
bool isNamedModuleInterfaceHasInit() const
bool isInterfaceOrPartition() const
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
llvm::iterator_range< submodule_iterator > submodules()
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
static const unsigned NumNSNumberLiteralMethods
This represents a decl that may have a name.
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
NamedDecl * getMostRecentDecl()
bool isExternallyVisible() const
ObjCMethodDecl - Represents an instance or class method declaration.
void addSupport(const llvm::StringMap< bool > &FeaturesMap, const LangOptions &Opts)
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.
UnresolvedSetImpl::iterator decls_iterator
decls_iterator decls_begin() const
decls_iterator decls_end() const
This interface provides a way to observe the actions of the preprocessor as it does its thing.
ParsedAttr - Represents a syntactic attribute.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
bool isArgIdent(unsigned Arg) const
Expr * getArgAsExpr(unsigned Arg) const
unsigned getDiagID() const
void Emit(const DiagnosticBuilder &DB) const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
A (possibly-)qualified type.
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
field_range fields() const
Scope - A scope is a transient data structure that is used while parsing the program.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ DeclScope
This is a scope that can contain a declaration.
Smart pointer class that efficiently represents Objective-C method names.
A generic diagnostic builder for errors which may or may not be deferred.
@ K_Immediate
Emit the diagnostic immediately (i.e., behave like Sema::Diag()).
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
llvm::DenseMap< CanonicalDeclPtr< const FunctionDecl >, FunctionDeclAndLoc > DeviceKnownEmittedFns
An inverse call graph, mapping known-emitted functions to one of their known-emitted callers (plus th...
An abstract interface that should be implemented by clients that read ASTs and then require further s...
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU)
ObjCMethodDecl * NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]
The Objective-C NSNumber methods used to create NSNumber literals.
void DiagnoseUseOfUnimplementedSelectors()
std::unique_ptr< NSAPI > NSAPIObj
Caches identifiers/selectors for NSFoundation APIs.
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU)
void DiagnoseUnterminatedOpenMPDeclareTarget()
Report unterminated 'omp declare target' or 'omp begin declare target' at the end of a compilation un...
A class which encapsulates the logic for delaying diagnostics during parsing and other processing.
sema::DelayedDiagnosticPool * getCurrentPool() const
Returns the current delayed-diagnostics pool.
FPFeaturesStateRAII(Sema &S)
Definition Sema.cpp:2899
~FPFeaturesStateRAII()
Definition Sema.cpp:2905
Custom deleter to allow FunctionScopeInfos to be kept alive for a short time after they've been poppe...
void operator()(sema::FunctionScopeInfo *Scope) const
Definition Sema.cpp:2467
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
Sema - This implements semantic analysis and AST building for C.
SmallVector< DeclaratorDecl *, 4 > ExternalDeclarations
All the external declarations encoutered and used in the TU.
bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, MutableArrayRef< Expr * > Args)
ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs (unless they are value dependent ...
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
sema::CapturingScopeInfo * getEnclosingLambdaOrBlock() const
Get the innermost lambda or block enclosing the current location, if any.
Definition Sema.cpp:2540
Scope * getCurScope() const
Retrieve the parser's current scope.
bool IsBuildingRecoveryCallExpr
Flag indicating if Sema is building a recovery call expression.
void LoadExternalWeakUndeclaredIdentifiers()
Load weak undeclared identifiers from the external source.
Definition Sema.cpp:1061
bool isExternalWithNoLinkageType(const ValueDecl *VD) const
Determine if VD, which must be a variable or function, is an external symbol that nonetheless can't b...
Definition Sema.cpp:935
bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, UnresolvedSetImpl &NonTemplateOverloads)
Figure out if an expression could be turned into a call.
Definition Sema.cpp:2640
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the pragma attribute stack.
OpaquePtr< QualType > TypeTy
void addImplicitTypedef(StringRef Name, QualType T)
Definition Sema.cpp:365
void CheckDelegatingCtorCycles()
SmallVector< CXXMethodDecl *, 4 > DelayedDllExportMemberFunctions
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
llvm::SmallSetVector< const TypedefNameDecl *, 4 > UnusedLocalTypedefNameCandidates
Set containing all typedefs that are likely unused.
void emitAndClearUnusedLocalTypedefWarnings()
Definition Sema.cpp:1152
std::unique_ptr< CXXFieldCollector > FieldCollector
FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
unsigned CapturingFunctionScopes
Track the number of currently active capturing scopes.
void Initialize()
Perform initialization that occurs after the parser has been initialized but before it parses anythin...
Definition Sema.cpp:371
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
PoppedFunctionScopePtr PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP=nullptr, const Decl *D=nullptr, QualType BlockType=QualType())
Pop a function (or block or lambda or captured region) scope from the stack.
Definition Sema.cpp:2443
Preprocessor & getPreprocessor() const
Scope * getScopeForContext(DeclContext *Ctx)
Determines the active Scope associated with the given declaration context.
Definition Sema.cpp:2312
PragmaStack< FPOptionsOverride > FpPragmaStack
PragmaStack< StringLiteral * > CodeSegStack
void setFunctionHasBranchIntoScope()
Definition Sema.cpp:2493
void ActOnComment(SourceRange Comment)
Definition Sema.cpp:2592
void ActOnEndOfTranslationUnit()
ActOnEndOfTranslationUnit - This is called at the very end of the translation unit when EOF is reache...
Definition Sema.cpp:1231
FPOptionsOverride CurFPFeatureOverrides()
ExprResult BuildCallToMemberFunction(Scope *S, Expr *MemExpr, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr, bool IsExecConfig=false, bool AllowRecovery=false)
BuildCallToMemberFunction - Build a call to a member function.
void ActOnTranslationUnitScope(Scope *S)
Scope actions.
Definition Sema.cpp:172
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
Look up a name, looking for a single declaration.
IdentifierInfo * getSuperIdentifier() const
Definition Sema.cpp:2867
FunctionDecl * getCurFunctionDecl(bool AllowLambda=false) const
Returns a pointer to the innermost enclosing function, or nullptr if the current context is not insid...
Definition Sema.cpp:1654
void DiagnosePrecisionLossInComplexDivision()
bool DisableTypoCorrection
Tracks whether we are in a context where typo correction is disabled.
void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, SourceLocation Loc)
Warn if we're implicitly casting from a _Nullable pointer type to a _Nonnull one.
Definition Sema.cpp:680
DiagnosticsEngine & getDiagnostics() const
bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, bool ForceComplain=false, bool(*IsPlausibleResult)(QualType)=nullptr)
Try to recover by turning the given expression into a call.
Definition Sema.cpp:2822
SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags
Diagnostics that are emitted only if we discover that the given function must be codegen'ed.
void CheckDelayedMemberExceptionSpecs()
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
ClassTemplateDecl * StdCoroutineTraitsCache
The C++ "std::coroutine_traits" template, which is defined in <coroutine_traits>
PragmaStack< bool > StrictGuardStackCheckStack
UnusedFileScopedDeclsType UnusedFileScopedDecls
The set of file scoped decls seen so far that have not been used and must warn if not used.
ASTContext & getASTContext() const
std::unique_ptr< sema::FunctionScopeInfo, PoppedFunctionScopeDeleter > PoppedFunctionScopePtr
void addExternalSource(IntrusiveRefCntPtr< ExternalSemaSource > E)
Registers an external source.
Definition Sema.cpp:655
ClassTemplateDecl * StdInitializerList
The C++ "std::initializer_list" template, which is defined in <initializer_list>.
SmallVector< std::pair< FunctionDecl *, FunctionDecl * >, 2 > DelayedEquivalentExceptionSpecChecks
All the function redeclarations seen during a class definition that had their exception spec checks d...
PragmaStack< StringLiteral * > ConstSegStack
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition Sema.cpp:756
unsigned TyposCorrected
The number of typos corrected by CorrectTypo.
static const unsigned MaxAlignmentExponent
The maximum alignment, same as in llvm::Value.
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
Definition Sema.cpp:1659
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
Definition Sema.cpp:2583
void setFunctionHasIndirectGoto()
Definition Sema.cpp:2503
LangAS getDefaultCXXMethodAddrSpace() const
Returns default addr space for method qualifiers.
Definition Sema.cpp:1673
void PushFunctionScope()
Enter a new function scope.
Definition Sema.cpp:2331
FPOptions & getCurFPFeatures()
RecordDecl * StdSourceLocationImplDecl
The C++ "std::source_location::__impl" struct, defined in <source_location>.
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr)
Definition Sema.cpp:272
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition Sema.cpp:83
sema::LambdaScopeInfo * PushLambdaScope()
Definition Sema.cpp:2349
void PopCompoundScope()
Definition Sema.cpp:2482
api_notes::APINotesManager APINotes
const LangOptions & getLangOpts() const
const FunctionProtoType * ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT)
ASTConsumer & getASTConsumer() const
ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr, bool IsExecConfig=false, bool AllowRecovery=false)
BuildCallExpr - Handle a call to Fn with the specified array of arguments.
threadSafety::BeforeSet * ThreadSafetyDeclCache
void checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D=nullptr)
Check if the type is allowed to be used for the current target.
Definition Sema.cpp:2121
const LangOptions & LangOpts
std::unique_ptr< sema::FunctionScopeInfo > CachedFunctionScope
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition Sema.cpp:2558
static const uint64_t MaximumAlignment
NamedDeclSetType UnusedPrivateFields
Set containing all declared private fields that are not used.
bool CollectStats
Flag indicating whether or not to collect detailed statistics.
void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind)
Definition Sema.cpp:1171
bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const
IdentifierInfo * InventAbbreviatedTemplateParameterTypeName(const IdentifierInfo *ParamName, unsigned Index)
Invent a new identifier for parameters of abbreviated templates.
Definition Sema.cpp:139
SmallVector< PendingImplicitInstantiation, 1 > LateParsedInstantiations
Queue of implicit template instantiations that cannot be performed eagerly.
void performFunctionEffectAnalysis(TranslationUnitDecl *TU)
PragmaStack< AlignPackInfo > AlignPackStack
SmallVector< std::pair< const CXXMethodDecl *, const CXXMethodDecl * >, 2 > DelayedOverridingExceptionSpecChecks
All the overriding functions seen during a class definition that had their exception spec checks dela...
PragmaStack< StringLiteral * > BSSSegStack
DeclContext * getCurLexicalContext() const
NamedDecl * getCurFunctionOrMethodDecl() const
getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method or C function we're in,...
Definition Sema.cpp:1666
static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy)
ScalarTypeToBooleanCastKind - Returns the cast kind corresponding to the conversion from scalar type ...
Definition Sema.cpp:849
llvm::SmallSetVector< Decl *, 4 > DeclsToCheckForDeferredDiags
Function or variable declarations to be checked for whether the deferred diagnostics should be emitte...
sema::FunctionScopeInfo * getCurFunction() const
void PushCompoundScope(bool IsStmtExpr)
Definition Sema.cpp:2477
bool isDeclaratorFunctionLike(Declarator &D)
Determine whether.
Definition Sema.cpp:2911
bool findMacroSpelling(SourceLocation &loc, StringRef name)
Looks through the macro-expansion chain for the given location, looking for a macro expansion with th...
Definition Sema.cpp:2295
StringLiteral * CurInitSeg
Last section used with pragma init_seg.
Module * getCurrentModule() const
Get the module unit whose scope we are currently within.
static bool isCast(CheckedConversionKind CCK)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2513
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
ClassTemplateDecl * StdTypeIdentity
The C++ "std::type_identity" template, which is defined in <type_traits>.
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5.
DeclContext * getFunctionLevelDeclContext(bool AllowLambda=false) const
If AllowLambda is true, treat lambda as function.
Definition Sema.cpp:1634
bool DefineUsedVTables()
Define all of the vtables that have been used in this translation unit and reference any virtual memb...
bool GlobalNewDeleteDeclared
A flag to remember whether the implicit forms of operator new and delete have been declared.
DeclContext * OriginalLexicalContext
Generally null except when we temporarily switch decl contexts, like in.
unsigned NonInstantiationEntries
The number of CodeSynthesisContexts that are not template instantiations and, therefore,...
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
SourceManager & getSourceManager() const
bool makeUnavailableInSystemHeader(SourceLocation loc, UnavailableAttr::ImplicitReason reason)
makeUnavailableInSystemHeader - There is an error in the current context.
Definition Sema.cpp:630
void getUndefinedButUsed(SmallVectorImpl< std::pair< NamedDecl *, SourceLocation > > &Undefined)
Obtain a sorted list of functions that are undefined but ODR-used.
Definition Sema.cpp:946
void diagnoseFunctionEffectConversion(QualType DstType, QualType SrcType, SourceLocation Loc)
Warn when implicitly changing function effects.
Definition Sema.cpp:696
void PerformPendingInstantiations(bool LocalOnly=false, bool AtEndOfTU=true)
Performs template instantiation for all implicit template instantiations we have seen until this poin...
ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, const NamedReturnInfo &NRInfo, Expr *Value, bool SupressSimplerImplicitMoves=false)
Perform the initialization of a potentially-movable value, which is the result of return value.
CanThrowResult canThrow(const Stmt *E)
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
void PushBlockScope(Scope *BlockScope, BlockDecl *Block)
Definition Sema.cpp:2343
PragmaStack< MSVtorDispMode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
bool isSFINAEContext() const
UnsignedOrNone ArgPackSubstIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, RecordDecl *RD, CapturedRegionKind K, unsigned OpenMPCaptureLevel=0)
Definition Sema.cpp:2873
void emitDeferredDiags()
Definition Sema.cpp:2014
void setFunctionHasMustTail()
Definition Sema.cpp:2508
RecordDecl * CXXTypeInfoDecl
The C++ "type_info" declaration, which is defined in .
void CheckCompleteVariableDeclaration(VarDecl *VD)
void setFunctionHasBranchProtectedScope()
Definition Sema.cpp:2498
RedeclarationKind forRedeclarationInCurContext() const
void ActOnStartOfTranslationUnit()
This is called before the very first declaration in the translation unit is parsed.
Definition Sema.cpp:1165
IntrusiveRefCntPtr< ExternalSemaSource > ExternalSource
Source of additional semantic information.
llvm::SmallPtrSet< const Decl *, 4 > ParsingInitForAutoVars
ParsingInitForAutoVars - a set of declarations with auto types for which we are currently parsing the...
@ NonDefaultStateAtInclude
sema::AnalysisBasedWarnings AnalysisWarnings
Worker object for performing CFG-based warnings.
bool hasUncompilableErrorOccurred() const
Whether uncompilable error has occurred.
Definition Sema.cpp:1780
std::deque< PendingImplicitInstantiation > PendingInstantiations
The queue of implicit template instantiations that are required but have not yet been performed.
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with the preprocessor.
Definition Sema.cpp:109
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
std::pair< SourceLocation, bool > DeleteExprLoc
void RecordParsingTemplateParameterDepth(unsigned Depth)
This is used to inform Sema what the current TemplateParameterDepth is during Parsing.
Definition Sema.cpp:2356
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
void DiagnoseUnterminatedPragmaAttribute()
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
LateTemplateParserCB * LateTemplateParser
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
llvm::MapVector< FieldDecl *, DeleteLocs > DeleteExprs
Delete-expressions to be analyzed at the end of translation unit.
TentativeDefinitionsType TentativeDefinitions
All the tentative definitions encountered in the TU.
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
DarwinSDKInfo * getDarwinSDKInfoForAvailabilityChecking()
Definition Sema.cpp:123
const llvm::MapVector< FieldDecl *, DeleteLocs > & getMismatchingDeleteExpressions() const
Retrieves list of suspicious delete-expressions that will be checked at the end of translation unit.
Definition Sema.cpp:2895
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
void PushDeclContext(Scope *S, DeclContext *DC)
Set the current declaration context until it gets popped.
SourceManager & SourceMgr
DiagnosticsEngine & Diags
void DiagnoseUnterminatedPragmaAlignPack()
OpenCLOptions & getOpenCLOptions()
PragmaStack< StringLiteral * > DataSegStack
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
Attr * CreateAnnotationAttr(const AttributeCommonInfo &CI, StringRef Annot, MutableArrayRef< Expr * > Args)
CreateAnnotationAttr - Creates an annotation Annot with Args arguments.
Definition Sema.cpp:2934
llvm::MapVector< NamedDecl *, SourceLocation > UndefinedButUsed
UndefinedInternals - all the used, undefined objects which require a definition in this translation u...
void PrintStats() const
Print out statistics about the semantic analysis.
Definition Sema.cpp:670
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
llvm::BumpPtrAllocator BumpAlloc
SourceRange getRangeForNextToken(SourceLocation Loc, bool IncludeMacros, bool IncludeComments, std::optional< tok::TokenKind > ExpectedToken=std::nullopt)
Calls Lexer::findNextToken() to find the next token, and if the locations of both ends of the token c...
Definition Sema.cpp:88
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
Definition Sema.cpp:625
SmallVector< CXXRecordDecl *, 4 > DelayedDllExportClasses
llvm::MapVector< IdentifierInfo *, llvm::SetVector< WeakInfo, llvm::SmallVector< WeakInfo, 1u >, llvm::SmallDenseSet< WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly > > > WeakUndeclaredIdentifiers
WeakUndeclaredIdentifiers - Identifiers contained in #pragma weak before declared.
SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD=nullptr)
Definition Sema.cpp:2104
DeclarationName VAListTagName
VAListTagName - The declaration name corresponding to __va_list_tag.
~Sema()
Definition Sema.cpp:588
sema::FunctionScopeInfo * getEnclosingFunction() const
Definition Sema.cpp:2528
sema::CapturedRegionScopeInfo * getCurCapturedRegion()
Retrieve the current captured region, if any.
Definition Sema.cpp:2887
void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E)
Warn when implicitly casting 0 to nullptr.
Definition Sema.cpp:708
void EmitDiagnostic(unsigned DiagID, const DiagnosticBuilder &DB)
Cause the built diagnostic to be emitted on the DiagosticsEngine.
Definition Sema.cpp:1679
void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, NonTrivialCUnionContext UseContext, unsigned NonTrivialKind)
Emit diagnostics if a non-trivial C union type or a struct that contains a non-trivial C union is use...
IdentifierResolver IdResolver
bool hasAnyUnrecoverableErrorsInThisFunction() const
Determine whether any errors occurred within this function/method/ block.
Definition Sema.cpp:2489
bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, const Expr *E, StringRef &Str, SourceLocation *ArgLocation=nullptr)
Check if the argument E is a ASCII string literal.
llvm::DenseSet< InstantiatingSpecializationsKey > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
ASTMutationListener * getASTMutationListener() const
Definition Sema.cpp:651
SFINAETrap * getSFINAEContext() const
Returns a pointer to the current SFINAE context, if any.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
void setEnd(SourceLocation e)
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Exposes information about the current target.
virtual bool hasLongDoubleType() const
Determine whether the long double type is supported on this target.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual bool hasFPReturn() const
Determine whether return of a floating point value is supported on this target.
bool hasRISCVVTypes() const
Returns whether or not the RISC-V V built-in types are available on this target.
A container of type source information.
The base class of the type hierarchy.
bool isFloat16Type() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
const T * castAs() const
Member-template castAs.
bool isFloat128Type() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isBitIntType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
ScalarTypeKind getScalarTypeKind() const
Given that this is a scalar type, classify it.
bool isIbm128Type() const
bool isBFloat16Type() const
bool isStructureOrClassType() const
bool isRealFloatingType() const
Floating point categories.
bool isRVVSizelessBuiltinType() const
Returns true for RVV scalable vector types.
Linkage getLinkage() const
Determine the linkage of this type.
const T * getAs() const
Member-template getAs'.
bool isNullPtrType() const
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
Base class for declarations which introduce a typedef-name.
A set of unresolved declarations.
UnresolvedSetIterator iterator
void addDecl(NamedDecl *D)
A set of unresolved declarations.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
void setType(QualType newType)
Represents a variable declaration or definition.
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
VarDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
const Expr * getInit() const
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
@ DeclarationOnly
This declaration is only a declaration.
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Declaration of a variable template.
Represents a GCC generic vector type.
Retains information about a block that is currently being parsed.
Retains information about a captured region.
Contains information about the compound statement currently being parsed.
Retains information about a function, method, or block that is currently being parsed.
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound statement scopes in the function.
llvm::SmallPtrSet< const BlockDecl *, 1 > Blocks
The set of blocks that are introduced in this function.
llvm::TinyPtrVector< VarDecl * > ByrefBlockVars
The set of __block variables that are introduced in this function.
void set(Sema &S)
Definition Sema.cpp:186
void reset()
Definition Sema.cpp:188
void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override
Callback invoked whenever a source file is entered or exited.
Definition Sema.cpp:190
void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity Mapping, StringRef Str) override
Callback invoked when a #pragma gcc diagnostic directive is read.
Definition Sema.cpp:227
Provides information about an attempted template argument deduction, whose success or failure was des...
void addSuppressedDiagnostic(SourceLocation Loc, PartialDiagnostic PD)
Add a new diagnostic to the set of diagnostics.
void addSFINAEDiagnostic(SourceLocation Loc, PartialDiagnostic PD)
Set the diagnostic which caused the SFINAE failure.
bool hasSFINAEDiagnostic() const
Is a SFINAE diagnostic available?
Defines the clang::TargetInfo interface.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Flavor
Flavors of diagnostics we can emit.
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
@ Remark
A diagnostic that indicates normal progress through compilation.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
void threadSafetyCleanup(BeforeSet *Cache)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
@ ExpectedVariableOrFunction
@ Nullable
Values of this type can be null.
@ NonNull
Values of this type can never be null.
Expected< std::optional< DarwinSDKInfo > > parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath)
Parse the SDK information from the SDKSettings.json file.
@ Override
Merge availability attributes for an override, which requires an exact match or a weakening of constr...
void inferNoReturnAttr(Sema &S, const Decl *D)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
CapturedRegionKind
The different kinds of captured statement.
@ SD_Thread
Thread storage duration.
@ SD_Static
Static storage duration.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ Private
The private module fragment, between 'module :private;' and the end of the translation unit.
@ Global
The global module fragment, between 'module;' and a module-declaration.
@ Normal
A normal translation unit fragment.
@ OverloadSet
The name was classified as an overload set, and an expression representing that overload set has been...
LangAS
Defines the address space values used by the address space qualifier of QualType.
CastKind
CastKind - The kind of operation required for a conversion.
TranslationUnitKind
Describes the kind of translation unit being processed.
@ TU_ClangModule
The translation unit is a clang module.
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
ComparisonCategoryType
An enumeration representing the different comparison categories types.
void FormatASTNodeDiagnosticArgument(DiagnosticsEngine::ArgumentKind Kind, intptr_t Val, StringRef Modifier, StringRef Argument, ArrayRef< DiagnosticsEngine::ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, void *Cookie, ArrayRef< intptr_t > QualTypeVals)
DiagnosticsEngine argument formatting function for diagnostics that involve AST nodes.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
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_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
bool isExternalFormalLinkage(Linkage L)
@ SveFixedLengthData
is AArch64 SVE fixed-length data vector
@ SveFixedLengthPredicate
is AArch64 SVE fixed-length predicate vector
U cast(CodeGen::Address addr)
@ Class
The "class" keyword introduces the elaborated-type-specifier.
bool IsArmStreamingFunction(const FunctionDecl *FD, bool IncludeLocallyStreaming)
Returns whether the given FunctionDecl has an __arm[_locally]_streaming attribute.
bool isExternallyVisible(Linkage L)
ActionResult< Expr * > ExprResult
CheckedConversionKind
The kind of conversion being performed.
Represents an explicit template argument list in C++, e.g., the "" in "sort".
bool HasFormOfMemberPointer
OverloadExpr * Expression
Describes how types, statements, expressions, and declarations should be printed.
unsigned Bool
Whether we can use 'bool' rather than '_Bool' (even if the language doesn't actually have 'bool',...
unsigned EntireContentsOfLargeArray
Whether to print the entire array initializers, especially on non-type template parameters,...
@ RewritingOperatorAsSpaceship
We are rewriting a comparison operator in terms of an operator<=>.