clang 20.0.0git
Sema.cpp
Go to the documentation of this file.
1//===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the actions class which performs semantic analysis and
10// builds an AST out of a parse stream.
11//
12//===----------------------------------------------------------------------===//
13
14#include "UsedDeclVisitor.h"
17#include "clang/AST/Decl.h"
18#include "clang/AST/DeclCXX.h"
20#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
22#include "clang/AST/ExprCXX.h"
24#include "clang/AST/StmtCXX.h"
29#include "clang/Basic/Stack.h"
42#include "clang/Sema/Scope.h"
45#include "clang/Sema/SemaARM.h"
46#include "clang/Sema/SemaAVR.h"
47#include "clang/Sema/SemaBPF.h"
48#include "clang/Sema/SemaCUDA.h"
51#include "clang/Sema/SemaHLSL.h"
55#include "clang/Sema/SemaM68k.h"
56#include "clang/Sema/SemaMIPS.h"
59#include "clang/Sema/SemaObjC.h"
63#include "clang/Sema/SemaPPC.h"
66#include "clang/Sema/SemaSYCL.h"
69#include "clang/Sema/SemaWasm.h"
70#include "clang/Sema/SemaX86.h"
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 <optional>
79
80using namespace clang;
81using namespace sema;
82
85}
86
88
91 StringRef Platform) {
93 if (!SDKInfo && !WarnedDarwinSDKInfoMissing) {
94 Diag(Loc, diag::warn_missing_sdksettings_for_availability_checking)
95 << Platform;
96 WarnedDarwinSDKInfoMissing = true;
97 }
98 return SDKInfo;
99}
100
102 if (CachedDarwinSDKInfo)
103 return CachedDarwinSDKInfo->get();
104 auto SDKInfo = parseDarwinSDKInfo(
107 if (SDKInfo && *SDKInfo) {
108 CachedDarwinSDKInfo = std::make_unique<DarwinSDKInfo>(std::move(**SDKInfo));
109 return CachedDarwinSDKInfo->get();
110 }
111 if (!SDKInfo)
112 llvm::consumeError(SDKInfo.takeError());
113 CachedDarwinSDKInfo = std::unique_ptr<DarwinSDKInfo>();
114 return nullptr;
115}
116
118 const IdentifierInfo *ParamName, unsigned int Index) {
119 std::string InventedName;
120 llvm::raw_string_ostream OS(InventedName);
121
122 if (!ParamName)
123 OS << "auto:" << Index + 1;
124 else
125 OS << ParamName->getName() << ":auto";
126
127 OS.flush();
128 return &Context.Idents.get(OS.str());
129}
130
132 const Preprocessor &PP) {
134 // In diagnostics, we print _Bool as bool if the latter is defined as the
135 // former.
136 Policy.Bool = Context.getLangOpts().Bool;
137 if (!Policy.Bool) {
138 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
139 Policy.Bool = BoolMacro->isObjectLike() &&
140 BoolMacro->getNumTokens() == 1 &&
141 BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
142 }
143 }
144
145 // Shorten the data output if needed
146 Policy.EntireContentsOfLargeArray = false;
147
148 return Policy;
149}
150
152 TUScope = S;
154}
155
156namespace clang {
157namespace sema {
158
160 Sema *S = nullptr;
163
164public:
165 void set(Sema &S) { this->S = &S; }
166
167 void reset() { S = nullptr; }
168
171 FileID PrevFID) override {
172 if (!S)
173 return;
174 switch (Reason) {
175 case EnterFile: {
177 SourceLocation IncludeLoc = SM.getIncludeLoc(SM.getFileID(Loc));
178 if (IncludeLoc.isValid()) {
179 if (llvm::timeTraceProfilerEnabled()) {
180 OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc));
181 ProfilerStack.push_back(llvm::timeTraceAsyncProfilerBegin(
182 "Source", FE ? FE->getName() : StringRef("<unknown>")));
183 }
184
185 IncludeStack.push_back(IncludeLoc);
188 IncludeLoc);
189 }
190 break;
191 }
192 case ExitFile:
193 if (!IncludeStack.empty()) {
194 if (llvm::timeTraceProfilerEnabled())
195 llvm::timeTraceProfilerEnd(ProfilerStack.pop_back_val());
196
199 IncludeStack.pop_back_val());
200 }
201 break;
202 default:
203 break;
204 }
205 }
206};
207
208} // end namespace sema
209} // end namespace clang
210
211const unsigned Sema::MaxAlignmentExponent;
213
215 TranslationUnitKind TUKind, CodeCompleteConsumer *CodeCompleter)
216 : SemaBase(*this), CollectStats(false), TUKind(TUKind),
217 CurFPFeatures(pp.getLangOpts()), LangOpts(pp.getLangOpts()), PP(pp),
218 Context(ctxt), Consumer(consumer), Diags(PP.getDiagnostics()),
219 SourceMgr(PP.getSourceManager()), APINotes(SourceMgr, LangOpts),
220 AnalysisWarnings(*this), ThreadSafetyDeclCache(nullptr),
221 LateTemplateParser(nullptr), LateTemplateParserCleanup(nullptr),
222 OpaqueParser(nullptr), CurContext(nullptr), ExternalSource(nullptr),
223 CurScope(nullptr), Ident_super(nullptr),
224 AMDGPUPtr(std::make_unique<SemaAMDGPU>(*this)),
225 ARMPtr(std::make_unique<SemaARM>(*this)),
226 AVRPtr(std::make_unique<SemaAVR>(*this)),
227 BPFPtr(std::make_unique<SemaBPF>(*this)),
228 CodeCompletionPtr(
229 std::make_unique<SemaCodeCompletion>(*this, CodeCompleter)),
230 CUDAPtr(std::make_unique<SemaCUDA>(*this)),
231 HLSLPtr(std::make_unique<SemaHLSL>(*this)),
232 HexagonPtr(std::make_unique<SemaHexagon>(*this)),
233 LoongArchPtr(std::make_unique<SemaLoongArch>(*this)),
234 M68kPtr(std::make_unique<SemaM68k>(*this)),
235 MIPSPtr(std::make_unique<SemaMIPS>(*this)),
236 MSP430Ptr(std::make_unique<SemaMSP430>(*this)),
237 NVPTXPtr(std::make_unique<SemaNVPTX>(*this)),
238 ObjCPtr(std::make_unique<SemaObjC>(*this)),
239 OpenACCPtr(std::make_unique<SemaOpenACC>(*this)),
240 OpenCLPtr(std::make_unique<SemaOpenCL>(*this)),
241 OpenMPPtr(std::make_unique<SemaOpenMP>(*this)),
242 PPCPtr(std::make_unique<SemaPPC>(*this)),
243 PseudoObjectPtr(std::make_unique<SemaPseudoObject>(*this)),
244 RISCVPtr(std::make_unique<SemaRISCV>(*this)),
245 SYCLPtr(std::make_unique<SemaSYCL>(*this)),
246 SwiftPtr(std::make_unique<SemaSwift>(*this)),
247 SystemZPtr(std::make_unique<SemaSystemZ>(*this)),
248 WasmPtr(std::make_unique<SemaWasm>(*this)),
249 X86Ptr(std::make_unique<SemaX86>(*this)),
250 MSPointerToMemberRepresentationMethod(
251 LangOpts.getMSPointerToMemberRepresentationMethod()),
252 MSStructPragmaOn(false), VtorDispStack(LangOpts.getVtorDispMode()),
253 AlignPackStack(AlignPackInfo(getLangOpts().XLPragmaPack)),
254 DataSegStack(nullptr), BSSSegStack(nullptr), ConstSegStack(nullptr),
255 CodeSegStack(nullptr), StrictGuardStackCheckStack(false),
256 FpPragmaStack(FPOptionsOverride()), CurInitSeg(nullptr),
257 VisContext(nullptr), PragmaAttributeCurrentTargetDecl(nullptr),
258 StdCoroutineTraitsCache(nullptr), IdResolver(pp),
259 OriginalLexicalContext(nullptr), StdInitializerList(nullptr),
260 FullyCheckedComparisonCategories(
261 static_cast<unsigned>(ComparisonCategoryType::Last) + 1),
262 StdSourceLocationImplDecl(nullptr), CXXTypeInfoDecl(nullptr),
263 GlobalNewDeleteDeclared(false), DisableTypoCorrection(false),
264 TyposCorrected(0), IsBuildingRecoveryCallExpr(false), NumSFINAEErrors(0),
265 AccessCheckingSFINAE(false), CurrentInstantiationScope(nullptr),
266 InNonInstantiationSFINAEContext(false), NonInstantiationEntries(0),
267 ArgumentPackSubstitutionIndex(-1), SatisfactionCache(Context) {
268 assert(pp.TUKind == TUKind);
269 TUScope = nullptr;
270
271 LoadedExternalKnownNamespaces = false;
272 for (unsigned I = 0; I != NSAPI::NumNSNumberLiteralMethods; ++I)
273 ObjC().NSNumberLiteralMethods[I] = nullptr;
274
275 if (getLangOpts().ObjC)
276 ObjC().NSAPIObj.reset(new NSAPI(Context));
277
280
281 // Tell diagnostics how to render things from the AST library.
283
284 // This evaluation context exists to ensure that there's always at least one
285 // valid evaluation context available. It is never removed from the
286 // evaluation stack.
287 ExprEvalContexts.emplace_back(
290
291 // Initialization of data sharing attributes stack for OpenMP
292 OpenMP().InitDataSharingAttributesStack();
293
294 std::unique_ptr<sema::SemaPPCallbacks> Callbacks =
295 std::make_unique<sema::SemaPPCallbacks>();
296 SemaPPCallbackHandler = Callbacks.get();
297 PP.addPPCallbacks(std::move(Callbacks));
298 SemaPPCallbackHandler->set(*this);
299
300 CurFPFeatures.setFPEvalMethod(PP.getCurrentFPEvalMethod());
301}
302
303// Anchor Sema's type info to this TU.
305
306void Sema::addImplicitTypedef(StringRef Name, QualType T) {
307 DeclarationName DN = &Context.Idents.get(Name);
308 if (IdResolver.begin(DN) == IdResolver.end())
310}
311
313 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
314 SC->InitializeSema(*this);
315
316 // Tell the external Sema source about this Sema object.
317 if (ExternalSemaSource *ExternalSema
318 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
319 ExternalSema->InitializeSema(*this);
320
321 // This needs to happen after ExternalSemaSource::InitializeSema(this) or we
322 // will not be able to merge any duplicate __va_list_tag decls correctly.
323 VAListTagName = PP.getIdentifierInfo("__va_list_tag");
324
325 if (!TUScope)
326 return;
327
328 // Initialize predefined 128-bit integer types, if needed.
332 // If either of the 128-bit integer types are unavailable to name lookup,
333 // define them now.
334 DeclarationName Int128 = &Context.Idents.get("__int128_t");
335 if (IdResolver.begin(Int128) == IdResolver.end())
337
338 DeclarationName UInt128 = &Context.Idents.get("__uint128_t");
339 if (IdResolver.begin(UInt128) == IdResolver.end())
341 }
342
343
344 // Initialize predefined Objective-C types:
345 if (getLangOpts().ObjC) {
346 // If 'SEL' does not yet refer to any declarations, make it refer to the
347 // predefined 'SEL'.
348 DeclarationName SEL = &Context.Idents.get("SEL");
349 if (IdResolver.begin(SEL) == IdResolver.end())
351
352 // If 'id' does not yet refer to any declarations, make it refer to the
353 // predefined 'id'.
355 if (IdResolver.begin(Id) == IdResolver.end())
357
358 // Create the built-in typedef for 'Class'.
362
363 // Create the built-in forward declaratino for 'Protocol'.
364 DeclarationName Protocol = &Context.Idents.get("Protocol");
365 if (IdResolver.begin(Protocol) == IdResolver.end())
367 }
368
369 // Create the internal type for the *StringMakeConstantString builtins.
370 DeclarationName ConstantString = &Context.Idents.get("__NSConstantString");
371 if (IdResolver.begin(ConstantString) == IdResolver.end())
373
374 // Initialize Microsoft "predefined C++ types".
375 if (getLangOpts().MSVCCompat) {
376 if (getLangOpts().CPlusPlus &&
377 IdResolver.begin(&Context.Idents.get("type_info")) == IdResolver.end())
380 TUScope);
381
383 }
384
385 // Initialize predefined OpenCL types and supported extensions and (optional)
386 // core features.
387 if (getLangOpts().OpenCL) {
392 auto OCLCompatibleVersion = getLangOpts().getOpenCLCompatibleVersion();
393 if (OCLCompatibleVersion >= 200) {
394 if (getLangOpts().OpenCLCPlusPlus || getLangOpts().Blocks) {
397 }
398 if (getLangOpts().OpenCLPipes)
401 addImplicitTypedef("atomic_uint",
403 addImplicitTypedef("atomic_float",
405 // OpenCLC v2.0, s6.13.11.6 requires that atomic_flag is implemented as
406 // 32-bit integer and OpenCLC v2.0, s6.1.1 int is always 32-bit wide.
408
409
410 // OpenCL v2.0 s6.13.11.6:
411 // - The atomic_long and atomic_ulong types are supported if the
412 // cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics
413 // extensions are supported.
414 // - The atomic_double type is only supported if double precision
415 // is supported and the cl_khr_int64_base_atomics and
416 // cl_khr_int64_extended_atomics extensions are supported.
417 // - If the device address space is 64-bits, the data types
418 // atomic_intptr_t, atomic_uintptr_t, atomic_size_t and
419 // atomic_ptrdiff_t are supported if the cl_khr_int64_base_atomics and
420 // cl_khr_int64_extended_atomics extensions are supported.
421
422 auto AddPointerSizeDependentTypes = [&]() {
423 auto AtomicSizeT = Context.getAtomicType(Context.getSizeType());
424 auto AtomicIntPtrT = Context.getAtomicType(Context.getIntPtrType());
425 auto AtomicUIntPtrT = Context.getAtomicType(Context.getUIntPtrType());
426 auto AtomicPtrDiffT =
428 addImplicitTypedef("atomic_size_t", AtomicSizeT);
429 addImplicitTypedef("atomic_intptr_t", AtomicIntPtrT);
430 addImplicitTypedef("atomic_uintptr_t", AtomicUIntPtrT);
431 addImplicitTypedef("atomic_ptrdiff_t", AtomicPtrDiffT);
432 };
433
434 if (Context.getTypeSize(Context.getSizeType()) == 32) {
435 AddPointerSizeDependentTypes();
436 }
437
438 if (getOpenCLOptions().isSupported("cl_khr_fp16", getLangOpts())) {
439 auto AtomicHalfT = Context.getAtomicType(Context.HalfTy);
440 addImplicitTypedef("atomic_half", AtomicHalfT);
441 }
442
443 std::vector<QualType> Atomic64BitTypes;
444 if (getOpenCLOptions().isSupported("cl_khr_int64_base_atomics",
445 getLangOpts()) &&
446 getOpenCLOptions().isSupported("cl_khr_int64_extended_atomics",
447 getLangOpts())) {
448 if (getOpenCLOptions().isSupported("cl_khr_fp64", getLangOpts())) {
449 auto AtomicDoubleT = Context.getAtomicType(Context.DoubleTy);
450 addImplicitTypedef("atomic_double", AtomicDoubleT);
451 Atomic64BitTypes.push_back(AtomicDoubleT);
452 }
453 auto AtomicLongT = Context.getAtomicType(Context.LongTy);
454 auto AtomicULongT = Context.getAtomicType(Context.UnsignedLongTy);
455 addImplicitTypedef("atomic_long", AtomicLongT);
456 addImplicitTypedef("atomic_ulong", AtomicULongT);
457
458
459 if (Context.getTypeSize(Context.getSizeType()) == 64) {
460 AddPointerSizeDependentTypes();
461 }
462 }
463 }
464
465#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
466 if (getOpenCLOptions().isSupported(#Ext, getLangOpts())) { \
467 addImplicitTypedef(#ExtType, Context.Id##Ty); \
468 }
469#include "clang/Basic/OpenCLExtensionTypes.def"
470 }
471
475#define SVE_TYPE(Name, Id, SingletonId) \
476 addImplicitTypedef(Name, Context.SingletonId);
477#include "clang/Basic/AArch64SVEACLETypes.def"
478 }
479
480 if (Context.getTargetInfo().getTriple().isPPC64()) {
481#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
482 addImplicitTypedef(#Name, Context.Id##Ty);
483#include "clang/Basic/PPCTypes.def"
484#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
485 addImplicitTypedef(#Name, Context.Id##Ty);
486#include "clang/Basic/PPCTypes.def"
487 }
488
490#define RVV_TYPE(Name, Id, SingletonId) \
491 addImplicitTypedef(Name, Context.SingletonId);
492#include "clang/Basic/RISCVVTypes.def"
493 }
494
495 if (Context.getTargetInfo().getTriple().isWasm() &&
496 Context.getTargetInfo().hasFeature("reference-types")) {
497#define WASM_TYPE(Name, Id, SingletonId) \
498 addImplicitTypedef(Name, Context.SingletonId);
499#include "clang/Basic/WebAssemblyReferenceTypes.def"
500 }
501
502 if (Context.getTargetInfo().getTriple().isAMDGPU() ||
504 Context.getAuxTargetInfo()->getTriple().isAMDGPU())) {
505#define AMDGPU_TYPE(Name, Id, SingletonId) \
506 addImplicitTypedef(Name, Context.SingletonId);
507#include "clang/Basic/AMDGPUTypes.def"
508 }
509
511 DeclarationName MSVaList = &Context.Idents.get("__builtin_ms_va_list");
512 if (IdResolver.begin(MSVaList) == IdResolver.end())
514 }
515
516 DeclarationName BuiltinVaList = &Context.Idents.get("__builtin_va_list");
517 if (IdResolver.begin(BuiltinVaList) == IdResolver.end())
519}
520
522 assert(InstantiatingSpecializations.empty() &&
523 "failed to clean up an InstantiatingTemplate?");
524
526
527 // Kill all the active scopes.
529 delete FSI;
530
531 // Tell the SemaConsumer to forget about us; we're going out of scope.
532 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
533 SC->ForgetSema();
534
535 // Detach from the external Sema source.
536 if (ExternalSemaSource *ExternalSema
537 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
538 ExternalSema->ForgetSema();
539
540 // Delete cached satisfactions.
541 std::vector<ConstraintSatisfaction *> Satisfactions;
542 Satisfactions.reserve(SatisfactionCache.size());
543 for (auto &Node : SatisfactionCache)
544 Satisfactions.push_back(&Node);
545 for (auto *Node : Satisfactions)
546 delete Node;
547
549
550 // Destroys data sharing attributes stack for OpenMP
551 OpenMP().DestroyDataSharingAttributesStack();
552
553 // Detach from the PP callback handler which outlives Sema since it's owned
554 // by the preprocessor.
555 SemaPPCallbackHandler->reset();
556}
557
559 // Only warn about this once.
561 Diag(Loc, diag::warn_stack_exhausted);
563 }
564}
565
567 llvm::function_ref<void()> Fn) {
569}
570
572 UnavailableAttr::ImplicitReason reason) {
573 // If we're not in a function, it's an error.
574 FunctionDecl *fn = dyn_cast<FunctionDecl>(CurContext);
575 if (!fn) return false;
576
577 // If we're in template instantiation, it's an error.
579 return false;
580
581 // If that function's not in a system header, it's an error.
583 return false;
584
585 // If the function is already unavailable, it's not an error.
586 if (fn->hasAttr<UnavailableAttr>()) return true;
587
588 fn->addAttr(UnavailableAttr::CreateImplicit(Context, "", reason, loc));
589 return true;
590}
591
594}
595
597 assert(E && "Cannot use with NULL ptr");
598
599 if (!ExternalSource) {
601 return;
602 }
603
604 if (auto *Ex = dyn_cast<MultiplexExternalSemaSource>(ExternalSource))
605 Ex->AddSource(E);
606 else
608}
609
610void Sema::PrintStats() const {
611 llvm::errs() << "\n*** Semantic Analysis Stats:\n";
612 llvm::errs() << NumSFINAEErrors << " SFINAE diagnostics trapped.\n";
613
614 BumpAlloc.PrintStats();
616}
617
619 QualType SrcType,
621 std::optional<NullabilityKind> ExprNullability = SrcType->getNullability();
622 if (!ExprNullability || (*ExprNullability != NullabilityKind::Nullable &&
623 *ExprNullability != NullabilityKind::NullableResult))
624 return;
625
626 std::optional<NullabilityKind> TypeNullability = DstType->getNullability();
627 if (!TypeNullability || *TypeNullability != NullabilityKind::NonNull)
628 return;
629
630 Diag(Loc, diag::warn_nullability_lost) << SrcType << DstType;
631}
632
633// Generate diagnostics when adding or removing effects in a type conversion.
636 const auto SrcFX = FunctionEffectsRef::get(SrcType);
637 const auto DstFX = FunctionEffectsRef::get(DstType);
638 if (SrcFX != DstFX) {
639 for (const auto &Diff : FunctionEffectDifferences(SrcFX, DstFX)) {
640 if (Diff.shouldDiagnoseConversion(SrcType, SrcFX, DstType, DstFX))
641 Diag(Loc, diag::warn_invalid_add_func_effects) << Diff.effectName();
642 }
643 }
644}
645
647 // nullptr only exists from C++11 on, so don't warn on its absence earlier.
649 return;
650
651 if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
652 return;
653
654 const Expr *EStripped = E->IgnoreParenImpCasts();
655 if (EStripped->getType()->isNullPtrType())
656 return;
657 if (isa<GNUNullExpr>(EStripped))
658 return;
659
660 if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
661 E->getBeginLoc()))
662 return;
663
664 // Don't diagnose the conversion from a 0 literal to a null pointer argument
665 // in a synthesized call to operator<=>.
666 if (!CodeSynthesisContexts.empty() &&
667 CodeSynthesisContexts.back().Kind ==
669 return;
670
671 // Ignore null pointers in defaulted comparison operators.
673 if (FD && FD->isDefaulted()) {
674 return;
675 }
676
677 // If it is a macro from system header, and if the macro name is not "NULL",
678 // do not warn.
679 // Note that uses of "NULL" will be ignored above on systems that define it
680 // as __null.
681 SourceLocation MaybeMacroLoc = E->getBeginLoc();
683 SourceMgr.isInSystemMacro(MaybeMacroLoc) &&
684 !findMacroSpelling(MaybeMacroLoc, "NULL"))
685 return;
686
687 Diag(E->getBeginLoc(), diag::warn_zero_as_null_pointer_constant)
689}
690
691/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
692/// If there is already an implicit cast, merge into the existing one.
693/// The result is of the given category.
695 CastKind Kind, ExprValueKind VK,
696 const CXXCastPath *BasePath,
698#ifndef NDEBUG
699 if (VK == VK_PRValue && !E->isPRValue()) {
700 switch (Kind) {
701 default:
702 llvm_unreachable(
703 ("can't implicitly cast glvalue to prvalue with this cast "
704 "kind: " +
705 std::string(CastExpr::getCastKindName(Kind)))
706 .c_str());
707 case CK_Dependent:
708 case CK_LValueToRValue:
709 case CK_ArrayToPointerDecay:
710 case CK_FunctionToPointerDecay:
711 case CK_ToVoid:
712 case CK_NonAtomicToAtomic:
713 case CK_HLSLArrayRValue:
714 break;
715 }
716 }
717 assert((VK == VK_PRValue || Kind == CK_Dependent || !E->isPRValue()) &&
718 "can't cast prvalue to glvalue");
719#endif
720
723 if (Context.hasAnyFunctionEffects() && !isCast(CCK) &&
724 Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
726
729
730 if (ExprTy == TypeTy)
731 return E;
732
733 if (Kind == CK_ArrayToPointerDecay) {
734 // C++1z [conv.array]: The temporary materialization conversion is applied.
735 // We also use this to fuel C++ DR1213, which applies to C++11 onwards.
736 if (getLangOpts().CPlusPlus && E->isPRValue()) {
737 // The temporary is an lvalue in C++98 and an xvalue otherwise.
740 if (Materialized.isInvalid())
741 return ExprError();
742 E = Materialized.get();
743 }
744 // C17 6.7.1p6 footnote 124: The implementation can treat any register
745 // declaration simply as an auto declaration. However, whether or not
746 // addressable storage is actually used, the address of any part of an
747 // object declared with storage-class specifier register cannot be
748 // computed, either explicitly(by use of the unary & operator as discussed
749 // in 6.5.3.2) or implicitly(by converting an array name to a pointer as
750 // discussed in 6.3.2.1).Thus, the only operator that can be applied to an
751 // array declared with storage-class specifier register is sizeof.
752 if (VK == VK_PRValue && !getLangOpts().CPlusPlus && !E->isPRValue()) {
753 if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
754 if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
755 if (VD->getStorageClass() == SC_Register) {
756 Diag(E->getExprLoc(), diag::err_typecheck_address_of)
757 << /*register variable*/ 3 << E->getSourceRange();
758 return ExprError();
759 }
760 }
761 }
762 }
763 }
764
765 if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
766 if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) {
767 ImpCast->setType(Ty);
768 ImpCast->setValueKind(VK);
769 return E;
770 }
771 }
772
773 return ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK,
775}
776
778 switch (ScalarTy->getScalarTypeKind()) {
779 case Type::STK_Bool: return CK_NoOp;
780 case Type::STK_CPointer: return CK_PointerToBoolean;
781 case Type::STK_BlockPointer: return CK_PointerToBoolean;
782 case Type::STK_ObjCObjectPointer: return CK_PointerToBoolean;
783 case Type::STK_MemberPointer: return CK_MemberPointerToBoolean;
784 case Type::STK_Integral: return CK_IntegralToBoolean;
785 case Type::STK_Floating: return CK_FloatingToBoolean;
786 case Type::STK_IntegralComplex: return CK_IntegralComplexToBoolean;
787 case Type::STK_FloatingComplex: return CK_FloatingComplexToBoolean;
788 case Type::STK_FixedPoint: return CK_FixedPointToBoolean;
789 }
790 llvm_unreachable("unknown scalar type kind");
791}
792
793/// Used to prune the decls of Sema's UnusedFileScopedDecls vector.
794static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) {
795 if (D->getMostRecentDecl()->isUsed())
796 return true;
797
798 if (D->isExternallyVisible())
799 return true;
800
801 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
802 // If this is a function template and none of its specializations is used,
803 // we should warn.
804 if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate())
805 for (const auto *Spec : Template->specializations())
806 if (ShouldRemoveFromUnused(SemaRef, Spec))
807 return true;
808
809 // UnusedFileScopedDecls stores the first declaration.
810 // The declaration may have become definition so check again.
811 const FunctionDecl *DeclToCheck;
812 if (FD->hasBody(DeclToCheck))
813 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
814
815 // Later redecls may add new information resulting in not having to warn,
816 // so check again.
817 DeclToCheck = FD->getMostRecentDecl();
818 if (DeclToCheck != FD)
819 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
820 }
821
822 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
823 // If a variable usable in constant expressions is referenced,
824 // don't warn if it isn't used: if the value of a variable is required
825 // for the computation of a constant expression, it doesn't make sense to
826 // warn even if the variable isn't odr-used. (isReferenced doesn't
827 // precisely reflect that, but it's a decent approximation.)
828 if (VD->isReferenced() &&
829 VD->mightBeUsableInConstantExpressions(SemaRef->Context))
830 return true;
831
832 if (VarTemplateDecl *Template = VD->getDescribedVarTemplate())
833 // If this is a variable template and none of its specializations is used,
834 // we should warn.
835 for (const auto *Spec : Template->specializations())
836 if (ShouldRemoveFromUnused(SemaRef, Spec))
837 return true;
838
839 // UnusedFileScopedDecls stores the first declaration.
840 // The declaration may have become definition so check again.
841 const VarDecl *DeclToCheck = VD->getDefinition();
842 if (DeclToCheck)
843 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
844
845 // Later redecls may add new information resulting in not having to warn,
846 // so check again.
847 DeclToCheck = VD->getMostRecentDecl();
848 if (DeclToCheck != VD)
849 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
850 }
851
852 return false;
853}
854
855static bool isFunctionOrVarDeclExternC(const NamedDecl *ND) {
856 if (const auto *FD = dyn_cast<FunctionDecl>(ND))
857 return FD->isExternC();
858 return cast<VarDecl>(ND)->isExternC();
859}
860
861/// Determine whether ND is an external-linkage function or variable whose
862/// type has no linkage.
864 // Note: it's not quite enough to check whether VD has UniqueExternalLinkage,
865 // because we also want to catch the case where its type has VisibleNoLinkage,
866 // which does not affect the linkage of VD.
867 return getLangOpts().CPlusPlus && VD->hasExternalFormalLinkage() &&
870}
871
872/// Obtains a sorted list of functions and variables that are undefined but
873/// ODR-used.
875 SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined) {
876 for (const auto &UndefinedUse : UndefinedButUsed) {
877 NamedDecl *ND = UndefinedUse.first;
878
879 // Ignore attributes that have become invalid.
880 if (ND->isInvalidDecl()) continue;
881
882 // __attribute__((weakref)) is basically a definition.
883 if (ND->hasAttr<WeakRefAttr>()) continue;
884
885 if (isa<CXXDeductionGuideDecl>(ND))
886 continue;
887
888 if (ND->hasAttr<DLLImportAttr>() || ND->hasAttr<DLLExportAttr>()) {
889 // An exported function will always be emitted when defined, so even if
890 // the function is inline, it doesn't have to be emitted in this TU. An
891 // imported function implies that it has been exported somewhere else.
892 continue;
893 }
894
895 if (const auto *FD = dyn_cast<FunctionDecl>(ND)) {
896 if (FD->isDefined())
897 continue;
898 if (FD->isExternallyVisible() &&
900 !FD->getMostRecentDecl()->isInlined() &&
901 !FD->hasAttr<ExcludeFromExplicitInstantiationAttr>())
902 continue;
903 if (FD->getBuiltinID())
904 continue;
905 } else {
906 const auto *VD = cast<VarDecl>(ND);
907 if (VD->hasDefinition() != VarDecl::DeclarationOnly)
908 continue;
909 if (VD->isExternallyVisible() &&
911 !VD->getMostRecentDecl()->isInline() &&
912 !VD->hasAttr<ExcludeFromExplicitInstantiationAttr>())
913 continue;
914
915 // Skip VarDecls that lack formal definitions but which we know are in
916 // fact defined somewhere.
917 if (VD->isKnownToBeDefined())
918 continue;
919 }
920
921 Undefined.push_back(std::make_pair(ND, UndefinedUse.second));
922 }
923}
924
925/// checkUndefinedButUsed - Check for undefined objects with internal linkage
926/// or that are inline.
928 if (S.UndefinedButUsed.empty()) return;
929
930 // Collect all the still-undefined entities with internal linkage.
932 S.getUndefinedButUsed(Undefined);
933 S.UndefinedButUsed.clear();
934 if (Undefined.empty()) return;
935
936 for (const auto &Undef : Undefined) {
937 ValueDecl *VD = cast<ValueDecl>(Undef.first);
938 SourceLocation UseLoc = Undef.second;
939
940 if (S.isExternalWithNoLinkageType(VD)) {
941 // C++ [basic.link]p8:
942 // A type without linkage shall not be used as the type of a variable
943 // or function with external linkage unless
944 // -- the entity has C language linkage
945 // -- the entity is not odr-used or is defined in the same TU
946 //
947 // As an extension, accept this in cases where the type is externally
948 // visible, since the function or variable actually can be defined in
949 // another translation unit in that case.
951 ? diag::ext_undefined_internal_type
952 : diag::err_undefined_internal_type)
953 << isa<VarDecl>(VD) << VD;
954 } else if (!VD->isExternallyVisible()) {
955 // FIXME: We can promote this to an error. The function or variable can't
956 // be defined anywhere else, so the program must necessarily violate the
957 // one definition rule.
958 bool IsImplicitBase = false;
959 if (const auto *BaseD = dyn_cast<FunctionDecl>(VD)) {
960 auto *DVAttr = BaseD->getAttr<OMPDeclareVariantAttr>();
961 if (DVAttr && !DVAttr->getTraitInfo().isExtensionActive(
962 llvm::omp::TraitProperty::
963 implementation_extension_disable_implicit_base)) {
964 const auto *Func = cast<FunctionDecl>(
965 cast<DeclRefExpr>(DVAttr->getVariantFuncRef())->getDecl());
966 IsImplicitBase = BaseD->isImplicit() &&
967 Func->getIdentifier()->isMangledOpenMPVariantName();
968 }
969 }
970 if (!S.getLangOpts().OpenMP || !IsImplicitBase)
971 S.Diag(VD->getLocation(), diag::warn_undefined_internal)
972 << isa<VarDecl>(VD) << VD;
973 } else if (auto *FD = dyn_cast<FunctionDecl>(VD)) {
974 (void)FD;
975 assert(FD->getMostRecentDecl()->isInlined() &&
976 "used object requires definition but isn't inline or internal?");
977 // FIXME: This is ill-formed; we should reject.
978 S.Diag(VD->getLocation(), diag::warn_undefined_inline) << VD;
979 } else {
980 assert(cast<VarDecl>(VD)->getMostRecentDecl()->isInline() &&
981 "used var requires definition but isn't inline or internal?");
982 S.Diag(VD->getLocation(), diag::err_undefined_inline_var) << VD;
983 }
984 if (UseLoc.isValid())
985 S.Diag(UseLoc, diag::note_used_here);
986 }
987}
988
990 if (!ExternalSource)
991 return;
992
994 ExternalSource->ReadWeakUndeclaredIdentifiers(WeakIDs);
995 for (auto &WeakID : WeakIDs)
996 (void)WeakUndeclaredIdentifiers[WeakID.first].insert(WeakID.second);
997}
998
999
1000typedef llvm::DenseMap<const CXXRecordDecl*, bool> RecordCompleteMap;
1001
1002/// Returns true, if all methods and nested classes of the given
1003/// CXXRecordDecl are defined in this translation unit.
1004///
1005/// Should only be called from ActOnEndOfTranslationUnit so that all
1006/// definitions are actually read.
1008 RecordCompleteMap &MNCComplete) {
1009 RecordCompleteMap::iterator Cache = MNCComplete.find(RD);
1010 if (Cache != MNCComplete.end())
1011 return Cache->second;
1012 if (!RD->isCompleteDefinition())
1013 return false;
1014 bool Complete = true;
1016 E = RD->decls_end();
1017 I != E && Complete; ++I) {
1018 if (const CXXMethodDecl *M = dyn_cast<CXXMethodDecl>(*I))
1019 Complete = M->isDefined() || M->isDefaulted() ||
1020 (M->isPureVirtual() && !isa<CXXDestructorDecl>(M));
1021 else if (const FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(*I))
1022 // If the template function is marked as late template parsed at this
1023 // point, it has not been instantiated and therefore we have not
1024 // performed semantic analysis on it yet, so we cannot know if the type
1025 // can be considered complete.
1026 Complete = !F->getTemplatedDecl()->isLateTemplateParsed() &&
1027 F->getTemplatedDecl()->isDefined();
1028 else if (const CXXRecordDecl *R = dyn_cast<CXXRecordDecl>(*I)) {
1029 if (R->isInjectedClassName())
1030 continue;
1031 if (R->hasDefinition())
1032 Complete = MethodsAndNestedClassesComplete(R->getDefinition(),
1033 MNCComplete);
1034 else
1035 Complete = false;
1036 }
1037 }
1038 MNCComplete[RD] = Complete;
1039 return Complete;
1040}
1041
1042/// Returns true, if the given CXXRecordDecl is fully defined in this
1043/// translation unit, i.e. all methods are defined or pure virtual and all
1044/// friends, friend functions and nested classes are fully defined in this
1045/// translation unit.
1046///
1047/// Should only be called from ActOnEndOfTranslationUnit so that all
1048/// definitions are actually read.
1050 RecordCompleteMap &RecordsComplete,
1051 RecordCompleteMap &MNCComplete) {
1052 RecordCompleteMap::iterator Cache = RecordsComplete.find(RD);
1053 if (Cache != RecordsComplete.end())
1054 return Cache->second;
1055 bool Complete = MethodsAndNestedClassesComplete(RD, MNCComplete);
1057 E = RD->friend_end();
1058 I != E && Complete; ++I) {
1059 // Check if friend classes and methods are complete.
1060 if (TypeSourceInfo *TSI = (*I)->getFriendType()) {
1061 // Friend classes are available as the TypeSourceInfo of the FriendDecl.
1062 if (CXXRecordDecl *FriendD = TSI->getType()->getAsCXXRecordDecl())
1063 Complete = MethodsAndNestedClassesComplete(FriendD, MNCComplete);
1064 else
1065 Complete = false;
1066 } else {
1067 // Friend functions are available through the NamedDecl of FriendDecl.
1068 if (const FunctionDecl *FD =
1069 dyn_cast<FunctionDecl>((*I)->getFriendDecl()))
1070 Complete = FD->isDefined();
1071 else
1072 // This is a template friend, give up.
1073 Complete = false;
1074 }
1075 }
1076 RecordsComplete[RD] = Complete;
1077 return Complete;
1078}
1079
1081 if (ExternalSource)
1082 ExternalSource->ReadUnusedLocalTypedefNameCandidates(
1085 if (TD->isReferenced())
1086 continue;
1087 Diag(TD->getLocation(), diag::warn_unused_local_typedef)
1088 << isa<TypeAliasDecl>(TD) << TD->getDeclName();
1089 }
1091}
1092
1094 if (getLangOpts().CPlusPlusModules &&
1095 getLangOpts().getCompilingModule() == LangOptions::CMK_HeaderUnit)
1096 HandleStartOfHeaderUnit();
1097}
1098
1100 // No explicit actions are required at the end of the global module fragment.
1101 if (Kind == TUFragmentKind::Global)
1102 return;
1103
1104 // Transfer late parsed template instantiations over to the pending template
1105 // instantiation list. During normal compilation, the late template parser
1106 // will be installed and instantiating these templates will succeed.
1107 //
1108 // If we are building a TU prefix for serialization, it is also safe to
1109 // transfer these over, even though they are not parsed. The end of the TU
1110 // should be outside of any eager template instantiation scope, so when this
1111 // AST is deserialized, these templates will not be parsed until the end of
1112 // the combined TU.
1117
1118 // If DefinedUsedVTables ends up marking any virtual member functions it
1119 // might lead to more pending template instantiations, which we then need
1120 // to instantiate.
1122
1123 // C++: Perform implicit template instantiations.
1124 //
1125 // FIXME: When we perform these implicit instantiations, we do not
1126 // carefully keep track of the point of instantiation (C++ [temp.point]).
1127 // This means that name lookup that occurs within the template
1128 // instantiation will always happen at the end of the translation unit,
1129 // so it will find some names that are not required to be found. This is
1130 // valid, but we could do better by diagnosing if an instantiation uses a
1131 // name that was not visible at its first point of instantiation.
1132 if (ExternalSource) {
1133 // Load pending instantiations from the external source.
1135 ExternalSource->ReadPendingInstantiations(Pending);
1136 for (auto PII : Pending)
1137 if (auto Func = dyn_cast<FunctionDecl>(PII.first))
1138 Func->setInstantiationIsPending(true);
1140 Pending.begin(), Pending.end());
1141 }
1142
1143 {
1144 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
1146 }
1147
1149
1150 assert(LateParsedInstantiations.empty() &&
1151 "end of TU template instantiation should not create more "
1152 "late-parsed templates");
1153
1154 // Report diagnostics for uncorrected delayed typos. Ideally all of them
1155 // should have been corrected by that time, but it is very hard to cover all
1156 // cases in practice.
1157 for (const auto &Typo : DelayedTypos) {
1158 // We pass an empty TypoCorrection to indicate no correction was performed.
1159 Typo.second.DiagHandler(TypoCorrection());
1160 }
1161 DelayedTypos.clear();
1162}
1163
1165 assert(DelayedDiagnostics.getCurrentPool() == nullptr
1166 && "reached end of translation unit with a pool attached?");
1167
1168 // If code completion is enabled, don't perform any end-of-translation-unit
1169 // work.
1171 return;
1172
1173 // Complete translation units and modules define vtables and perform implicit
1174 // instantiations. PCH files do not.
1175 if (TUKind != TU_Prefix) {
1177
1179 !ModuleScopes.empty() && ModuleScopes.back().Module->Kind ==
1183
1186
1188 } else {
1189 // If we are building a TU prefix for serialization, it is safe to transfer
1190 // these over, even though they are not parsed. The end of the TU should be
1191 // outside of any eager template instantiation scope, so when this AST is
1192 // deserialized, these templates will not be parsed until the end of the
1193 // combined TU.
1198
1199 if (LangOpts.PCHInstantiateTemplates) {
1200 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
1202 }
1203 }
1204
1208
1209 // All delayed member exception specs should be checked or we end up accepting
1210 // incompatible declarations.
1213
1214 // All dllexport classes should have been processed already.
1215 assert(DelayedDllExportClasses.empty());
1216 assert(DelayedDllExportMemberFunctions.empty());
1217
1218 // Remove file scoped decls that turned out to be used.
1220 std::remove_if(UnusedFileScopedDecls.begin(nullptr, true),
1222 [this](const DeclaratorDecl *DD) {
1223 return ShouldRemoveFromUnused(this, DD);
1224 }),
1226
1227 if (TUKind == TU_Prefix) {
1228 // Translation unit prefixes don't need any of the checking below.
1230 TUScope = nullptr;
1231 return;
1232 }
1233
1234 // Check for #pragma weak identifiers that were never declared
1236 for (const auto &WeakIDs : WeakUndeclaredIdentifiers) {
1237 if (WeakIDs.second.empty())
1238 continue;
1239
1240 Decl *PrevDecl = LookupSingleName(TUScope, WeakIDs.first, SourceLocation(),
1242 if (PrevDecl != nullptr &&
1243 !(isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl)))
1244 for (const auto &WI : WeakIDs.second)
1245 Diag(WI.getLocation(), diag::warn_attribute_wrong_decl_type)
1246 << "'weak'" << /*isRegularKeyword=*/0 << ExpectedVariableOrFunction;
1247 else
1248 for (const auto &WI : WeakIDs.second)
1249 Diag(WI.getLocation(), diag::warn_weak_identifier_undeclared)
1250 << WeakIDs.first;
1251 }
1252
1253 if (LangOpts.CPlusPlus11 &&
1254 !Diags.isIgnored(diag::warn_delegating_ctor_cycle, SourceLocation()))
1256
1257 if (!Diags.hasErrorOccurred()) {
1258 if (ExternalSource)
1259 ExternalSource->ReadUndefinedButUsed(UndefinedButUsed);
1260 checkUndefinedButUsed(*this);
1261 }
1262
1263 // A global-module-fragment is only permitted within a module unit.
1264 if (!ModuleScopes.empty() && ModuleScopes.back().Module->Kind ==
1266 Diag(ModuleScopes.back().BeginLoc,
1267 diag::err_module_declaration_missing_after_global_module_introducer);
1268 }
1269
1270 // Now we can decide whether the modules we're building need an initializer.
1271 if (Module *CurrentModule = getCurrentModule();
1272 CurrentModule && CurrentModule->isInterfaceOrPartition()) {
1273 auto DoesModNeedInit = [this](Module *M) {
1274 if (!getASTContext().getModuleInitializers(M).empty())
1275 return true;
1276 for (auto [Exported, _] : M->Exports)
1277 if (Exported->isNamedModuleInterfaceHasInit())
1278 return true;
1279 for (Module *I : M->Imports)
1281 return true;
1282
1283 return false;
1284 };
1285
1286 CurrentModule->NamedModuleHasInit =
1287 DoesModNeedInit(CurrentModule) ||
1288 llvm::any_of(CurrentModule->submodules(),
1289 [&](auto *SubM) { return DoesModNeedInit(SubM); });
1290 }
1291
1292 if (TUKind == TU_ClangModule) {
1293 // If we are building a module, resolve all of the exported declarations
1294 // now.
1295 if (Module *CurrentModule = PP.getCurrentModule()) {
1297
1299 Stack.push_back(CurrentModule);
1300 while (!Stack.empty()) {
1301 Module *Mod = Stack.pop_back_val();
1302
1303 // Resolve the exported declarations and conflicts.
1304 // FIXME: Actually complain, once we figure out how to teach the
1305 // diagnostic client to deal with complaints in the module map at this
1306 // point.
1307 ModMap.resolveExports(Mod, /*Complain=*/false);
1308 ModMap.resolveUses(Mod, /*Complain=*/false);
1309 ModMap.resolveConflicts(Mod, /*Complain=*/false);
1310
1311 // Queue the submodules, so their exports will also be resolved.
1312 auto SubmodulesRange = Mod->submodules();
1313 Stack.append(SubmodulesRange.begin(), SubmodulesRange.end());
1314 }
1315 }
1316
1317 // Warnings emitted in ActOnEndOfTranslationUnit() should be emitted for
1318 // modules when they are built, not every time they are used.
1320 }
1321
1322 // C++ standard modules. Diagnose cases where a function is declared inline
1323 // in the module purview but has no definition before the end of the TU or
1324 // the start of a Private Module Fragment (if one is present).
1325 if (!PendingInlineFuncDecls.empty()) {
1326 for (auto *D : PendingInlineFuncDecls) {
1327 if (auto *FD = dyn_cast<FunctionDecl>(D)) {
1328 bool DefInPMF = false;
1329 if (auto *FDD = FD->getDefinition()) {
1330 DefInPMF = FDD->getOwningModule()->isPrivateModule();
1331 if (!DefInPMF)
1332 continue;
1333 }
1334 Diag(FD->getLocation(), diag::err_export_inline_not_defined)
1335 << DefInPMF;
1336 // If we have a PMF it should be at the end of the ModuleScopes.
1337 if (DefInPMF &&
1338 ModuleScopes.back().Module->Kind == Module::PrivateModuleFragment) {
1339 Diag(ModuleScopes.back().BeginLoc,
1340 diag::note_private_module_fragment);
1341 }
1342 }
1343 }
1344 PendingInlineFuncDecls.clear();
1345 }
1346
1347 // C99 6.9.2p2:
1348 // A declaration of an identifier for an object that has file
1349 // scope without an initializer, and without a storage-class
1350 // specifier or with the storage-class specifier static,
1351 // constitutes a tentative definition. If a translation unit
1352 // contains one or more tentative definitions for an identifier,
1353 // and the translation unit contains no external definition for
1354 // that identifier, then the behavior is exactly as if the
1355 // translation unit contains a file scope declaration of that
1356 // identifier, with the composite type as of the end of the
1357 // translation unit, with an initializer equal to 0.
1358 llvm::SmallSet<VarDecl *, 32> Seen;
1359 for (TentativeDefinitionsType::iterator
1361 TEnd = TentativeDefinitions.end();
1362 T != TEnd; ++T) {
1363 VarDecl *VD = (*T)->getActingDefinition();
1364
1365 // If the tentative definition was completed, getActingDefinition() returns
1366 // null. If we've already seen this variable before, insert()'s second
1367 // return value is false.
1368 if (!VD || VD->isInvalidDecl() || !Seen.insert(VD).second)
1369 continue;
1370
1371 if (const IncompleteArrayType *ArrayT
1373 // Set the length of the array to 1 (C99 6.9.2p5).
1374 Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
1375 llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true);
1377 ArrayT->getElementType(), One, nullptr, ArraySizeModifier::Normal, 0);
1378 VD->setType(T);
1379 } else if (RequireCompleteType(VD->getLocation(), VD->getType(),
1380 diag::err_tentative_def_incomplete_type))
1381 VD->setInvalidDecl();
1382
1383 // No initialization is performed for a tentative definition.
1385
1386 // Notify the consumer that we've completed a tentative definition.
1387 if (!VD->isInvalidDecl())
1389 }
1390
1391 for (auto *D : ExternalDeclarations) {
1392 if (!D || D->isInvalidDecl() || D->getPreviousDecl() || !D->isUsed())
1393 continue;
1394
1396 }
1397
1398 if (LangOpts.HLSL)
1400 getASTContext().getTranslationUnitDecl());
1401
1402 // If there were errors, disable 'unused' warnings since they will mostly be
1403 // noise. Don't warn for a use from a module: either we should warn on all
1404 // file-scope declarations in modules or not at all, but whether the
1405 // declaration is used is immaterial.
1407 // Output warning for unused file scoped decls.
1408 for (UnusedFileScopedDeclsType::iterator
1411 I != E; ++I) {
1412 if (ShouldRemoveFromUnused(this, *I))
1413 continue;
1414
1415 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
1416 const FunctionDecl *DiagD;
1417 if (!FD->hasBody(DiagD))
1418 DiagD = FD;
1419 if (DiagD->isDeleted())
1420 continue; // Deleted functions are supposed to be unused.
1421 SourceRange DiagRange = DiagD->getLocation();
1422 if (const ASTTemplateArgumentListInfo *ASTTAL =
1424 DiagRange.setEnd(ASTTAL->RAngleLoc);
1425 if (DiagD->isReferenced()) {
1426 if (isa<CXXMethodDecl>(DiagD))
1427 Diag(DiagD->getLocation(), diag::warn_unneeded_member_function)
1428 << DiagD << DiagRange;
1429 else {
1430 if (FD->getStorageClass() == SC_Static &&
1431 !FD->isInlineSpecified() &&
1433 SourceMgr.getExpansionLoc(FD->getLocation())))
1434 Diag(DiagD->getLocation(),
1435 diag::warn_unneeded_static_internal_decl)
1436 << DiagD << DiagRange;
1437 else
1438 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
1439 << /*function=*/0 << DiagD << DiagRange;
1440 }
1441 } else if (!FD->isTargetMultiVersion() ||
1442 FD->isTargetMultiVersionDefault()) {
1443 if (FD->getDescribedFunctionTemplate())
1444 Diag(DiagD->getLocation(), diag::warn_unused_template)
1445 << /*function=*/0 << DiagD << DiagRange;
1446 else
1447 Diag(DiagD->getLocation(), isa<CXXMethodDecl>(DiagD)
1448 ? diag::warn_unused_member_function
1449 : diag::warn_unused_function)
1450 << DiagD << DiagRange;
1451 }
1452 } else {
1453 const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition();
1454 if (!DiagD)
1455 DiagD = cast<VarDecl>(*I);
1456 SourceRange DiagRange = DiagD->getLocation();
1457 if (const auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(DiagD)) {
1458 if (const ASTTemplateArgumentListInfo *ASTTAL =
1459 VTSD->getTemplateArgsAsWritten())
1460 DiagRange.setEnd(ASTTAL->RAngleLoc);
1461 }
1462 if (DiagD->isReferenced()) {
1463 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
1464 << /*variable=*/1 << DiagD << DiagRange;
1465 } else if (DiagD->getDescribedVarTemplate()) {
1466 Diag(DiagD->getLocation(), diag::warn_unused_template)
1467 << /*variable=*/1 << DiagD << DiagRange;
1468 } else if (DiagD->getType().isConstQualified()) {
1469 const SourceManager &SM = SourceMgr;
1470 if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) ||
1472 Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
1473 << DiagD << DiagRange;
1474 } else {
1475 Diag(DiagD->getLocation(), diag::warn_unused_variable)
1476 << DiagD << DiagRange;
1477 }
1478 }
1479 }
1480
1482 }
1483
1484 if (!Diags.isIgnored(diag::warn_unused_private_field, SourceLocation())) {
1485 // FIXME: Load additional unused private field candidates from the external
1486 // source.
1487 RecordCompleteMap RecordsComplete;
1488 RecordCompleteMap MNCComplete;
1489 for (const NamedDecl *D : UnusedPrivateFields) {
1490 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext());
1491 if (RD && !RD->isUnion() &&
1492 IsRecordFullyDefined(RD, RecordsComplete, MNCComplete)) {
1493 Diag(D->getLocation(), diag::warn_unused_private_field)
1494 << D->getDeclName();
1495 }
1496 }
1497 }
1498
1499 if (!Diags.isIgnored(diag::warn_mismatched_delete_new, SourceLocation())) {
1500 if (ExternalSource)
1501 ExternalSource->ReadMismatchingDeleteExpressions(DeleteExprs);
1502 for (const auto &DeletedFieldInfo : DeleteExprs) {
1503 for (const auto &DeleteExprLoc : DeletedFieldInfo.second) {
1504 AnalyzeDeleteExprMismatch(DeletedFieldInfo.first, DeleteExprLoc.first,
1505 DeleteExprLoc.second);
1506 }
1507 }
1508 }
1509
1511
1512 // Check we've noticed that we're no longer parsing the initializer for every
1513 // variable. If we miss cases, then at best we have a performance issue and
1514 // at worst a rejects-valid bug.
1515 assert(ParsingInitForAutoVars.empty() &&
1516 "Didn't unmark var as having its initializer parsed");
1517
1519 TUScope = nullptr;
1520}
1521
1522
1523//===----------------------------------------------------------------------===//
1524// Helper functions.
1525//===----------------------------------------------------------------------===//
1526
1528 DeclContext *DC = CurContext;
1529
1530 while (true) {
1531 if (isa<BlockDecl>(DC) || isa<EnumDecl>(DC) || isa<CapturedDecl>(DC) ||
1532 isa<RequiresExprBodyDecl>(DC)) {
1533 DC = DC->getParent();
1534 } else if (!AllowLambda && isa<CXXMethodDecl>(DC) &&
1535 cast<CXXMethodDecl>(DC)->getOverloadedOperator() == OO_Call &&
1536 cast<CXXRecordDecl>(DC->getParent())->isLambda()) {
1537 DC = DC->getParent()->getParent();
1538 } else break;
1539 }
1540
1541 return DC;
1542}
1543
1544/// getCurFunctionDecl - If inside of a function body, this returns a pointer
1545/// to the function decl for the function being parsed. If we're currently
1546/// in a 'block', this returns the containing context.
1547FunctionDecl *Sema::getCurFunctionDecl(bool AllowLambda) const {
1548 DeclContext *DC = getFunctionLevelDeclContext(AllowLambda);
1549 return dyn_cast<FunctionDecl>(DC);
1550}
1551
1554 while (isa<RecordDecl>(DC))
1555 DC = DC->getParent();
1556 return dyn_cast<ObjCMethodDecl>(DC);
1557}
1558
1561 if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC))
1562 return cast<NamedDecl>(DC);
1563 return nullptr;
1564}
1565
1567 if (getLangOpts().OpenCL)
1569 return LangAS::Default;
1570}
1571
1572void Sema::EmitCurrentDiagnostic(unsigned DiagID) {
1573 // FIXME: It doesn't make sense to me that DiagID is an incoming argument here
1574 // and yet we also use the current diag ID on the DiagnosticsEngine. This has
1575 // been made more painfully obvious by the refactor that introduced this
1576 // function, but it is possible that the incoming argument can be
1577 // eliminated. If it truly cannot be (for example, there is some reentrancy
1578 // issue I am not seeing yet), then there should at least be a clarifying
1579 // comment somewhere.
1580 if (std::optional<TemplateDeductionInfo *> Info = isSFINAEContext()) {
1584 // We'll report the diagnostic below.
1585 break;
1586
1588 // Count this failure so that we know that template argument deduction
1589 // has failed.
1591
1592 // Make a copy of this suppressed diagnostic and store it with the
1593 // template-deduction information.
1594 if (*Info && !(*Info)->hasSFINAEDiagnostic()) {
1595 Diagnostic DiagInfo(&Diags);
1596 (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(),
1598 }
1599
1601 Diags.Clear();
1602 return;
1603
1605 // Per C++ Core Issue 1170, access control is part of SFINAE.
1606 // Additionally, the AccessCheckingSFINAE flag can be used to temporarily
1607 // make access control a part of SFINAE for the purposes of checking
1608 // type traits.
1610 break;
1611
1613
1614 // Suppress this diagnostic.
1616
1617 // Make a copy of this suppressed diagnostic and store it with the
1618 // template-deduction information.
1619 if (*Info && !(*Info)->hasSFINAEDiagnostic()) {
1620 Diagnostic DiagInfo(&Diags);
1621 (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(),
1623 }
1624
1626 Diags.Clear();
1627
1628 // Now the diagnostic state is clear, produce a C++98 compatibility
1629 // warning.
1630 Diag(Loc, diag::warn_cxx98_compat_sfinae_access_control);
1631
1632 // The last diagnostic which Sema produced was ignored. Suppress any
1633 // notes attached to it.
1635 return;
1636 }
1637
1639 // Make a copy of this suppressed diagnostic and store it with the
1640 // template-deduction information;
1641 if (*Info) {
1642 Diagnostic DiagInfo(&Diags);
1643 (*Info)->addSuppressedDiagnostic(DiagInfo.getLocation(),
1645 }
1646
1647 // Suppress this diagnostic.
1649 Diags.Clear();
1650 return;
1651 }
1652 }
1653
1654 // Copy the diagnostic printing policy over the ASTContext printing policy.
1655 // TODO: Stop doing that. See: https://reviews.llvm.org/D45093#1090292
1657
1658 // Emit the diagnostic.
1660 return;
1661
1662 // If this is not a note, and we're in a template instantiation
1663 // that is different from the last template instantiation where
1664 // we emitted an error, print a template instantiation
1665 // backtrace.
1666 if (!DiagnosticIDs::isBuiltinNote(DiagID))
1668}
1669
1672 return true;
1673 auto *FD = dyn_cast<FunctionDecl>(CurContext);
1674 if (!FD)
1675 return false;
1676 auto Loc = DeviceDeferredDiags.find(FD);
1677 if (Loc == DeviceDeferredDiags.end())
1678 return false;
1679 for (auto PDAt : Loc->second) {
1680 if (DiagnosticIDs::isDefaultMappingAsError(PDAt.second.getDiagID()))
1681 return true;
1682 }
1683 return false;
1684}
1685
1686// Print notes showing how we can reach FD starting from an a priori
1687// known-callable function.
1688static void emitCallStackNotes(Sema &S, const FunctionDecl *FD) {
1689 auto FnIt = S.CUDA().DeviceKnownEmittedFns.find(FD);
1690 while (FnIt != S.CUDA().DeviceKnownEmittedFns.end()) {
1691 // Respect error limit.
1693 return;
1694 DiagnosticBuilder Builder(
1695 S.Diags.Report(FnIt->second.Loc, diag::note_called_by));
1696 Builder << FnIt->second.FD;
1697 FnIt = S.CUDA().DeviceKnownEmittedFns.find(FnIt->second.FD);
1698 }
1699}
1700
1701namespace {
1702
1703/// Helper class that emits deferred diagnostic messages if an entity directly
1704/// or indirectly using the function that causes the deferred diagnostic
1705/// messages is known to be emitted.
1706///
1707/// During parsing of AST, certain diagnostic messages are recorded as deferred
1708/// diagnostics since it is unknown whether the functions containing such
1709/// diagnostics will be emitted. A list of potentially emitted functions and
1710/// variables that may potentially trigger emission of functions are also
1711/// recorded. DeferredDiagnosticsEmitter recursively visits used functions
1712/// by each function to emit deferred diagnostics.
1713///
1714/// During the visit, certain OpenMP directives or initializer of variables
1715/// with certain OpenMP attributes will cause subsequent visiting of any
1716/// functions enter a state which is called OpenMP device context in this
1717/// implementation. The state is exited when the directive or initializer is
1718/// exited. This state can change the emission states of subsequent uses
1719/// of functions.
1720///
1721/// Conceptually the functions or variables to be visited form a use graph
1722/// where the parent node uses the child node. At any point of the visit,
1723/// the tree nodes traversed from the tree root to the current node form a use
1724/// stack. The emission state of the current node depends on two factors:
1725/// 1. the emission state of the root node
1726/// 2. whether the current node is in OpenMP device context
1727/// If the function is decided to be emitted, its contained deferred diagnostics
1728/// are emitted, together with the information about the use stack.
1729///
1730class DeferredDiagnosticsEmitter
1731 : public UsedDeclVisitor<DeferredDiagnosticsEmitter> {
1732public:
1734
1735 // Whether the function is already in the current use-path.
1737
1738 // The current use-path.
1740
1741 // Whether the visiting of the function has been done. Done[0] is for the
1742 // case not in OpenMP device context. Done[1] is for the case in OpenMP
1743 // device context. We need two sets because diagnostics emission may be
1744 // different depending on whether it is in OpenMP device context.
1746
1747 // Emission state of the root node of the current use graph.
1748 bool ShouldEmitRootNode;
1749
1750 // Current OpenMP device context level. It is initialized to 0 and each
1751 // entering of device context increases it by 1 and each exit decreases
1752 // it by 1. Non-zero value indicates it is currently in device context.
1753 unsigned InOMPDeviceContext;
1754
1755 DeferredDiagnosticsEmitter(Sema &S)
1756 : Inherited(S), ShouldEmitRootNode(false), InOMPDeviceContext(0) {}
1757
1758 bool shouldVisitDiscardedStmt() const { return false; }
1759
1760 void VisitOMPTargetDirective(OMPTargetDirective *Node) {
1761 ++InOMPDeviceContext;
1762 Inherited::VisitOMPTargetDirective(Node);
1763 --InOMPDeviceContext;
1764 }
1765
1766 void visitUsedDecl(SourceLocation Loc, Decl *D) {
1767 if (isa<VarDecl>(D))
1768 return;
1769 if (auto *FD = dyn_cast<FunctionDecl>(D))
1770 checkFunc(Loc, FD);
1771 else
1772 Inherited::visitUsedDecl(Loc, D);
1773 }
1774
1775 void checkVar(VarDecl *VD) {
1776 assert(VD->isFileVarDecl() &&
1777 "Should only check file-scope variables");
1778 if (auto *Init = VD->getInit()) {
1779 auto DevTy = OMPDeclareTargetDeclAttr::getDeviceType(VD);
1780 bool IsDev = DevTy && (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost ||
1781 *DevTy == OMPDeclareTargetDeclAttr::DT_Any);
1782 if (IsDev)
1783 ++InOMPDeviceContext;
1784 this->Visit(Init);
1785 if (IsDev)
1786 --InOMPDeviceContext;
1787 }
1788 }
1789
1790 void checkFunc(SourceLocation Loc, FunctionDecl *FD) {
1791 auto &Done = DoneMap[InOMPDeviceContext > 0 ? 1 : 0];
1792 FunctionDecl *Caller = UsePath.empty() ? nullptr : UsePath.back();
1793 if ((!ShouldEmitRootNode && !S.getLangOpts().OpenMP && !Caller) ||
1794 S.shouldIgnoreInHostDeviceCheck(FD) || InUsePath.count(FD))
1795 return;
1796 // Finalize analysis of OpenMP-specific constructs.
1797 if (Caller && S.LangOpts.OpenMP && UsePath.size() == 1 &&
1798 (ShouldEmitRootNode || InOMPDeviceContext))
1799 S.OpenMP().finalizeOpenMPDelayedAnalysis(Caller, FD, Loc);
1800 if (Caller)
1801 S.CUDA().DeviceKnownEmittedFns[FD] = {Caller, Loc};
1802 // Always emit deferred diagnostics for the direct users. This does not
1803 // lead to explosion of diagnostics since each user is visited at most
1804 // twice.
1805 if (ShouldEmitRootNode || InOMPDeviceContext)
1806 emitDeferredDiags(FD, Caller);
1807 // Do not revisit a function if the function body has been completely
1808 // visited before.
1809 if (!Done.insert(FD).second)
1810 return;
1811 InUsePath.insert(FD);
1812 UsePath.push_back(FD);
1813 if (auto *S = FD->getBody()) {
1814 this->Visit(S);
1815 }
1816 UsePath.pop_back();
1817 InUsePath.erase(FD);
1818 }
1819
1820 void checkRecordedDecl(Decl *D) {
1821 if (auto *FD = dyn_cast<FunctionDecl>(D)) {
1822 ShouldEmitRootNode = S.getEmissionStatus(FD, /*Final=*/true) ==
1823 Sema::FunctionEmissionStatus::Emitted;
1824 checkFunc(SourceLocation(), FD);
1825 } else
1826 checkVar(cast<VarDecl>(D));
1827 }
1828
1829 // Emit any deferred diagnostics for FD
1830 void emitDeferredDiags(FunctionDecl *FD, bool ShowCallStack) {
1831 auto It = S.DeviceDeferredDiags.find(FD);
1832 if (It == S.DeviceDeferredDiags.end())
1833 return;
1834 bool HasWarningOrError = false;
1835 bool FirstDiag = true;
1836 for (PartialDiagnosticAt &PDAt : It->second) {
1837 // Respect error limit.
1839 return;
1840 const SourceLocation &Loc = PDAt.first;
1841 const PartialDiagnostic &PD = PDAt.second;
1842 HasWarningOrError |=
1845 {
1846 DiagnosticBuilder Builder(S.Diags.Report(Loc, PD.getDiagID()));
1847 PD.Emit(Builder);
1848 }
1849 // Emit the note on the first diagnostic in case too many diagnostics
1850 // cause the note not emitted.
1851 if (FirstDiag && HasWarningOrError && ShowCallStack) {
1852 emitCallStackNotes(S, FD);
1853 FirstDiag = false;
1854 }
1855 }
1856 }
1857};
1858} // namespace
1859
1861 if (ExternalSource)
1862 ExternalSource->ReadDeclsToCheckForDeferredDiags(
1863 DeclsToCheckForDeferredDiags);
1864
1865 if ((DeviceDeferredDiags.empty() && !LangOpts.OpenMP) ||
1866 DeclsToCheckForDeferredDiags.empty())
1867 return;
1868
1869 DeferredDiagnosticsEmitter DDE(*this);
1870 for (auto *D : DeclsToCheckForDeferredDiags)
1871 DDE.checkRecordedDecl(D);
1872}
1873
1874// In CUDA, there are some constructs which may appear in semantically-valid
1875// code, but trigger errors if we ever generate code for the function in which
1876// they appear. Essentially every construct you're not allowed to use on the
1877// device falls into this category, because you are allowed to use these
1878// constructs in a __host__ __device__ function, but only if that function is
1879// never codegen'ed on the device.
1880//
1881// To handle semantic checking for these constructs, we keep track of the set of
1882// functions we know will be emitted, either because we could tell a priori that
1883// they would be emitted, or because they were transitively called by a
1884// known-emitted function.
1885//
1886// We also keep a partial call graph of which not-known-emitted functions call
1887// which other not-known-emitted functions.
1888//
1889// When we see something which is illegal if the current function is emitted
1890// (usually by way of DiagIfDeviceCode, DiagIfHostCode, or
1891// CheckCall), we first check if the current function is known-emitted. If
1892// so, we immediately output the diagnostic.
1893//
1894// Otherwise, we "defer" the diagnostic. It sits in Sema::DeviceDeferredDiags
1895// until we discover that the function is known-emitted, at which point we take
1896// it out of this map and emit the diagnostic.
1897
1898Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(Kind K, SourceLocation Loc,
1899 unsigned DiagID,
1900 const FunctionDecl *Fn,
1901 Sema &S)
1902 : S(S), Loc(Loc), DiagID(DiagID), Fn(Fn),
1903 ShowCallStack(K == K_ImmediateWithCallStack || K == K_Deferred) {
1904 switch (K) {
1905 case K_Nop:
1906 break;
1907 case K_Immediate:
1908 case K_ImmediateWithCallStack:
1909 ImmediateDiag.emplace(
1910 ImmediateDiagBuilder(S.Diags.Report(Loc, DiagID), S, DiagID));
1911 break;
1912 case K_Deferred:
1913 assert(Fn && "Must have a function to attach the deferred diag to.");
1914 auto &Diags = S.DeviceDeferredDiags[Fn];
1915 PartialDiagId.emplace(Diags.size());
1916 Diags.emplace_back(Loc, S.PDiag(DiagID));
1917 break;
1918 }
1919}
1920
1921Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D)
1922 : S(D.S), Loc(D.Loc), DiagID(D.DiagID), Fn(D.Fn),
1923 ShowCallStack(D.ShowCallStack), ImmediateDiag(D.ImmediateDiag),
1924 PartialDiagId(D.PartialDiagId) {
1925 // Clean the previous diagnostics.
1926 D.ShowCallStack = false;
1927 D.ImmediateDiag.reset();
1928 D.PartialDiagId.reset();
1929}
1930
1931Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() {
1932 if (ImmediateDiag) {
1933 // Emit our diagnostic and, if it was a warning or error, output a callstack
1934 // if Fn isn't a priori known-emitted.
1935 bool IsWarningOrError = S.getDiagnostics().getDiagnosticLevel(
1936 DiagID, Loc) >= DiagnosticsEngine::Warning;
1937 ImmediateDiag.reset(); // Emit the immediate diag.
1938 if (IsWarningOrError && ShowCallStack)
1939 emitCallStackNotes(S, Fn);
1940 } else {
1941 assert((!PartialDiagId || ShowCallStack) &&
1942 "Must always show call stack for deferred diags.");
1943 }
1944}
1945
1947Sema::targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD) {
1948 FD = FD ? FD : getCurFunctionDecl();
1949 if (LangOpts.OpenMP)
1950 return LangOpts.OpenMPIsTargetDevice
1951 ? OpenMP().diagIfOpenMPDeviceCode(Loc, DiagID, FD)
1952 : OpenMP().diagIfOpenMPHostCode(Loc, DiagID, FD);
1953 if (getLangOpts().CUDA)
1954 return getLangOpts().CUDAIsDevice ? CUDA().DiagIfDeviceCode(Loc, DiagID)
1955 : CUDA().DiagIfHostCode(Loc, DiagID);
1956
1957 if (getLangOpts().SYCLIsDevice)
1958 return SYCL().DiagIfDeviceCode(Loc, DiagID);
1959
1961 FD, *this);
1962}
1963
1965 if (isUnevaluatedContext() || Ty.isNull())
1966 return;
1967
1968 // The original idea behind checkTypeSupport function is that unused
1969 // declarations can be replaced with an array of bytes of the same size during
1970 // codegen, such replacement doesn't seem to be possible for types without
1971 // constant byte size like zero length arrays. So, do a deep check for SYCL.
1972 if (D && LangOpts.SYCLIsDevice) {
1974 SYCL().deepTypeCheckForDevice(Loc, Visited, D);
1975 }
1976
1977 Decl *C = cast<Decl>(getCurLexicalContext());
1978
1979 // Memcpy operations for structs containing a member with unsupported type
1980 // are ok, though.
1981 if (const auto *MD = dyn_cast<CXXMethodDecl>(C)) {
1982 if ((MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()) &&
1983 MD->isTrivial())
1984 return;
1985
1986 if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(MD))
1987 if (Ctor->isCopyOrMoveConstructor() && Ctor->isTrivial())
1988 return;
1989 }
1990
1991 // Try to associate errors with the lexical context, if that is a function, or
1992 // the value declaration otherwise.
1993 const FunctionDecl *FD = isa<FunctionDecl>(C)
1994 ? cast<FunctionDecl>(C)
1995 : dyn_cast_or_null<FunctionDecl>(D);
1996
1997 auto CheckDeviceType = [&](QualType Ty) {
1998 if (Ty->isDependentType())
1999 return;
2000
2001 if (Ty->isBitIntType()) {
2002 if (!Context.getTargetInfo().hasBitIntType()) {
2003 PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
2004 if (D)
2005 PD << D;
2006 else
2007 PD << "expression";
2008 targetDiag(Loc, PD, FD)
2009 << false /*show bit size*/ << 0 /*bitsize*/ << false /*return*/
2010 << Ty << Context.getTargetInfo().getTriple().str();
2011 }
2012 return;
2013 }
2014
2015 // Check if we are dealing with two 'long double' but with different
2016 // semantics.
2017 bool LongDoubleMismatched = false;
2018 if (Ty->isRealFloatingType() && Context.getTypeSize(Ty) == 128) {
2019 const llvm::fltSemantics &Sem = Context.getFloatTypeSemantics(Ty);
2020 if ((&Sem != &llvm::APFloat::PPCDoubleDouble() &&
2021 !Context.getTargetInfo().hasFloat128Type()) ||
2022 (&Sem == &llvm::APFloat::PPCDoubleDouble() &&
2023 !Context.getTargetInfo().hasIbm128Type()))
2024 LongDoubleMismatched = true;
2025 }
2026
2027 if ((Ty->isFloat16Type() && !Context.getTargetInfo().hasFloat16Type()) ||
2028 (Ty->isFloat128Type() && !Context.getTargetInfo().hasFloat128Type()) ||
2029 (Ty->isIbm128Type() && !Context.getTargetInfo().hasIbm128Type()) ||
2030 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
2031 !Context.getTargetInfo().hasInt128Type()) ||
2032 (Ty->isBFloat16Type() && !Context.getTargetInfo().hasBFloat16Type() &&
2033 !LangOpts.CUDAIsDevice) ||
2034 LongDoubleMismatched) {
2035 PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
2036 if (D)
2037 PD << D;
2038 else
2039 PD << "expression";
2040
2041 if (targetDiag(Loc, PD, FD)
2042 << true /*show bit size*/
2043 << static_cast<unsigned>(Context.getTypeSize(Ty)) << Ty
2044 << false /*return*/ << Context.getTargetInfo().getTriple().str()) {
2045 if (D)
2046 D->setInvalidDecl();
2047 }
2048 if (D)
2049 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2050 }
2051 };
2052
2053 auto CheckType = [&](QualType Ty, bool IsRetTy = false) {
2054 if (LangOpts.SYCLIsDevice ||
2055 (LangOpts.OpenMP && LangOpts.OpenMPIsTargetDevice) ||
2056 LangOpts.CUDAIsDevice)
2057 CheckDeviceType(Ty);
2058
2060 const TargetInfo &TI = Context.getTargetInfo();
2061 if (!TI.hasLongDoubleType() && UnqualTy == Context.LongDoubleTy) {
2062 PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
2063 if (D)
2064 PD << D;
2065 else
2066 PD << "expression";
2067
2068 if (Diag(Loc, PD, FD)
2069 << false /*show bit size*/ << 0 << Ty << false /*return*/
2070 << TI.getTriple().str()) {
2071 if (D)
2072 D->setInvalidDecl();
2073 }
2074 if (D)
2075 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2076 }
2077
2078 bool IsDouble = UnqualTy == Context.DoubleTy;
2079 bool IsFloat = UnqualTy == Context.FloatTy;
2080 if (IsRetTy && !TI.hasFPReturn() && (IsDouble || IsFloat)) {
2081 PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
2082 if (D)
2083 PD << D;
2084 else
2085 PD << "expression";
2086
2087 if (Diag(Loc, PD, FD)
2088 << false /*show bit size*/ << 0 << Ty << true /*return*/
2089 << TI.getTriple().str()) {
2090 if (D)
2091 D->setInvalidDecl();
2092 }
2093 if (D)
2094 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2095 }
2096
2097 if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType() && FD) {
2098 llvm::StringMap<bool> CallerFeatureMap;
2099 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
2100 RISCV().checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
2101 }
2102
2103 // Don't allow SVE types in functions without a SVE target.
2104 if (Ty->isSVESizelessBuiltinType() && FD) {
2105 llvm::StringMap<bool> CallerFeatureMap;
2106 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
2107 if (!Builtin::evaluateRequiredTargetFeatures("sve", CallerFeatureMap)) {
2108 if (!Builtin::evaluateRequiredTargetFeatures("sme", CallerFeatureMap))
2109 Diag(Loc, diag::err_sve_vector_in_non_sve_target) << Ty;
2110 else if (!IsArmStreamingFunction(FD,
2111 /*IncludeLocallyStreaming=*/true)) {
2112 Diag(Loc, diag::err_sve_vector_in_non_streaming_function) << Ty;
2113 }
2114 }
2115 }
2116 };
2117
2118 CheckType(Ty);
2119 if (const auto *FPTy = dyn_cast<FunctionProtoType>(Ty)) {
2120 for (const auto &ParamTy : FPTy->param_types())
2121 CheckType(ParamTy);
2122 CheckType(FPTy->getReturnType(), /*IsRetTy=*/true);
2123 }
2124 if (const auto *FNPTy = dyn_cast<FunctionNoProtoType>(Ty))
2125 CheckType(FNPTy->getReturnType(), /*IsRetTy=*/true);
2126}
2127
2128bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) {
2129 SourceLocation loc = locref;
2130 if (!loc.isMacroID()) return false;
2131
2132 // There's no good way right now to look at the intermediate
2133 // expansions, so just jump to the expansion location.
2134 loc = getSourceManager().getExpansionLoc(loc);
2135
2136 // If that's written with the name, stop here.
2137 SmallString<16> buffer;
2138 if (getPreprocessor().getSpelling(loc, buffer) == name) {
2139 locref = loc;
2140 return true;
2141 }
2142 return false;
2143}
2144
2146
2147 if (!Ctx)
2148 return nullptr;
2149
2150 Ctx = Ctx->getPrimaryContext();
2151 for (Scope *S = getCurScope(); S; S = S->getParent()) {
2152 // Ignore scopes that cannot have declarations. This is important for
2153 // out-of-line definitions of static class members.
2154 if (S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope))
2155 if (DeclContext *Entity = S->getEntity())
2156 if (Ctx == Entity->getPrimaryContext())
2157 return S;
2158 }
2159
2160 return nullptr;
2161}
2162
2163/// Enter a new function scope
2165 if (FunctionScopes.empty() && CachedFunctionScope) {
2166 // Use CachedFunctionScope to avoid allocating memory when possible.
2167 CachedFunctionScope->Clear();
2168 FunctionScopes.push_back(CachedFunctionScope.release());
2169 } else {
2170 FunctionScopes.push_back(new FunctionScopeInfo(getDiagnostics()));
2171 }
2172 if (LangOpts.OpenMP)
2173 OpenMP().pushOpenMPFunctionRegion();
2174}
2175
2177 FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics(),
2178 BlockScope, Block));
2179 CapturingFunctionScopes++;
2180}
2181
2184 FunctionScopes.push_back(LSI);
2185 CapturingFunctionScopes++;
2186 return LSI;
2187}
2188
2190 if (LambdaScopeInfo *const LSI = getCurLambda()) {
2191 LSI->AutoTemplateParameterDepth = Depth;
2192 return;
2193 }
2194 llvm_unreachable(
2195 "Remove assertion if intentionally called in a non-lambda context.");
2196}
2197
2198// Check that the type of the VarDecl has an accessible copy constructor and
2199// resolve its destructor's exception specification.
2200// This also performs initialization of block variables when they are moved
2201// to the heap. It uses the same rules as applicable for implicit moves
2202// according to the C++ standard in effect ([class.copy.elision]p3).
2203static void checkEscapingByref(VarDecl *VD, Sema &S) {
2204 QualType T = VD->getType();
2208 Expr *VarRef =
2209 new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK_LValue, Loc);
2212 if (S.getLangOpts().CPlusPlus23) {
2213 auto *E = ImplicitCastExpr::Create(S.Context, T, CK_NoOp, VarRef, nullptr,
2216 } else {
2219 VarRef);
2220 }
2221
2222 if (!Result.isInvalid()) {
2224 Expr *Init = Result.getAs<Expr>();
2226 }
2227
2228 // The destructor's exception specification is needed when IRGen generates
2229 // block copy/destroy functions. Resolve it here.
2230 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
2231 if (CXXDestructorDecl *DD = RD->getDestructor()) {
2232 auto *FPT = DD->getType()->castAs<FunctionProtoType>();
2233 S.ResolveExceptionSpec(Loc, FPT);
2234 }
2235}
2236
2237static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S) {
2238 // Set the EscapingByref flag of __block variables captured by
2239 // escaping blocks.
2240 for (const BlockDecl *BD : FSI.Blocks) {
2241 for (const BlockDecl::Capture &BC : BD->captures()) {
2242 VarDecl *VD = BC.getVariable();
2243 if (VD->hasAttr<BlocksAttr>()) {
2244 // Nothing to do if this is a __block variable captured by a
2245 // non-escaping block.
2246 if (BD->doesNotEscape())
2247 continue;
2248 VD->setEscapingByref();
2249 }
2250 // Check whether the captured variable is or contains an object of
2251 // non-trivial C union type.
2252 QualType CapType = BC.getVariable()->getType();
2255 S.checkNonTrivialCUnion(BC.getVariable()->getType(),
2256 BD->getCaretLocation(),
2259 }
2260 }
2261
2262 for (VarDecl *VD : FSI.ByrefBlockVars) {
2263 // __block variables might require us to capture a copy-initializer.
2264 if (!VD->isEscapingByref())
2265 continue;
2266 // It's currently invalid to ever have a __block variable with an
2267 // array type; should we diagnose that here?
2268 // Regardless, we don't want to ignore array nesting when
2269 // constructing this copy.
2270 if (VD->getType()->isStructureOrClassType())
2271 checkEscapingByref(VD, S);
2272 }
2273}
2274
2277 const Decl *D, QualType BlockType) {
2278 assert(!FunctionScopes.empty() && "mismatched push/pop!");
2279
2280 markEscapingByrefs(*FunctionScopes.back(), *this);
2281
2282 PoppedFunctionScopePtr Scope(FunctionScopes.pop_back_val(),
2284
2285 if (LangOpts.OpenMP)
2286 OpenMP().popOpenMPFunctionRegion(Scope.get());
2287
2288 // Issue any analysis-based warnings.
2289 if (WP && D)
2290 AnalysisWarnings.IssueWarnings(*WP, Scope.get(), D, BlockType);
2291 else
2292 for (const auto &PUD : Scope->PossiblyUnreachableDiags)
2293 Diag(PUD.Loc, PUD.PD);
2294
2295 return Scope;
2296}
2297
2300 if (!Scope->isPlainFunction())
2301 Self->CapturingFunctionScopes--;
2302 // Stash the function scope for later reuse if it's for a normal function.
2303 if (Scope->isPlainFunction() && !Self->CachedFunctionScope)
2304 Self->CachedFunctionScope.reset(Scope);
2305 else
2306 delete Scope;
2307}
2308
2309void Sema::PushCompoundScope(bool IsStmtExpr) {
2310 getCurFunction()->CompoundScopes.push_back(
2311 CompoundScopeInfo(IsStmtExpr, getCurFPFeatures()));
2312}
2313
2315 FunctionScopeInfo *CurFunction = getCurFunction();
2316 assert(!CurFunction->CompoundScopes.empty() && "mismatched push/pop");
2317
2318 CurFunction->CompoundScopes.pop_back();
2319}
2320
2322 return getCurFunction()->hasUnrecoverableErrorOccurred();
2323}
2324
2326 if (!FunctionScopes.empty())
2327 FunctionScopes.back()->setHasBranchIntoScope();
2328}
2329
2331 if (!FunctionScopes.empty())
2332 FunctionScopes.back()->setHasBranchProtectedScope();
2333}
2334
2336 if (!FunctionScopes.empty())
2337 FunctionScopes.back()->setHasIndirectGoto();
2338}
2339
2341 if (!FunctionScopes.empty())
2342 FunctionScopes.back()->setHasMustTail();
2343}
2344
2346 if (FunctionScopes.empty())
2347 return nullptr;
2348
2349 auto CurBSI = dyn_cast<BlockScopeInfo>(FunctionScopes.back());
2350 if (CurBSI && CurBSI->TheDecl &&
2351 !CurBSI->TheDecl->Encloses(CurContext)) {
2352 // We have switched contexts due to template instantiation.
2353 assert(!CodeSynthesisContexts.empty());
2354 return nullptr;
2355 }
2356
2357 return CurBSI;
2358}
2359
2361 if (FunctionScopes.empty())
2362 return nullptr;
2363
2364 for (int e = FunctionScopes.size() - 1; e >= 0; --e) {
2365 if (isa<sema::BlockScopeInfo>(FunctionScopes[e]))
2366 continue;
2367 return FunctionScopes[e];
2368 }
2369 return nullptr;
2370}
2371
2373 for (auto *Scope : llvm::reverse(FunctionScopes)) {
2374 if (auto *LSI = dyn_cast<sema::LambdaScopeInfo>(Scope)) {
2375 if (LSI->Lambda && !LSI->Lambda->Encloses(CurContext) &&
2376 LSI->AfterParameterList) {
2377 // We have switched contexts due to template instantiation.
2378 // FIXME: We should swap out the FunctionScopes during code synthesis
2379 // so that we don't need to check for this.
2380 assert(!CodeSynthesisContexts.empty());
2381 return nullptr;
2382 }
2383 return LSI;
2384 }
2385 }
2386 return nullptr;
2387}
2388
2389LambdaScopeInfo *Sema::getCurLambda(bool IgnoreNonLambdaCapturingScope) {
2390 if (FunctionScopes.empty())
2391 return nullptr;
2392
2393 auto I = FunctionScopes.rbegin();
2394 if (IgnoreNonLambdaCapturingScope) {
2395 auto E = FunctionScopes.rend();
2396 while (I != E && isa<CapturingScopeInfo>(*I) && !isa<LambdaScopeInfo>(*I))
2397 ++I;
2398 if (I == E)
2399 return nullptr;
2400 }
2401 auto *CurLSI = dyn_cast<LambdaScopeInfo>(*I);
2402 if (CurLSI && CurLSI->Lambda && CurLSI->CallOperator &&
2403 !CurLSI->Lambda->Encloses(CurContext) && CurLSI->AfterParameterList) {
2404 // We have switched contexts due to template instantiation.
2405 assert(!CodeSynthesisContexts.empty());
2406 return nullptr;
2407 }
2408
2409 return CurLSI;
2410}
2411
2412// We have a generic lambda if we parsed auto parameters, or we have
2413// an associated template parameter list.
2415 if (LambdaScopeInfo *LSI = getCurLambda()) {
2416 return (LSI->TemplateParams.size() ||
2417 LSI->GLTemplateParameterList) ? LSI : nullptr;
2418 }
2419 return nullptr;
2420}
2421
2422
2424 if (!LangOpts.RetainCommentsFromSystemHeaders &&
2425 SourceMgr.isInSystemHeader(Comment.getBegin()))
2426 return;
2427 RawComment RC(SourceMgr, Comment, LangOpts.CommentOpts, false);
2428 if (RC.isAlmostTrailingComment() || RC.hasUnsupportedSplice(SourceMgr)) {
2429 SourceRange MagicMarkerRange(Comment.getBegin(),
2430 Comment.getBegin().getLocWithOffset(3));
2431 StringRef MagicMarkerText;
2432 switch (RC.getKind()) {
2434 MagicMarkerText = "///<";
2435 break;
2437 MagicMarkerText = "/**<";
2438 break;
2440 // FIXME: are there other scenarios that could produce an invalid
2441 // raw comment here?
2442 Diag(Comment.getBegin(), diag::warn_splice_in_doxygen_comment);
2443 return;
2444 default:
2445 llvm_unreachable("if this is an almost Doxygen comment, "
2446 "it should be ordinary");
2447 }
2448 Diag(Comment.getBegin(), diag::warn_not_a_doxygen_trailing_member_comment) <<
2449 FixItHint::CreateReplacement(MagicMarkerRange, MagicMarkerText);
2450 }
2451 Context.addComment(RC);
2452}
2453
2454// Pin this vtable to this file.
2456char ExternalSemaSource::ID;
2457
2460
2463}
2464
2466 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {}
2467
2469 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &) {}
2470
2471bool Sema::tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
2472 UnresolvedSetImpl &OverloadSet) {
2473 ZeroArgCallReturnTy = QualType();
2474 OverloadSet.clear();
2475
2476 const OverloadExpr *Overloads = nullptr;
2477 bool IsMemExpr = false;
2478 if (E.getType() == Context.OverloadTy) {
2480
2481 // Ignore overloads that are pointer-to-member constants.
2483 return false;
2484
2485 Overloads = FR.Expression;
2486 } else if (E.getType() == Context.BoundMemberTy) {
2487 Overloads = dyn_cast<UnresolvedMemberExpr>(E.IgnoreParens());
2488 IsMemExpr = true;
2489 }
2490
2491 bool Ambiguous = false;
2492 bool IsMV = false;
2493
2494 if (Overloads) {
2495 for (OverloadExpr::decls_iterator it = Overloads->decls_begin(),
2496 DeclsEnd = Overloads->decls_end(); it != DeclsEnd; ++it) {
2497 OverloadSet.addDecl(*it);
2498
2499 // Check whether the function is a non-template, non-member which takes no
2500 // arguments.
2501 if (IsMemExpr)
2502 continue;
2503 if (const FunctionDecl *OverloadDecl
2504 = dyn_cast<FunctionDecl>((*it)->getUnderlyingDecl())) {
2505 if (OverloadDecl->getMinRequiredArguments() == 0) {
2506 if (!ZeroArgCallReturnTy.isNull() && !Ambiguous &&
2507 (!IsMV || !(OverloadDecl->isCPUDispatchMultiVersion() ||
2508 OverloadDecl->isCPUSpecificMultiVersion()))) {
2509 ZeroArgCallReturnTy = QualType();
2510 Ambiguous = true;
2511 } else {
2512 ZeroArgCallReturnTy = OverloadDecl->getReturnType();
2513 IsMV = OverloadDecl->isCPUDispatchMultiVersion() ||
2514 OverloadDecl->isCPUSpecificMultiVersion();
2515 }
2516 }
2517 }
2518 }
2519
2520 // If it's not a member, use better machinery to try to resolve the call
2521 if (!IsMemExpr)
2522 return !ZeroArgCallReturnTy.isNull();
2523 }
2524
2525 // Attempt to call the member with no arguments - this will correctly handle
2526 // member templates with defaults/deduction of template arguments, overloads
2527 // with default arguments, etc.
2528 if (IsMemExpr && !E.isTypeDependent()) {
2529 Sema::TentativeAnalysisScope Trap(*this);
2530 ExprResult R = BuildCallToMemberFunction(nullptr, &E, SourceLocation(),
2531 std::nullopt, SourceLocation());
2532 if (R.isUsable()) {
2533 ZeroArgCallReturnTy = R.get()->getType();
2534 return true;
2535 }
2536 return false;
2537 }
2538
2539 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(E.IgnoreParens())) {
2540 if (const auto *Fun = dyn_cast<FunctionDecl>(DeclRef->getDecl())) {
2541 if (Fun->getMinRequiredArguments() == 0)
2542 ZeroArgCallReturnTy = Fun->getReturnType();
2543 return true;
2544 }
2545 }
2546
2547 // We don't have an expression that's convenient to get a FunctionDecl from,
2548 // but we can at least check if the type is "function of 0 arguments".
2549 QualType ExprTy = E.getType();
2550 const FunctionType *FunTy = nullptr;
2551 QualType PointeeTy = ExprTy->getPointeeType();
2552 if (!PointeeTy.isNull())
2553 FunTy = PointeeTy->getAs<FunctionType>();
2554 if (!FunTy)
2555 FunTy = ExprTy->getAs<FunctionType>();
2556
2557 if (const auto *FPT = dyn_cast_if_present<FunctionProtoType>(FunTy)) {
2558 if (FPT->getNumParams() == 0)
2559 ZeroArgCallReturnTy = FunTy->getReturnType();
2560 return true;
2561 }
2562 return false;
2563}
2564
2565/// Give notes for a set of overloads.
2566///
2567/// A companion to tryExprAsCall. In cases when the name that the programmer
2568/// wrote was an overloaded function, we may be able to make some guesses about
2569/// plausible overloads based on their return types; such guesses can be handed
2570/// off to this method to be emitted as notes.
2571///
2572/// \param Overloads - The overloads to note.
2573/// \param FinalNoteLoc - If we've suppressed printing some overloads due to
2574/// -fshow-overloads=best, this is the location to attach to the note about too
2575/// many candidates. Typically this will be the location of the original
2576/// ill-formed expression.
2577static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads,
2578 const SourceLocation FinalNoteLoc) {
2579 unsigned ShownOverloads = 0;
2580 unsigned SuppressedOverloads = 0;
2581 for (UnresolvedSetImpl::iterator It = Overloads.begin(),
2582 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
2583 if (ShownOverloads >= S.Diags.getNumOverloadCandidatesToShow()) {
2584 ++SuppressedOverloads;
2585 continue;
2586 }
2587
2588 const NamedDecl *Fn = (*It)->getUnderlyingDecl();
2589 // Don't print overloads for non-default multiversioned functions.
2590 if (const auto *FD = Fn->getAsFunction()) {
2591 if (FD->isMultiVersion() && FD->hasAttr<TargetAttr>() &&
2592 !FD->getAttr<TargetAttr>()->isDefaultVersion())
2593 continue;
2594 if (FD->isMultiVersion() && FD->hasAttr<TargetVersionAttr>() &&
2595 !FD->getAttr<TargetVersionAttr>()->isDefaultVersion())
2596 continue;
2597 }
2598 S.Diag(Fn->getLocation(), diag::note_possible_target_of_call);
2599 ++ShownOverloads;
2600 }
2601
2602 S.Diags.overloadCandidatesShown(ShownOverloads);
2603
2604 if (SuppressedOverloads)
2605 S.Diag(FinalNoteLoc, diag::note_ovl_too_many_candidates)
2606 << SuppressedOverloads;
2607}
2608
2610 const UnresolvedSetImpl &Overloads,
2611 bool (*IsPlausibleResult)(QualType)) {
2612 if (!IsPlausibleResult)
2613 return noteOverloads(S, Overloads, Loc);
2614
2615 UnresolvedSet<2> PlausibleOverloads;
2616 for (OverloadExpr::decls_iterator It = Overloads.begin(),
2617 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
2618 const auto *OverloadDecl = cast<FunctionDecl>(*It);
2619 QualType OverloadResultTy = OverloadDecl->getReturnType();
2620 if (IsPlausibleResult(OverloadResultTy))
2621 PlausibleOverloads.addDecl(It.getDecl());
2622 }
2623 noteOverloads(S, PlausibleOverloads, Loc);
2624}
2625
2626/// Determine whether the given expression can be called by just
2627/// putting parentheses after it. Notably, expressions with unary
2628/// operators can't be because the unary operator will start parsing
2629/// outside the call.
2630static bool IsCallableWithAppend(const Expr *E) {
2631 E = E->IgnoreImplicit();
2632 return (!isa<CStyleCastExpr>(E) &&
2633 !isa<UnaryOperator>(E) &&
2634 !isa<BinaryOperator>(E) &&
2635 !isa<CXXOperatorCallExpr>(E));
2636}
2637
2639 if (const auto *UO = dyn_cast<UnaryOperator>(E))
2640 E = UO->getSubExpr();
2641
2642 if (const auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
2643 if (ULE->getNumDecls() == 0)
2644 return false;
2645
2646 const NamedDecl *ND = *ULE->decls_begin();
2647 if (const auto *FD = dyn_cast<FunctionDecl>(ND))
2649 }
2650 return false;
2651}
2652
2654 bool ForceComplain,
2655 bool (*IsPlausibleResult)(QualType)) {
2656 SourceLocation Loc = E.get()->getExprLoc();
2657 SourceRange Range = E.get()->getSourceRange();
2658 UnresolvedSet<4> Overloads;
2659
2660 // If this is a SFINAE context, don't try anything that might trigger ADL
2661 // prematurely.
2662 if (!isSFINAEContext()) {
2663 QualType ZeroArgCallTy;
2664 if (tryExprAsCall(*E.get(), ZeroArgCallTy, Overloads) &&
2665 !ZeroArgCallTy.isNull() &&
2666 (!IsPlausibleResult || IsPlausibleResult(ZeroArgCallTy))) {
2667 // At this point, we know E is potentially callable with 0
2668 // arguments and that it returns something of a reasonable type,
2669 // so we can emit a fixit and carry on pretending that E was
2670 // actually a CallExpr.
2671 SourceLocation ParenInsertionLoc = getLocForEndOfToken(Range.getEnd());
2672 bool IsMV = IsCPUDispatchCPUSpecificMultiVersion(E.get());
2673 Diag(Loc, PD) << /*zero-arg*/ 1 << IsMV << Range
2674 << (IsCallableWithAppend(E.get())
2675 ? FixItHint::CreateInsertion(ParenInsertionLoc,
2676 "()")
2677 : FixItHint());
2678 if (!IsMV)
2679 notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult);
2680
2681 // FIXME: Try this before emitting the fixit, and suppress diagnostics
2682 // while doing so.
2683 E = BuildCallExpr(nullptr, E.get(), Range.getEnd(), std::nullopt,
2685 return true;
2686 }
2687 }
2688 if (!ForceComplain) return false;
2689
2690 bool IsMV = IsCPUDispatchCPUSpecificMultiVersion(E.get());
2691 Diag(Loc, PD) << /*not zero-arg*/ 0 << IsMV << Range;
2692 if (!IsMV)
2693 notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult);
2694 E = ExprError();
2695 return true;
2696}
2697
2699 if (!Ident_super)
2700 Ident_super = &Context.Idents.get("super");
2701 return Ident_super;
2702}
2703
2706 unsigned OpenMPCaptureLevel) {
2707 auto *CSI = new CapturedRegionScopeInfo(
2708 getDiagnostics(), S, CD, RD, CD->getContextParam(), K,
2709 (getLangOpts().OpenMP && K == CR_OpenMP)
2710 ? OpenMP().getOpenMPNestingLevel()
2711 : 0,
2712 OpenMPCaptureLevel);
2713 CSI->ReturnType = Context.VoidTy;
2714 FunctionScopes.push_back(CSI);
2715 CapturingFunctionScopes++;
2716}
2717
2719 if (FunctionScopes.empty())
2720 return nullptr;
2721
2722 return dyn_cast<CapturedRegionScopeInfo>(FunctionScopes.back());
2723}
2724
2725const llvm::MapVector<FieldDecl *, Sema::DeleteLocs> &
2727 return DeleteExprs;
2728}
2729
2731 : S(S), OldFPFeaturesState(S.CurFPFeatures),
2732 OldOverrides(S.FpPragmaStack.CurrentValue),
2733 OldEvalMethod(S.PP.getCurrentFPEvalMethod()),
2734 OldFPPragmaLocation(S.PP.getLastFPEvalPragmaLocation()) {}
2735
2737 S.CurFPFeatures = OldFPFeaturesState;
2738 S.FpPragmaStack.CurrentValue = OldOverrides;
2739 S.PP.setCurrentFPEvalMethod(OldFPPragmaLocation, OldEvalMethod);
2740}
2741
2743 assert(D.getCXXScopeSpec().isSet() &&
2744 "can only be called for qualified names");
2745
2746 auto LR = LookupResult(*this, D.getIdentifier(), D.getBeginLoc(),
2748 DeclContext *DC = computeDeclContext(D.getCXXScopeSpec(),
2749 !D.getDeclSpec().isFriendSpecified());
2750 if (!DC)
2751 return false;
2752
2753 LookupQualifiedName(LR, DC);
2754 bool Result = llvm::all_of(LR, [](Decl *Dcl) {
2755 if (NamedDecl *ND = dyn_cast<NamedDecl>(Dcl)) {
2756 ND = ND->getUnderlyingDecl();
2757 return isa<FunctionDecl>(ND) || isa<FunctionTemplateDecl>(ND) ||
2758 isa<UsingDecl>(ND);
2759 }
2760 return false;
2761 });
2762 return Result;
2763}
2764
2766 const FunctionEffectsRef &Old, const FunctionEffectsRef &New) {
2767
2769 FunctionEffectsRef::iterator OldEnd = Old.end();
2771 FunctionEffectsRef::iterator NewEnd = New.end();
2772
2773 while (true) {
2774 int cmp = 0;
2775 if (POld == OldEnd) {
2776 if (PNew == NewEnd)
2777 break;
2778 cmp = 1;
2779 } else if (PNew == NewEnd)
2780 cmp = -1;
2781 else {
2782 FunctionEffectWithCondition Old = *POld;
2783 FunctionEffectWithCondition New = *PNew;
2784 if (Old.Effect.kind() < New.Effect.kind())
2785 cmp = -1;
2786 else if (New.Effect.kind() < Old.Effect.kind())
2787 cmp = 1;
2788 else {
2789 cmp = 0;
2790 if (Old.Cond.getCondition() != New.Cond.getCondition()) {
2791 // FIXME: Cases where the expressions are equivalent but
2792 // don't have the same identity.
2793 push_back(FunctionEffectDiff{
2795 Old, New});
2796 }
2797 }
2798 }
2799
2800 if (cmp < 0) {
2801 // removal
2802 FunctionEffectWithCondition Old = *POld;
2803 push_back(FunctionEffectDiff{
2805 ++POld;
2806 } else if (cmp > 0) {
2807 // addition
2808 FunctionEffectWithCondition New = *PNew;
2809 push_back(FunctionEffectDiff{
2811 ++PNew;
2812 } else {
2813 ++POld;
2814 ++PNew;
2815 }
2816 }
2817}
2818
2820 QualType SrcType, const FunctionEffectsRef &SrcFX, QualType DstType,
2821 const FunctionEffectsRef &DstFX) const {
2822
2823 switch (EffectKind) {
2825 // nonallocating can't be added (spoofed) during a conversion, unless we
2826 // have nonblocking.
2827 if (DiffKind == Kind::Added) {
2828 for (const auto &CFE : SrcFX) {
2829 if (CFE.Effect.kind() == FunctionEffect::Kind::NonBlocking)
2830 return false;
2831 }
2832 }
2833 [[fallthrough]];
2835 // nonblocking can't be added (spoofed) during a conversion.
2836 switch (DiffKind) {
2837 case Kind::Added:
2838 return true;
2839 case Kind::Removed:
2840 return false;
2841 case Kind::ConditionMismatch:
2842 // FIXME: Condition mismatches are too coarse right now -- expressions
2843 // which are equivalent but don't have the same identity are detected as
2844 // mismatches. We're going to diagnose those anyhow until expression
2845 // matching is better.
2846 return true;
2847 }
2850 return false;
2852 break;
2853 }
2854 llvm_unreachable("unknown effect kind");
2855}
2856
2858 const FunctionDecl &OldFunction, const FunctionEffectsRef &OldFX,
2859 const FunctionDecl &NewFunction, const FunctionEffectsRef &NewFX) const {
2860 switch (EffectKind) {
2863 // nonblocking/nonallocating can't be removed in a redeclaration.
2864 switch (DiffKind) {
2865 case Kind::Added:
2866 return false; // No diagnostic.
2867 case Kind::Removed:
2868 return true; // Issue diagnostic.
2869 case Kind::ConditionMismatch:
2870 // All these forms of mismatches are diagnosed.
2871 return true;
2872 }
2875 return false;
2877 break;
2878 }
2879 llvm_unreachable("unknown effect kind");
2880}
2881
2884 const CXXMethodDecl &OldMethod, const FunctionEffectsRef &OldFX,
2885 const CXXMethodDecl &NewMethod, const FunctionEffectsRef &NewFX) const {
2886 switch (EffectKind) {
2889 switch (DiffKind) {
2890
2891 // If added on an override, that's fine and not diagnosed.
2892 case Kind::Added:
2893 return OverrideResult::NoAction;
2894
2895 // If missing from an override (removed), propagate from base to derived.
2896 case Kind::Removed:
2897 return OverrideResult::Merge;
2898
2899 // If there's a mismatch involving the effect's polarity or condition,
2900 // issue a warning.
2901 case Kind::ConditionMismatch:
2902 return OverrideResult::Warn;
2903 }
2904
2907 return OverrideResult::NoAction;
2908
2910 break;
2911 }
2912 llvm_unreachable("unknown effect kind");
2913}
Defines the clang::ASTContext interface.
DynTypedNode Node
#define SM(sm)
Definition: Cuda.cpp:83
const Decl * D
Expr * E
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
Defines the clang::Expr interface and subclasses for C++ expressions.
llvm::DenseSet< const void * > Visited
Definition: HTMLLogger.cpp:146
llvm::MachO::FileType FileType
Definition: MachO.h:46
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.
uint32_t Id
Definition: SemaARM.cpp:1143
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 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.
SourceRange Range
Definition: SemaObjC.cpp:757
SourceLocation Loc
Definition: SemaObjC.cpp:758
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 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:2203
static bool IsCPUDispatchCPUSpecificMultiVersion(const Expr *E)
Definition: Sema.cpp:2638
llvm::DenseMap< const CXXRecordDecl *, bool > RecordCompleteMap
Definition: Sema.cpp:1000
static bool IsCallableWithAppend(const Expr *E)
Determine whether the given expression can be called by just putting parentheses after it.
Definition: Sema.cpp:2630
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:1007
static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads, const SourceLocation FinalNoteLoc)
Give notes for a set of overloads.
Definition: Sema.cpp:2577
static bool isFunctionOrVarDeclExternC(const NamedDecl *ND)
Definition: Sema.cpp:855
static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S)
Definition: Sema.cpp:2237
static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D)
Used to prune the decls of Sema's UnusedFileScopedDecls vector.
Definition: Sema.cpp:794
static void emitCallStackNotes(Sema &S, const FunctionDecl *FD)
Definition: Sema.cpp:1688
static void notePlausibleOverloads(Sema &S, SourceLocation Loc, const UnresolvedSetImpl &Overloads, bool(*IsPlausibleResult)(QualType))
Definition: Sema.cpp:2609
static void checkUndefinedButUsed(Sema &S)
checkUndefinedButUsed - Check for undefined objects with internal linkage or that are inline.
Definition: Sema.cpp:927
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:1049
Defines the SourceManager interface.
Defines utilities for dealing with stack allocation and stack space.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:34
virtual void CompleteTentativeDefinition(VarDecl *D)
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
Definition: ASTConsumer.h:104
virtual ASTMutationListener * GetASTMutationListener()
If the consumer is interested in entities getting modified after their initial creation,...
Definition: ASTConsumer.h:129
virtual void CompleteExternalDeclaration(DeclaratorDecl *D)
CompleteExternalDeclaration - Callback invoked at the end of a translation unit to notify the consume...
Definition: ASTConsumer.h:109
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:186
SourceManager & getSourceManager()
Definition: ASTContext.h:720
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1100
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
CanQualType LongTy
Definition: ASTContext.h:1127
TypedefDecl * getObjCClassDecl() const
Retrieve the typedef declaration corresponding to the predefined Objective-C 'Class' type.
TypedefDecl * getCFConstantStringDecl() const
const llvm::fltSemantics & getFloatTypeSemantics(QualType T) const
Return the APFloat 'semantics' for the specified scalar floating point type.
TypedefDecl * getObjCSelDecl() const
Retrieve the typedef corresponding to the predefined 'SEL' type in Objective-C.
TypedefDecl * buildImplicitTypedef(QualType T, StringRef Name) const
Create a new implicit TU-level typedef declaration.
TypedefDecl * getBuiltinMSVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_ms_va_list type.
TypedefDecl * getObjCIdDecl() const
Retrieve the typedef corresponding to the predefined id type in Objective-C.
CanQualType FloatTy
Definition: ASTContext.h:1130
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2625
CanQualType DoubleTy
Definition: ASTContext.h:1130
ArrayRef< Decl * > getModuleInitializers(Module *M)
Get the initializations to perform when importing a module, if any.
CanQualType LongDoubleTy
Definition: ASTContext.h:1130
void addComment(const RawComment &RC)
Definition: ASTContext.cpp:328
RecordDecl * buildImplicitRecord(StringRef Name, RecordDecl::TagKind TK=RecordDecl::TagKind::Struct) const
Create a new implicit TU-level CXXRecordDecl or RecordDecl declaration.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
Definition: ASTContext.h:2828
IdentifierTable & Idents
Definition: ASTContext.h:659
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:796
QualType getUIntPtrType() const
Return a type compatible with "uintptr_t" (C99 7.18.1.4), as defined by the target.
PartialDiagnostic::DiagStorageAllocator & getDiagAllocator()
Definition: ASTContext.h:774
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
const TargetInfo * getAuxTargetInfo() const
Definition: ASTContext.h:779
CanQualType UnsignedLongTy
Definition: ASTContext.h:1128
bool hasAnyFunctionEffects() const
Definition: ASTContext.h:2921
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
CanQualType BoundMemberTy
Definition: ASTContext.h:1146
TypedefDecl * getInt128Decl() const
Retrieve the declaration for the 128-bit signed integer type.
CanQualType IntTy
Definition: ASTContext.h:1127
LangAS getDefaultOpenCLPointeeAddrSpace()
Returns default address space based on OpenCL version and enabled features.
Definition: ASTContext.h:1459
CanQualType OverloadTy
Definition: ASTContext.h:1146
CanQualType OCLClkEventTy
Definition: ASTContext.h:1155
TypedefDecl * getUInt128Decl() const
Retrieve the declaration for the 128-bit unsigned integer type.
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:712
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2391
ObjCInterfaceDecl * getObjCProtocolDecl() const
Retrieve the Objective-C class declaration corresponding to the predefined Protocol class.
CanQualType OCLSamplerTy
Definition: ASTContext.h:1155
TypedefDecl * getBuiltinVaListDecl() const
Retrieve the C type declaration corresponding to the predefined __builtin_va_list type.
CanQualType VoidTy
Definition: ASTContext.h:1118
CanQualType UnsignedIntTy
Definition: ASTContext.h:1128
CanQualType OCLReserveIDTy
Definition: ASTContext.h:1156
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:778
CanQualType OCLQueueTy
Definition: ASTContext.h:1156
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *) const
void setBlockVarCopyInit(const VarDecl *VD, Expr *CopyExpr, bool CanThrow)
Set the copy initialization expression of a block var decl.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1224
QualType getIntPtrType() const
Return a type compatible with "intptr_t" (C99 7.18.1.4), as defined by the target.
IdentifierInfo * getBoolName() const
Retrieve the identifier 'bool'.
Definition: ASTContext.h:1975
CanQualType HalfTy
Definition: ASTContext.h:1142
CanQualType OCLEventTy
Definition: ASTContext.h:1155
void setPrintingPolicy(const clang::PrintingPolicy &Policy)
Definition: ASTContext.h:716
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
PtrTy get() const
Definition: Ownership.h:170
bool isInvalid() const
Definition: Ownership.h:166
bool isUsable() const
Definition: Ownership.h:168
A class which contains all the information about a particular captured value.
Definition: Decl.h:4473
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4467
ArrayRef< Capture > captures() const
Definition: Decl.h:4594
SourceLocation getCaretLocation() const
Definition: Decl.h:4540
bool doesNotEscape() const
Definition: Decl.h:4618
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
CXXFieldCollector - Used to keep track of CXXFieldDecls during parsing of C++ classes.
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
An iterator over the friend declarations of a class.
Definition: DeclFriend.h:186
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
friend_iterator friend_begin() const
Definition: DeclFriend.h:238
friend_iterator friend_end() const
Definition: DeclFriend.h:242
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4666
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition: Decl.h:4728
const char * getCastKindName() const
Definition: Expr.h:3546
Abstract interface for a consumer of code-completion information.
The information about the darwin SDK that was used during this compilation.
Definition: DarwinSDKInfo.h:29
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:2296
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1425
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2079
decl_iterator decls_end() const
Definition: DeclBase.h:2341
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1399
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1598
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1040
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:1055
T * getAttr() const
Definition: DeclBase.h:579
void addAttr(Attr *A)
Definition: DeclBase.cpp:1014
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:154
bool isReferenced() const
Whether any declaration of this entity was referenced.
Definition: DeclBase.cpp:577
bool isInvalidDecl() const
Definition: DeclBase.h:594
SourceLocation getLocation() const
Definition: DeclBase.h:445
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:552
DeclContext * getDeclContext()
Definition: DeclBase.h:454
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:437
bool hasAttr() const
Definition: DeclBase.h:583
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:731
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1900
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1271
static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID)
Determines whether the given built-in diagnostic ID is for an error that is suppressed if it occurs d...
static bool isDefaultMappingAsError(unsigned DiagID)
Return true if the specified diagnostic is mapped to errors by default.
static bool isBuiltinNote(unsigned DiagID)
Determine whether the given built-in diagnostic ID is a Note.
@ 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) ...
Definition: Diagnostic.h:1571
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1582
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1547
void SetArgToStringFn(ArgToStringFnTy Fn, void *Cookie)
Definition: Diagnostic.h:889
bool hasErrorOccurred() const
Definition: Diagnostic.h:843
void overloadCandidatesShown(unsigned N)
Call this after showing N overload candidates.
Definition: Diagnostic.h:746
void setLastDiagnosticIgnored(bool Ignored)
Pretend that the last diagnostic issued was ignored, so any subsequent notes will be suppressed,...
Definition: Diagnostic.h:761
unsigned getNumOverloadCandidatesToShow() const
When a call or operator fails, print out up to this many candidate overloads as suggestions.
Definition: Diagnostic.h:731
SourceLocation getCurrentDiagLoc() const
Definition: Diagnostic.h:1064
void Clear()
Clear out the current diagnostic.
Definition: Diagnostic.h:982
bool hasFatalErrorOccurred() const
Definition: Diagnostic.h:850
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition: Diagnostic.h:916
Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const
Based on the way the client configured the DiagnosticsEngine object, classify the specified diagnosti...
Definition: Diagnostic.h:931
bool EmitCurrentDiagnostic(bool Force=false)
Emit the current diagnostic and clear the diagnostic state.
Definition: Diagnostic.cpp:527
bool getSuppressSystemWarnings() const
Definition: Diagnostic.h:690
unsigned getCurrentDiagID() const
Definition: Diagnostic.h:1062
Expr * getCondition() const
Definition: Type.h:4781
RAII object that enters a new expression evaluation context.
This represents one expression.
Definition: Expr.h:110
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Definition: Expr.cpp:3070
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3058
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3066
bool isPRValue() const
Definition: Expr.h:278
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
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:2459
virtual void ReadMethodPool(Selector Sel)
Load the contents of the global method pool for a given selector.
Definition: Sema.cpp:2458
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:2465
~ExternalSemaSource() override
Definition: Sema.cpp:2455
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:2461
virtual void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 > > &)
Definition: Sema.cpp:2468
Represents difference between two FPOptions values.
Definition: LangOptions.h:919
Represents a member of a struct/union/class.
Definition: Decl.h:3030
StringRef getName() const
The name of this FileEntry.
Definition: FileEntry.h:61
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
llvm::vfs::FileSystem & getVirtualFileSystem() const
Definition: FileManager.h:251
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:71
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Definition: Diagnostic.h:134
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.
Definition: Diagnostic.h:97
Represents a function declaration or definition.
Definition: Decl.h:1932
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Definition: Decl.h:2562
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3224
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
Definition: Decl.cpp:3564
bool isDeleted() const
Whether this function has been deleted.
Definition: Decl.h:2465
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
Definition: Decl.cpp:3560
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2310
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition: Decl.cpp:4176
Support iteration in parallel through a pair of FunctionEffect and EffectConditionExpr containers.
Definition: Type.h:4806
Kind kind() const
The kind of the effect.
Definition: Type.h:4714
An immutable set of FunctionEffects and possibly conditions attached to them.
Definition: Type.h:4853
iterator begin() const
Definition: Type.h:4891
iterator end() const
Definition: Type.h:4892
static FunctionEffectsRef get(QualType QT)
Extract the effects from a Type if it is a function, block, or member function pointer,...
Definition: Type.h:8621
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4973
Declaration of a template function.
Definition: DeclTemplate.h:957
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4278
QualType getReturnType() const
Definition: Type.h:4600
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:833
HeaderSearchOptions & getHeaderSearchOpts() const
Retrieve the header-search options with which this header search was initialized.
Definition: HeaderSearch.h:382
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
iterator begin(DeclarationName Name)
Returns an iterator over decls with the name 'Name'.
iterator end()
Returns the end iterator.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3675
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2074
Represents a C array with an unspecified size.
Definition: Type.h:3725
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type)
@ CMK_HeaderUnit
Compiling a module header unit.
Definition: LangOptions.h:105
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i....
Definition: LangOptions.h:553
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:525
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
Definition: LangOptions.cpp:63
void erase(iterator From, iterator To)
iterator begin(Source *source, bool LocalOnly=false)
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.
Definition: Lexer.cpp:850
Represents the results of name lookup.
Definition: Lookup.h:46
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
Abstract interface for a module loader.
Definition: ModuleLoader.h:82
bool resolveExports(Module *Mod, bool Complain)
Resolve all of the unresolved exports in the given module.
Definition: ModuleMap.cpp:1399
bool resolveConflicts(Module *Mod, bool Complain)
Resolve all of the unresolved conflicts in the given module.
Definition: ModuleMap.cpp:1426
bool resolveUses(Module *Mod, bool Complain)
Resolve all of the unresolved uses in the given module.
Definition: ModuleMap.cpp:1412
Describes a module or submodule.
Definition: Module.h:105
bool isNamedModuleInterfaceHasInit() const
Definition: Module.h:628
bool isInterfaceOrPartition() const
Definition: Module.h:615
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition: Module.h:402
llvm::iterator_range< submodule_iterator > submodules()
Definition: Module.h:783
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
Definition: Module.h:141
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
Definition: Module.h:138
An abstract interface that should be implemented by external AST sources that also provide informatio...
static const unsigned NumNSNumberLiteralMethods
Definition: NSAPI.h:191
This represents a decl that may have a name.
Definition: Decl.h:249
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition: Decl.h:404
bool isExternallyVisible() const
Definition: Decl.h:408
This represents '#pragma omp target' directive.
Definition: StmtOpenMP.h:3152
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
void addSupport(const llvm::StringMap< bool > &FeaturesMap, const LangOptions &Opts)
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:2982
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
Definition: ExprCXX.h:3043
decls_iterator decls_begin() const
Definition: ExprCXX.h:3075
decls_iterator decls_end() const
Definition: ExprCXX.h:3078
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:36
void Emit(const DiagnosticBuilder &DB) const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:137
bool isIncrementalProcessingEnabled() const
Returns true if incremental processing is enabled.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
LangOptions::FPEvalMethodKind getCurrentFPEvalMethod() const
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
Definition: Preprocessor.h:295
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with this preprocessor.
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Module * getCurrentModule()
Retrieves the module that we're currently building, if any.
void setCurrentFPEvalMethod(SourceLocation PragmaLoc, LangOptions::FPEvalMethodKind Val)
FileManager & getFileManager() const
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
HeaderSearch & getHeaderSearchInfo() const
const LangOptions & getLangOpts() const
A (possibly-)qualified type.
Definition: Type.h:941
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...
Definition: Type.h:7890
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1008
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...
Definition: Type.h:7884
QualType getCanonicalType() const
Definition: Type.h:7795
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:7837
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:7816
bool hasUnsupportedSplice(const SourceManager &SourceMgr) const
@ RCK_OrdinaryC
Any normal C comment.
@ RCK_Invalid
Invalid comment.
@ RCK_OrdinaryBCPL
Any normal BCPL comments.
bool isAlmostTrailingComment() const LLVM_READONLY
Returns true if it is a probable typo:
CommentKind getKind() const LLVM_READONLY
Represents a struct/union/class.
Definition: Decl.h:4141
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:226
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
Definition: Scope.h:81
@ DeclScope
This is a scope that can contain a declaration.
Definition: Scope.h:63
Smart pointer class that efficiently represents Objective-C method names.
A generic diagnostic builder for errors which may or may not be deferred.
Definition: SemaBase.h:110
@ K_Immediate
Emit the diagnostic immediately (i.e., behave like Sema::Diag()).
Definition: SemaBase.h:116
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaBase.cpp:32
const LangOptions & getLangOpts() const
Definition: SemaBase.cpp:11
DiagnosticsEngine & getDiagnostics() const
Definition: SemaBase.cpp:10
llvm::DenseMap< CanonicalDeclPtr< const FunctionDecl >, FunctionDeclAndLoc > DeviceKnownEmittedFns
An inverse call graph, mapping known-emitted functions to one of their known-emitted callers (plus th...
Definition: SemaCUDA.h:72
An abstract interface that should be implemented by clients that read ASTs and then require further s...
Definition: SemaConsumer.h:25
void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU)
Definition: SemaHLSL.cpp:884
ObjCMethodDecl * NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]
The Objective-C NSNumber methods used to create NSNumber literals.
Definition: SemaObjC.h:614
void DiagnoseUseOfUnimplementedSelectors()
std::unique_ptr< NSAPI > NSAPIObj
Caches identifiers/selectors for NSFoundation APIs.
Definition: SemaObjC.h:599
void DiagnoseUnterminatedOpenMPDeclareTarget()
Report unterminated 'omp declare target' or 'omp begin declare target' at the end of a compilation un...
void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, const FunctionDecl *Callee, SourceLocation Loc)
Finishes analysis of the deferred functions calls that may be declared as host/nohost during device/h...
A class which encapsulates the logic for delaying diagnostics during parsing and other processing.
Definition: Sema.h:1078
sema::DelayedDiagnosticPool * getCurrentPool() const
Returns the current delayed-diagnostics pool.
Definition: Sema.h:1093
Custom deleter to allow FunctionScopeInfos to be kept alive for a short time after they've been poppe...
Definition: Sema.h:734
void operator()(sema::FunctionScopeInfo *Scope) const
Definition: Sema.cpp:2299
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
Definition: Sema.h:12119
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:535
SmallVector< DeclaratorDecl *, 4 > ExternalDeclarations
All the external declarations encoutered and used in the TU.
Definition: Sema.h:3102
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
Definition: Sema.h:13120
void LoadExternalWeakUndeclaredIdentifiers()
Load weak undeclared identifiers from the external source.
Definition: Sema.cpp:989
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:863
bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, UnresolvedSetImpl &NonTemplateOverloads)
Figure out if an expression could be turned into a call.
Definition: Sema.cpp:2471
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:8999
@ NTCUC_BlockCapture
Definition: Sema.h:3638
void addImplicitTypedef(StringRef Name, QualType T)
Definition: Sema.cpp:306
void PrintContextStack()
Definition: Sema.h:13206
SemaOpenMP & OpenMP()
Definition: Sema.h:1219
void CheckDelegatingCtorCycles()
SmallVector< CXXMethodDecl *, 4 > DelayedDllExportMemberFunctions
Definition: Sema.h:5805
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
Definition: Sema.h:958
llvm::SmallSetVector< const TypedefNameDecl *, 4 > UnusedLocalTypedefNameCandidates
Set containing all typedefs that are likely unused.
Definition: Sema.h:3084
void emitAndClearUnusedLocalTypedefWarnings()
Definition: Sema.cpp:1080
std::unique_ptr< CXXFieldCollector > FieldCollector
FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
Definition: Sema.h:6026
SemaCUDA & CUDA()
Definition: Sema.h:1164
void Initialize()
Perform initialization that occurs after the parser has been initialized but before it parses anythin...
Definition: Sema.cpp:312
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
Definition: Sema.h:940
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:2276
Scope * getScopeForContext(DeclContext *Ctx)
Determines the active Scope associated with the given declaration context.
Definition: Sema.cpp:2145
llvm::DenseSet< std::pair< Decl *, unsigned > > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
Definition: Sema.h:13123
PragmaStack< FPOptionsOverride > FpPragmaStack
Definition: Sema.h:1730
void setFunctionHasBranchIntoScope()
Definition: Sema.cpp:2325
virtual void anchor()
This virtual key function only exists to limit the emission of debug info describing the Sema class.
Definition: Sema.cpp:304
void ActOnComment(SourceRange Comment)
Definition: Sema.cpp:2423
void ActOnEndOfTranslationUnit()
ActOnEndOfTranslationUnit - This is called at the very end of the translation unit when EOF is reache...
Definition: Sema.cpp:1164
FPOptionsOverride CurFPFeatureOverrides()
Definition: Sema.h:1731
void ActOnTranslationUnitScope(Scope *S)
Scope actions.
Definition: Sema.cpp:151
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:2698
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:1547
ASTContext & Context
Definition: Sema.h:1002
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:618
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:597
SemaObjC & ObjC()
Definition: Sema.h:1204
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:2653
SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags
Diagnostics that are emitted only if we discover that the given function must be codegen'ed.
Definition: Sema.h:1134
void CheckDelayedMemberExceptionSpecs()
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
Definition: SemaDecl.cpp:1495
UnusedFileScopedDeclsType UnusedFileScopedDecls
The set of file scoped decls seen so far that have not been used and must warn if not used.
Definition: Sema.h:3092
ASTContext & getASTContext() const
Definition: Sema.h:600
SmallVector< std::pair< FunctionDecl *, FunctionDecl * >, 2 > DelayedEquivalentExceptionSpecChecks
All the function redeclarations seen during a class definition that had their exception spec checks d...
Definition: Sema.h:6130
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:694
static const unsigned MaxAlignmentExponent
The maximum alignment, same as in llvm::Value.
Definition: Sema.h:930
bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee)
Definition: SemaDecl.cpp:20211
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
Definition: Sema.h:908
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
Definition: Sema.cpp:1552
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
Definition: Sema.cpp:2414
unsigned NumSFINAEErrors
The number of SFINAE diagnostics that have been trapped.
Definition: Sema.h:11053
void setFunctionHasIndirectGoto()
Definition: Sema.cpp:2335
LangAS getDefaultCXXMethodAddrSpace() const
Returns default addr space for method qualifiers.
Definition: Sema.cpp:1566
void PushFunctionScope()
Enter a new function scope.
Definition: Sema.cpp:2164
void EmitCurrentDiagnostic(unsigned DiagID)
Cause the active diagnostic on the DiagosticsEngine to be emitted.
Definition: Sema.cpp:1572
std::unique_ptr< sema::FunctionScopeInfo, PoppedFunctionScopeDeleter > PoppedFunctionScopePtr
Definition: Sema.h:743
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr)
Definition: Sema.cpp:214
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:83
sema::LambdaScopeInfo * PushLambdaScope()
Definition: Sema.cpp:2182
void PopCompoundScope()
Definition: Sema.cpp:2314
const LangOptions & getLangOpts() const
Definition: Sema.h:593
const FunctionProtoType * ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT)
ASTConsumer & getASTConsumer() const
Definition: Sema.h:601
void * OpaqueParser
Definition: Sema.h:1046
Preprocessor & PP
Definition: Sema.h:1001
threadSafety::BeforeSet * ThreadSafetyDeclCache
Definition: Sema.h:1039
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:1964
const LangOptions & LangOpts
Definition: Sema.h:1000
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition: Sema.cpp:2389
static const uint64_t MaximumAlignment
Definition: Sema.h:931
void PerformPendingInstantiations(bool LocalOnly=false)
Performs template instantiation for all implicit template instantiations we have seen until this poin...
NamedDeclSetType UnusedPrivateFields
Set containing all declared private fields that are not used.
Definition: Sema.h:6030
SemaHLSL & HLSL()
Definition: Sema.h:1169
void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind)
Definition: Sema.cpp:1099
bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const
Definition: SemaDecl.cpp:1828
IdentifierInfo * InventAbbreviatedTemplateParameterTypeName(const IdentifierInfo *ParamName, unsigned Index)
Invent a new identifier for parameters of abbreviated templates.
Definition: Sema.cpp:117
SmallVector< PendingImplicitInstantiation, 1 > LateParsedInstantiations
Queue of implicit template instantiations that cannot be performed eagerly.
Definition: Sema.h:13504
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...
Definition: Sema.h:6122
NamedDecl * getCurFunctionOrMethodDecl() const
getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method or C function we're in,...
Definition: Sema.cpp:1559
static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy)
ScalarTypeToBooleanCastKind - Returns the cast kind corresponding to the conversion from scalar type ...
Definition: Sema.cpp:777
void PushCompoundScope(bool IsStmtExpr)
Definition: Sema.cpp:2309
bool isDeclaratorFunctionLike(Declarator &D)
Determine whether.
Definition: Sema.cpp:2742
std::optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
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:2128
FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl, bool Final=false)
Definition: SemaDecl.cpp:20131
Module * getCurrentModule() const
Get the module unit whose scope we are currently within.
Definition: Sema.h:9597
static bool isCast(CheckedConversionKind CCK)
Definition: Sema.h:2103
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition: Sema.cpp:2345
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:1137
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
Definition: SemaInit.cpp:7426
SemaOpenCL & OpenCL()
Definition: Sema.h:1214
DeclContext * getFunctionLevelDeclContext(bool AllowLambda=false) const
If AllowLambda is true, treat lambda as function.
Definition: Sema.cpp:1527
bool DefineUsedVTables()
Define all of the vtables that have been used in this translation unit and reference any virtual memb...
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
Definition: Sema.h:13471
SourceManager & getSourceManager() const
Definition: Sema.h:598
bool makeUnavailableInSystemHeader(SourceLocation loc, UnavailableAttr::ImplicitReason reason)
makeUnavailableInSystemHeader - There is an error in the current context.
Definition: Sema.cpp:571
void getUndefinedButUsed(SmallVectorImpl< std::pair< NamedDecl *, SourceLocation > > &Undefined)
Obtain a sorted list of functions that are undefined but ODR-used.
Definition: Sema.cpp:874
void diagnoseFunctionEffectConversion(QualType DstType, QualType SrcType, SourceLocation Loc)
Warn when implicitly changing function effects.
Definition: Sema.cpp:634
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.
Definition: SemaStmt.cpp:3372
void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, SourceLocation IncludeLoc)
Definition: SemaAttr.cpp:449
CanThrowResult canThrow(const Stmt *E)
bool AccessCheckingSFINAE
When true, access checking violations are treated as SFINAE failures rather than hard errors.
Definition: Sema.h:12075
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
@ NTCUK_Destruct
Definition: Sema.h:3652
@ NTCUK_Copy
Definition: Sema.h:3653
void PushBlockScope(Scope *BlockScope, BlockDecl *Block)
Definition: Sema.cpp:2176
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
Definition: Sema.h:1769
void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, RecordDecl *RD, CapturedRegionKind K, unsigned OpenMPCaptureLevel=0)
Definition: Sema.cpp:2704
void emitDeferredDiags()
Definition: Sema.cpp:1860
void setFunctionHasMustTail()
Definition: Sema.cpp:2340
bool WarnedStackExhausted
Definition: Sema.h:965
void CheckCompleteVariableDeclaration(VarDecl *VD)
Definition: SemaDecl.cpp:14152
TUFragmentKind
Definition: Sema.h:684
@ Global
The global module fragment, between 'module;' and a module-declaration.
Definition: Sema.h:686
@ Private
The private module fragment, between 'module :private;' and the end of the translation unit.
Definition: Sema.h:693
@ Normal
A normal translation unit fragment.
Definition: Sema.h:690
void setFunctionHasBranchProtectedScope()
Definition: Sema.cpp:2330
RedeclarationKind forRedeclarationInCurContext() const
void ActOnStartOfTranslationUnit()
This is called before the very first declaration in the translation unit is parsed.
Definition: Sema.cpp:1093
ASTConsumer & Consumer
Definition: Sema.h:1003
llvm::SmallPtrSet< const Decl *, 4 > ParsingInitForAutoVars
ParsingInitForAutoVars - a set of declarations with auto types for which we are currently parsing the...
Definition: Sema.h:4224
sema::AnalysisBasedWarnings AnalysisWarnings
Worker object for performing CFG-based warnings.
Definition: Sema.h:1038
bool hasUncompilableErrorOccurred() const
Whether uncompilable error has occurred.
Definition: Sema.cpp:1670
std::deque< PendingImplicitInstantiation > PendingInstantiations
The queue of implicit template instantiations that are required but have not yet been performed.
Definition: Sema.h:13500
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with the preprocessor.
Definition: Sema.cpp:87
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
std::pair< SourceLocation, bool > DeleteExprLoc
Definition: Sema.h:644
void RecordParsingTemplateParameterDepth(unsigned Depth)
This is used to inform Sema what the current TemplateParameterDepth is during Parsing.
Definition: Sema.cpp:2189
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:8885
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
Definition: Sema.h:963
void DiagnoseUnterminatedPragmaAttribute()
Definition: SemaAttr.cpp:1130
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:1235
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.
Definition: Sema.h:7989
TentativeDefinitionsType TentativeDefinitions
All the tentative definitions encountered in the TU.
Definition: Sema.h:3099
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
DarwinSDKInfo * getDarwinSDKInfoForAvailabilityChecking()
Definition: Sema.cpp:101
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:2726
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition: Sema.h:7930
void PushDeclContext(Scope *S, DeclContext *DC)
Set the current declaration context until it gets popped.
Definition: SemaDecl.cpp:1306
SourceManager & SourceMgr
Definition: Sema.h:1005
DiagnosticsEngine & Diags
Definition: Sema.h:1004
void DiagnoseUnterminatedPragmaAlignPack()
Definition: SemaAttr.cpp:488
OpenCLOptions & getOpenCLOptions()
Definition: Sema.h:594
FPOptions CurFPFeatures
Definition: Sema.h:998
LateTemplateParserCleanupCB * LateTemplateParserCleanup
Definition: Sema.h:1045
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
Definition: SemaInit.cpp:9616
llvm::MapVector< NamedDecl *, SourceLocation > UndefinedButUsed
UndefinedInternals - all the used, undefined objects which require a definition in this translation u...
Definition: Sema.h:6060
void PrintStats() const
Print out statistics about the semantic analysis.
Definition: Sema.cpp:610
llvm::BumpPtrAllocator BumpAlloc
Definition: Sema.h:949
sema::LambdaScopeInfo * getEnclosingLambda() const
Get the innermost lambda enclosing the current location, if any.
Definition: Sema.cpp:2372
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
Definition: Sema.cpp:566
void addExternalSource(ExternalSemaSource *E)
Registers an external source.
Definition: Sema.cpp:596
SmallVector< CXXRecordDecl *, 4 > DelayedDllExportClasses
Definition: Sema.h:5804
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.
Definition: Sema.h:3074
SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD=nullptr)
Definition: Sema.cpp:1947
DeclarationName VAListTagName
VAListTagName - The declaration name corresponding to __va_list_tag.
Definition: Sema.h:1061
sema::FunctionScopeInfo * getEnclosingFunction() const
Definition: Sema.cpp:2360
sema::CapturedRegionScopeInfo * getCurCapturedRegion()
Retrieve the current captured region, if any.
Definition: Sema.cpp:2718
void warnStackExhausted(SourceLocation Loc)
Warn that the stack is nearly exhausted.
Definition: Sema.cpp:558
void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E)
Warn when implicitly casting 0 to nullptr.
Definition: Sema.cpp:646
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...
Definition: SemaDecl.cpp:13203
IdentifierResolver IdResolver
Definition: Sema.h:3003
bool hasAnyUnrecoverableErrorsInThisFunction() const
Determine whether any errors occurred within this function/method/ block.
Definition: Sema.cpp:2321
ASTMutationListener * getASTMutationListener() const
Definition: Sema.cpp:592
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.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
bool isInSystemMacro(SourceLocation loc) const
Returns whether Loc is expanded from a macro in a system header.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
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...
Definition: Stmt.cpp:326
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3660
bool isUnion() const
Definition: Decl.h:3763
Exposes information about the current target.
Definition: TargetInfo.h:218
virtual bool hasLongDoubleType() const
Determine whether the long double type is supported on this target.
Definition: TargetInfo.h:711
virtual bool hasBitIntType() const
Determine whether the _BitInt type is supported on this target.
Definition: TargetInfo.h:666
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1256
virtual bool hasInt128Type() const
Determine whether the __int128 type is supported on this target.
Definition: TargetInfo.h:655
virtual bool hasFloat16Type() const
Determine whether the _Float16 type is supported on this target.
Definition: TargetInfo.h:696
llvm::StringMap< bool > & getSupportedOpenCLOpts()
Get supported OpenCL extensions and optional core features.
Definition: TargetInfo.h:1765
virtual bool hasIbm128Type() const
Determine whether the __ibm128 type is supported on this target.
Definition: TargetInfo.h:708
virtual bool hasFPReturn() const
Determine whether return of a floating point value is supported on this target.
Definition: TargetInfo.h:715
bool hasBuiltinMSVaList() const
Returns whether or not type __builtin_ms_va_list type is available on this target.
Definition: TargetInfo.h:1033
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
Definition: TargetInfo.h:693
bool hasAArch64SVETypes() const
Returns whether or not the AArch64 SVE built-in types are available on this target.
Definition: TargetInfo.h:1040
virtual bool hasBFloat16Type() const
Determine whether the _BFloat16 type is supported on this target.
Definition: TargetInfo.h:699
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
Definition: TargetInfo.h:1487
bool hasRISCVVTypes() const
Returns whether or not the RISC-V V built-in types are available on this target.
Definition: TargetInfo.h:1044
The type-property cache.
Definition: Type.cpp:4430
A container of type source information.
Definition: Type.h:7714
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1882
bool isFloat16Type() const
Definition: Type.h:8304
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:8335
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
Definition: Type.cpp:2480
bool isFloat128Type() const
Definition: Type.h:8320
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isBitIntType() const
Definition: Type.h:8230
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2672
ScalarTypeKind getScalarTypeKind() const
Given that this is a scalar type, classify it.
Definition: Type.cpp:2296
bool isIbm128Type() const
Definition: Type.h:8324
bool isBFloat16Type() const
Definition: Type.h:8316
bool isStructureOrClassType() const
Definition: Type.cpp:657
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2266
bool isRVVSizelessBuiltinType() const
Returns true for RVV scalable vector types.
Definition: Type.cpp:2494
Linkage getLinkage() const
Determine the linkage of this type.
Definition: Type.cpp:4575
@ STK_FloatingComplex
Definition: Type.h:2654
@ STK_Floating
Definition: Type.h:2652
@ STK_BlockPointer
Definition: Type.h:2647
@ STK_Bool
Definition: Type.h:2650
@ STK_ObjCObjectPointer
Definition: Type.h:2648
@ STK_FixedPoint
Definition: Type.h:2655
@ STK_IntegralComplex
Definition: Type.h:2653
@ STK_CPointer
Definition: Type.h:2646
@ STK_Integral
Definition: Type.h:2651
@ STK_MemberPointer
Definition: Type.h:2649
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8516
bool isNullPtrType() const
Definition: Type.h:8328
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
Definition: Type.cpp:4686
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3405
Simple class containing the result of Sema::CorrectTypo.
A set of unresolved declarations.
Definition: UnresolvedSet.h:62
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:92
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:35
A set of unresolved declarations.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
void setType(QualType newType)
Definition: Decl.h:679
QualType getType() const
Definition: Decl.h:678
Represents a variable declaration or definition.
Definition: Decl.h:879
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2775
void setEscapingByref()
Definition: Decl.h:1552
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2348
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition: Decl.h:1290
const Expr * getInit() const
Definition: Decl.h:1316
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
Definition: Decl.cpp:2327
@ DeclarationOnly
This declaration is only a declaration.
Definition: Decl.h:1243
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Definition: Decl.cpp:2663
Declaration of a variable template.
void IssueWarnings(Policy P, FunctionScopeInfo *fscope, const Decl *D, QualType BlockType)
Retains information about a block that is currently being parsed.
Definition: ScopeInfo.h:784
Retains information about a captured region.
Definition: ScopeInfo.h:810
Contains information about the compound statement currently being parsed.
Definition: ScopeInfo.h:67
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:104
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound statement scopes in the function.
Definition: ScopeInfo.h:228
llvm::SmallPtrSet< const BlockDecl *, 1 > Blocks
The set of blocks that are introduced in this function.
Definition: ScopeInfo.h:231
llvm::TinyPtrVector< VarDecl * > ByrefBlockVars
The set of __block variables that are introduced in this function.
Definition: ScopeInfo.h:234
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:169
Defines the clang::TargetInfo interface.
bool evaluateRequiredTargetFeatures(llvm::StringRef RequiredFatures, const llvm::StringMap< bool > &TargetFetureMap)
Returns true if the required target features of a builtin function are enabled.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:81
void threadSafetyCleanup(BeforeSet *Cache)
The JSON file list parser is used to communicate input to InstallAPI.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ CPlusPlus
Definition: LangStandard.h:56
@ CPlusPlus11
Definition: LangStandard.h:57
@ ExpectedVariableOrFunction
Definition: ParsedAttr.h:1093
@ 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.
CapturedRegionKind
The different kinds of captured statement.
Definition: CapturedStmt.h:16
@ CR_OpenMP
Definition: CapturedStmt.h:19
@ SC_Register
Definition: Specifiers.h:254
@ SC_Static
Definition: Specifiers.h:249
@ Result
The result type of a method or function.
@ Class
The "class" keyword.
ExprResult ExprError()
Definition: Ownership.h:264
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
CastKind
CastKind - The kind of operation required for a conversion.
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:1037
@ TU_ClangModule
The translation unit is a clang module.
Definition: LangOptions.h:1046
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:1043
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.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:129
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:132
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
Definition: Specifiers.h:141
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:136
const FunctionProtoType * T
bool isExternalFormalLinkage(Linkage L)
Definition: Linkage.h:117
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
@ 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.
Definition: Decl.cpp:5748
void runWithSufficientStackSpace(llvm::function_ref< void()> Diag, llvm::function_ref< void()> Fn)
Run a given function on a stack with "sufficient" space.
Definition: Stack.h:40
bool isExternallyVisible(Linkage L)
Definition: Linkage.h:90
CheckedConversionKind
The kind of conversion being performed.
Definition: Sema.h:456
unsigned long uint64_t
#define false
Definition: stdbool.h:26
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
bool shouldDiagnoseConversion(QualType SrcType, const FunctionEffectsRef &SrcFX, QualType DstType, const FunctionEffectsRef &DstFX) const
Return true if adding or removing the effect as part of a type conversion should generate a diagnosti...
Definition: Sema.cpp:2819
OverrideResult
Describes the result of effects differing between a base class's virtual method and an overriding met...
Definition: Sema.h:500
OverrideResult shouldDiagnoseMethodOverride(const CXXMethodDecl &OldMethod, const FunctionEffectsRef &OldFX, const CXXMethodDecl &NewMethod, const FunctionEffectsRef &NewFX) const
Return true if adding or removing the effect in a C++ virtual method override should generate a diagn...
Definition: Sema.cpp:2883
bool shouldDiagnoseRedeclaration(const FunctionDecl &OldFunction, const FunctionEffectsRef &OldFX, const FunctionDecl &NewFunction, const FunctionEffectsRef &NewFX) const
Return true if adding or removing the effect in a redeclaration should generate a diagnostic.
Definition: Sema.cpp:2857
FunctionEffectDifferences(const FunctionEffectsRef &Old, const FunctionEffectsRef &New)
Caller should short-circuit by checking for equality first.
Definition: Sema.cpp:2765
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition: Type.h:4791
EffectConditionExpr Cond
Definition: Type.h:4793
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
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<=>.
Definition: Sema.h:12742