clang 23.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"
41#include "clang/Sema/Scope.h"
44#include "clang/Sema/SemaARM.h"
45#include "clang/Sema/SemaAVR.h"
46#include "clang/Sema/SemaBPF.h"
47#include "clang/Sema/SemaCUDA.h"
51#include "clang/Sema/SemaHLSL.h"
54#include "clang/Sema/SemaM68k.h"
55#include "clang/Sema/SemaMIPS.h"
58#include "clang/Sema/SemaObjC.h"
62#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/SetVector.h"
77#include "llvm/ADT/SmallPtrSet.h"
78#include "llvm/Support/TimeProfiler.h"
79#include <optional>
80
81using namespace clang;
82using namespace sema;
83
87
90 bool IncludeComments,
91 std::optional<tok::TokenKind> ExpectedToken) {
92 if (!Loc.isValid())
93 return SourceRange();
94 std::optional<Token> NextToken =
95 Lexer::findNextToken(Loc, SourceMgr, LangOpts, IncludeComments);
96 if (!NextToken)
97 return SourceRange();
98 if (ExpectedToken && NextToken->getKind() != *ExpectedToken)
99 return SourceRange();
100 SourceLocation TokenStart = NextToken->getLocation();
101 SourceLocation TokenEnd = NextToken->getLastLoc();
102 if (!TokenStart.isValid() || !TokenEnd.isValid())
103 return SourceRange();
104 if (!IncludeMacros && (TokenStart.isMacroID() || TokenEnd.isMacroID()))
105 return SourceRange();
106
107 return SourceRange(TokenStart, TokenEnd);
108}
109
110ModuleLoader &Sema::getModuleLoader() const { return PP.getModuleLoader(); }
111
114 StringRef Platform) {
116 if (!SDKInfo && !WarnedDarwinSDKInfoMissing) {
117 Diag(Loc, diag::warn_missing_sdksettings_for_availability_checking)
118 << Platform;
119 WarnedDarwinSDKInfoMissing = true;
120 }
121 return SDKInfo;
122}
123
125 if (CachedDarwinSDKInfo)
126 return CachedDarwinSDKInfo->get();
127 auto SDKInfo = parseDarwinSDKInfo(
128 PP.getFileManager().getVirtualFileSystem(),
129 PP.getHeaderSearchInfo().getHeaderSearchOpts().Sysroot);
130 if (SDKInfo && *SDKInfo) {
131 CachedDarwinSDKInfo = std::make_unique<DarwinSDKInfo>(std::move(**SDKInfo));
132 return CachedDarwinSDKInfo->get();
133 }
134 if (!SDKInfo)
135 llvm::consumeError(SDKInfo.takeError());
136 CachedDarwinSDKInfo = std::unique_ptr<DarwinSDKInfo>();
137 return nullptr;
138}
139
141 const IdentifierInfo *ParamName, unsigned int Index) {
142 std::string InventedName;
143 llvm::raw_string_ostream OS(InventedName);
144
145 if (!ParamName)
146 OS << "auto:" << Index + 1;
147 else
148 OS << ParamName->getName() << ":auto";
149
150 return &Context.Idents.get(OS.str());
151}
152
154 const Preprocessor &PP) {
155 PrintingPolicy Policy = Context.getPrintingPolicy();
156 // In diagnostics, we print _Bool as bool if the latter is defined as the
157 // former.
158 Policy.Bool = Context.getLangOpts().Bool;
159 if (!Policy.Bool) {
160 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
161 Policy.Bool = BoolMacro->isObjectLike() &&
162 BoolMacro->getNumTokens() == 1 &&
163 BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
164 }
165 }
166
167 // Shorten the data output if needed
168 Policy.EntireContentsOfLargeArray = false;
169
170 return Policy;
171}
172
174 TUScope = S;
175 PushDeclContext(S, Context.getTranslationUnitDecl());
176}
177
178namespace clang {
179namespace sema {
180
182 Sema *S = nullptr;
185
186public:
187 void set(Sema &S) { this->S = &S; }
188
189 void reset() { S = nullptr; }
190
193 FileID PrevFID) override {
194 if (!S)
195 return;
196 switch (Reason) {
197 case EnterFile: {
198 SourceManager &SM = S->getSourceManager();
199 SourceLocation IncludeLoc = SM.getIncludeLoc(SM.getFileID(Loc));
200 if (IncludeLoc.isValid()) {
201 if (llvm::timeTraceProfilerEnabled()) {
202 OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc));
203 ProfilerStack.push_back(llvm::timeTraceAsyncProfilerBegin(
204 "Source", FE ? FE->getName() : StringRef("<unknown>")));
205 }
206
207 IncludeStack.push_back(IncludeLoc);
208 S->DiagnoseNonDefaultPragmaAlignPack(
210 IncludeLoc);
211 }
212 break;
213 }
214 case ExitFile:
215 if (!IncludeStack.empty()) {
216 if (llvm::timeTraceProfilerEnabled())
217 llvm::timeTraceProfilerEnd(ProfilerStack.pop_back_val());
218
219 S->DiagnoseNonDefaultPragmaAlignPack(
221 IncludeStack.pop_back_val());
222 }
223 break;
224 default:
225 break;
226 }
227 }
228 void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
229 diag::Severity Mapping, StringRef Str) override {
230 // If one of the analysis-based diagnostics was enabled while processing
231 // a function, we want to note it in the analysis-based warnings so they
232 // can be run at the end of the function body even if the analysis warnings
233 // are disabled at that point.
235 diag::Flavor Flavor =
237 StringRef Group = Str.substr(2);
238
239 if (S->PP.getDiagnostics().getDiagnosticIDs()->getDiagnosticsInGroup(
240 Flavor, Group, GroupDiags))
241 return;
242
243 for (diag::kind K : GroupDiags) {
244 // Note: the cases in this switch should be kept in sync with the
245 // diagnostics in AnalysisBasedWarnings::getPolicyInEffectAt().
247 S->AnalysisWarnings.getPolicyOverrides();
248 switch (K) {
249 default: break;
250 case diag::warn_unreachable:
251 case diag::warn_unreachable_break:
252 case diag::warn_unreachable_return:
253 case diag::warn_unreachable_loop_increment:
254 Override.enableCheckUnreachable = true;
255 break;
256 case diag::warn_double_lock:
257 Override.enableThreadSafetyAnalysis = true;
258 break;
259 case diag::warn_use_in_invalid_state:
260 Override.enableConsumedAnalysis = true;
261 break;
262 }
263 }
264 }
265};
266
267} // end namespace sema
268} // end namespace clang
269
270const unsigned Sema::MaxAlignmentExponent;
272
277 Context(ctxt), Consumer(consumer), Diags(PP.getDiagnostics()),
281 ExternalSource(nullptr), StackHandler(Diags), CurScope(nullptr),
282 Ident_super(nullptr), AMDGPUPtr(std::make_unique<SemaAMDGPU>(*this)),
283 ARMPtr(std::make_unique<SemaARM>(*this)),
284 AVRPtr(std::make_unique<SemaAVR>(*this)),
285 BPFPtr(std::make_unique<SemaBPF>(*this)),
286 CodeCompletionPtr(
287 std::make_unique<SemaCodeCompletion>(*this, CodeCompleter)),
288 CUDAPtr(std::make_unique<SemaCUDA>(*this)),
289 DirectXPtr(std::make_unique<SemaDirectX>(*this)),
290 HLSLPtr(std::make_unique<SemaHLSL>(*this)),
291 HexagonPtr(std::make_unique<SemaHexagon>(*this)),
292 LoongArchPtr(std::make_unique<SemaLoongArch>(*this)),
293 M68kPtr(std::make_unique<SemaM68k>(*this)),
294 MIPSPtr(std::make_unique<SemaMIPS>(*this)),
295 MSP430Ptr(std::make_unique<SemaMSP430>(*this)),
296 NVPTXPtr(std::make_unique<SemaNVPTX>(*this)),
297 ObjCPtr(std::make_unique<SemaObjC>(*this)),
298 OpenACCPtr(std::make_unique<SemaOpenACC>(*this)),
299 OpenCLPtr(std::make_unique<SemaOpenCL>(*this)),
300 OpenMPPtr(std::make_unique<SemaOpenMP>(*this)),
301 PPCPtr(std::make_unique<SemaPPC>(*this)),
302 PseudoObjectPtr(std::make_unique<SemaPseudoObject>(*this)),
303 RISCVPtr(std::make_unique<SemaRISCV>(*this)),
304 SPIRVPtr(std::make_unique<SemaSPIRV>(*this)),
305 SYCLPtr(std::make_unique<SemaSYCL>(*this)),
306 SwiftPtr(std::make_unique<SemaSwift>(*this)),
307 SystemZPtr(std::make_unique<SemaSystemZ>(*this)),
308 WasmPtr(std::make_unique<SemaWasm>(*this)),
309 X86Ptr(std::make_unique<SemaX86>(*this)),
311 LangOpts.getMSPointerToMemberRepresentationMethod()),
312 MSStructPragmaOn(false), VtorDispStack(LangOpts.getVtorDispMode()),
321 FullyCheckedComparisonCategories(
322 static_cast<unsigned>(ComparisonCategoryType::Last) + 1),
327 ArgPackSubstIndex(std::nullopt), SatisfactionCache(Context) {
328 assert(pp.TUKind == TUKind);
329 TUScope = nullptr;
330
331 LoadedExternalKnownNamespaces = false;
332 for (unsigned I = 0; I != NSAPI::NumNSNumberLiteralMethods; ++I)
333 ObjC().NSNumberLiteralMethods[I] = nullptr;
334
335 if (getLangOpts().ObjC)
336 ObjC().NSAPIObj.reset(new NSAPI(Context));
337
340
341 // Tell diagnostics how to render things from the AST library.
342 Diags.SetArgToStringFn(&FormatASTNodeDiagnosticArgument, &Context);
343
344 // This evaluation context exists to ensure that there's always at least one
345 // valid evaluation context available. It is never removed from the
346 // evaluation stack.
347 ExprEvalContexts.emplace_back(
350
351 // Initialization of data sharing attributes stack for OpenMP
352 OpenMP().InitDataSharingAttributesStack();
353
354 std::unique_ptr<sema::SemaPPCallbacks> Callbacks =
355 std::make_unique<sema::SemaPPCallbacks>();
356 SemaPPCallbackHandler = Callbacks.get();
357 PP.addPPCallbacks(std::move(Callbacks));
358 SemaPPCallbackHandler->set(*this);
359
360 CurFPFeatures.setFPEvalMethod(PP.getCurrentFPEvalMethod());
361}
362
363// Anchor Sema's type info to this TU.
364void Sema::anchor() {}
365
366void Sema::addImplicitTypedef(StringRef Name, QualType T) {
367 DeclarationName DN = &Context.Idents.get(Name);
368 if (IdResolver.begin(DN) == IdResolver.end())
369 PushOnScopeChains(Context.buildImplicitTypedef(T, Name), TUScope);
370}
371
373 // Create BuiltinVaListDecl *before* ExternalSemaSource::InitializeSema(this)
374 // because during initialization ASTReader can emit globals that require
375 // name mangling. And the name mangling uses BuiltinVaListDecl.
376 if (Context.getTargetInfo().hasBuiltinMSVaList())
377 (void)Context.getBuiltinMSVaListDecl();
378 (void)Context.getBuiltinVaListDecl();
379
380 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
381 SC->InitializeSema(*this);
382
383 // Tell the external Sema source about this Sema object.
384 if (ExternalSemaSource *ExternalSema
385 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
386 ExternalSema->InitializeSema(*this);
387
388 // This needs to happen after ExternalSemaSource::InitializeSema(this) or we
389 // will not be able to merge any duplicate __va_list_tag decls correctly.
390 VAListTagName = PP.getIdentifierInfo("__va_list_tag");
391
392 if (!TUScope)
393 return;
394
395 // Initialize predefined 128-bit integer types, if needed.
396 if (Context.getTargetInfo().hasInt128Type() ||
397 (Context.getAuxTargetInfo() &&
398 Context.getAuxTargetInfo()->hasInt128Type())) {
399 // If either of the 128-bit integer types are unavailable to name lookup,
400 // define them now.
401 DeclarationName Int128 = &Context.Idents.get("__int128_t");
402 if (IdResolver.begin(Int128) == IdResolver.end())
403 PushOnScopeChains(Context.getInt128Decl(), TUScope);
404
405 DeclarationName UInt128 = &Context.Idents.get("__uint128_t");
406 if (IdResolver.begin(UInt128) == IdResolver.end())
407 PushOnScopeChains(Context.getUInt128Decl(), TUScope);
408 }
409
410
411 // Initialize predefined Objective-C types:
412 if (getLangOpts().ObjC) {
413 // If 'SEL' does not yet refer to any declarations, make it refer to the
414 // predefined 'SEL'.
415 DeclarationName SEL = &Context.Idents.get("SEL");
416 if (IdResolver.begin(SEL) == IdResolver.end())
417 PushOnScopeChains(Context.getObjCSelDecl(), TUScope);
418
419 // If 'id' does not yet refer to any declarations, make it refer to the
420 // predefined 'id'.
421 DeclarationName Id = &Context.Idents.get("id");
422 if (IdResolver.begin(Id) == IdResolver.end())
423 PushOnScopeChains(Context.getObjCIdDecl(), TUScope);
424
425 // Create the built-in typedef for 'Class'.
426 DeclarationName Class = &Context.Idents.get("Class");
427 if (IdResolver.begin(Class) == IdResolver.end())
428 PushOnScopeChains(Context.getObjCClassDecl(), TUScope);
429
430 // Create the built-in forward declaratino for 'Protocol'.
431 DeclarationName Protocol = &Context.Idents.get("Protocol");
432 if (IdResolver.begin(Protocol) == IdResolver.end())
433 PushOnScopeChains(Context.getObjCProtocolDecl(), TUScope);
434 }
435
436 // Create the internal type for the *StringMakeConstantString builtins.
437 DeclarationName ConstantString = &Context.Idents.get("__NSConstantString");
438 if (IdResolver.begin(ConstantString) == IdResolver.end())
439 PushOnScopeChains(Context.getCFConstantStringDecl(), TUScope);
440
441 // Initialize Microsoft "predefined C++ types".
442 if (getLangOpts().MSVCCompat) {
443 if (getLangOpts().CPlusPlus &&
444 IdResolver.begin(&Context.Idents.get("type_info")) == IdResolver.end())
445 PushOnScopeChains(Context.getMSTypeInfoTagDecl(), TUScope);
446
447 addImplicitTypedef("size_t", Context.getSizeType());
448 }
449
450 // Initialize predefined OpenCL types and supported extensions and (optional)
451 // core features.
452 if (getLangOpts().OpenCL) {
454 Context.getTargetInfo().getSupportedOpenCLOpts(), getLangOpts());
455 addImplicitTypedef("sampler_t", Context.OCLSamplerTy);
456 addImplicitTypedef("event_t", Context.OCLEventTy);
457 auto OCLCompatibleVersion = getLangOpts().getOpenCLCompatibleVersion();
458 if (OCLCompatibleVersion >= 200) {
459 if (getLangOpts().OpenCLCPlusPlus || getLangOpts().Blocks) {
460 addImplicitTypedef("clk_event_t", Context.OCLClkEventTy);
461 addImplicitTypedef("queue_t", Context.OCLQueueTy);
462 }
463 if (getLangOpts().OpenCLPipes)
464 addImplicitTypedef("reserve_id_t", Context.OCLReserveIDTy);
465 addImplicitTypedef("atomic_int", Context.getAtomicType(Context.IntTy));
466 addImplicitTypedef("atomic_uint",
467 Context.getAtomicType(Context.UnsignedIntTy));
468 addImplicitTypedef("atomic_float",
469 Context.getAtomicType(Context.FloatTy));
470 // OpenCLC v2.0, s6.13.11.6 requires that atomic_flag is implemented as
471 // 32-bit integer and OpenCLC v2.0, s6.1.1 int is always 32-bit wide.
472 addImplicitTypedef("atomic_flag", Context.getAtomicType(Context.IntTy));
473
474
475 // OpenCL v2.0 s6.13.11.6:
476 // - The atomic_long and atomic_ulong types are supported if the
477 // cl_khr_int64_base_atomics and cl_khr_int64_extended_atomics
478 // extensions are supported.
479 // - The atomic_double type is only supported if double precision
480 // is supported and the cl_khr_int64_base_atomics and
481 // cl_khr_int64_extended_atomics extensions are supported.
482 // - If the device address space is 64-bits, the data types
483 // atomic_intptr_t, atomic_uintptr_t, atomic_size_t and
484 // atomic_ptrdiff_t are supported if the cl_khr_int64_base_atomics and
485 // cl_khr_int64_extended_atomics extensions are supported.
486
487 auto AddPointerSizeDependentTypes = [&]() {
488 auto AtomicSizeT = Context.getAtomicType(Context.getSizeType());
489 auto AtomicIntPtrT = Context.getAtomicType(Context.getIntPtrType());
490 auto AtomicUIntPtrT = Context.getAtomicType(Context.getUIntPtrType());
491 auto AtomicPtrDiffT =
492 Context.getAtomicType(Context.getPointerDiffType());
493 addImplicitTypedef("atomic_size_t", AtomicSizeT);
494 addImplicitTypedef("atomic_intptr_t", AtomicIntPtrT);
495 addImplicitTypedef("atomic_uintptr_t", AtomicUIntPtrT);
496 addImplicitTypedef("atomic_ptrdiff_t", AtomicPtrDiffT);
497 };
498
499 if (Context.getTypeSize(Context.getSizeType()) == 32) {
500 AddPointerSizeDependentTypes();
501 }
502
503 if (getOpenCLOptions().isSupported("cl_khr_fp16", getLangOpts())) {
504 auto AtomicHalfT = Context.getAtomicType(Context.HalfTy);
505 addImplicitTypedef("atomic_half", AtomicHalfT);
506 }
507
508 std::vector<QualType> Atomic64BitTypes;
509 if (getOpenCLOptions().isSupported("cl_khr_int64_base_atomics",
510 getLangOpts()) &&
511 getOpenCLOptions().isSupported("cl_khr_int64_extended_atomics",
512 getLangOpts())) {
513 if (getOpenCLOptions().isSupported("cl_khr_fp64", getLangOpts())) {
514 auto AtomicDoubleT = Context.getAtomicType(Context.DoubleTy);
515 addImplicitTypedef("atomic_double", AtomicDoubleT);
516 Atomic64BitTypes.push_back(AtomicDoubleT);
517 }
518 auto AtomicLongT = Context.getAtomicType(Context.LongTy);
519 auto AtomicULongT = Context.getAtomicType(Context.UnsignedLongTy);
520 addImplicitTypedef("atomic_long", AtomicLongT);
521 addImplicitTypedef("atomic_ulong", AtomicULongT);
522
523
524 if (Context.getTypeSize(Context.getSizeType()) == 64) {
525 AddPointerSizeDependentTypes();
526 }
527 }
528 }
529
530#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
531 if (getOpenCLOptions().isSupported(#Ext, getLangOpts())) { \
532 addImplicitTypedef(#ExtType, Context.Id##Ty); \
533 }
534#include "clang/Basic/OpenCLExtensionTypes.def"
535 }
536
537 if (Context.getTargetInfo().hasAArch64ACLETypes() ||
538 (Context.getAuxTargetInfo() &&
539 Context.getAuxTargetInfo()->hasAArch64ACLETypes())) {
540#define SVE_TYPE(Name, Id, SingletonId) \
541 addImplicitTypedef(#Name, Context.SingletonId);
542#define NEON_VECTOR_TYPE(Name, BaseType, ElBits, NumEls, VectorKind) \
543 addImplicitTypedef( \
544 #Name, Context.getVectorType(Context.BaseType, NumEls, VectorKind));
545#include "clang/Basic/AArch64ACLETypes.def"
546 }
547
548 if (Context.getTargetInfo().getTriple().isPPC64()) {
549#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
550 addImplicitTypedef(#Name, Context.Id##Ty);
551#include "clang/Basic/PPCTypes.def"
552#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
553 addImplicitTypedef(#Name, Context.Id##Ty);
554#include "clang/Basic/PPCTypes.def"
555 }
556
557 if (Context.getTargetInfo().hasRISCVVTypes()) {
558#define RVV_TYPE(Name, Id, SingletonId) \
559 addImplicitTypedef(Name, Context.SingletonId);
560#include "clang/Basic/RISCVVTypes.def"
561 }
562
563 if (Context.getTargetInfo().getTriple().isWasm() &&
564 Context.getTargetInfo().hasFeature("reference-types")) {
565#define WASM_TYPE(Name, Id, SingletonId) \
566 addImplicitTypedef(Name, Context.SingletonId);
567#include "clang/Basic/WebAssemblyReferenceTypes.def"
568 }
569
570 if (Context.getTargetInfo().getTriple().isAMDGPU() ||
571 (Context.getTargetInfo().getTriple().isSPIRV() &&
572 Context.getTargetInfo().getTriple().getVendor() == llvm::Triple::AMD) ||
573 (Context.getAuxTargetInfo() &&
574 (Context.getAuxTargetInfo()->getTriple().isAMDGPU() ||
575 (Context.getAuxTargetInfo()->getTriple().isSPIRV() &&
576 Context.getAuxTargetInfo()->getTriple().getVendor() ==
577 llvm::Triple::AMD)))) {
578#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
579 addImplicitTypedef(Name, Context.SingletonId);
580#include "clang/Basic/AMDGPUTypes.def"
581 }
582
583 if (Context.getTargetInfo().hasBuiltinMSVaList()) {
584 DeclarationName MSVaList = &Context.Idents.get("__builtin_ms_va_list");
585 if (IdResolver.begin(MSVaList) == IdResolver.end())
586 PushOnScopeChains(Context.getBuiltinMSVaListDecl(), TUScope);
587 }
588
589 DeclarationName BuiltinVaList = &Context.Idents.get("__builtin_va_list");
590 if (IdResolver.begin(BuiltinVaList) == IdResolver.end())
591 PushOnScopeChains(Context.getBuiltinVaListDecl(), TUScope);
592}
593
595 assert(InstantiatingSpecializations.empty() &&
596 "failed to clean up an InstantiatingTemplate?");
597
599
600 // Kill all the active scopes.
602 delete FSI;
603
604 // Tell the SemaConsumer to forget about us; we're going out of scope.
605 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer))
606 SC->ForgetSema();
607
608 // Detach from the external Sema source.
609 if (ExternalSemaSource *ExternalSema
610 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
611 ExternalSema->ForgetSema();
612
613 // Delete cached satisfactions.
614 std::vector<ConstraintSatisfaction *> Satisfactions;
615 Satisfactions.reserve(SatisfactionCache.size());
616 for (auto &Node : SatisfactionCache)
617 Satisfactions.push_back(&Node);
618 for (auto *Node : Satisfactions)
619 delete Node;
620
622
623 // Destroys data sharing attributes stack for OpenMP
624 OpenMP().DestroyDataSharingAttributesStack();
625
626 // Detach from the PP callback handler which outlives Sema since it's owned
627 // by the preprocessor.
628 SemaPPCallbackHandler->reset();
629}
630
632 llvm::function_ref<void()> Fn) {
633 StackHandler.runWithSufficientStackSpace(Loc, Fn);
634}
635
637 UnavailableAttr::ImplicitReason reason) {
638 // If we're not in a function, it's an error.
639 FunctionDecl *fn = dyn_cast<FunctionDecl>(CurContext);
640 if (!fn) return false;
641
642 // If we're in template instantiation, it's an error.
644 return false;
645
646 // If that function's not in a system header, it's an error.
647 if (!Context.getSourceManager().isInSystemHeader(loc))
648 return false;
649
650 // If the function is already unavailable, it's not an error.
651 if (fn->hasAttr<UnavailableAttr>()) return true;
652
653 fn->addAttr(UnavailableAttr::CreateImplicit(Context, "", reason, loc));
654 return true;
655}
656
660
662 assert(E && "Cannot use with NULL ptr");
663
664 if (!ExternalSource) {
665 ExternalSource = std::move(E);
666 return;
667 }
668
669 if (auto *Ex = dyn_cast<MultiplexExternalSemaSource>(ExternalSource.get()))
670 Ex->AddSource(std::move(E));
671 else
672 ExternalSource = llvm::makeIntrusiveRefCnt<MultiplexExternalSemaSource>(
673 ExternalSource, std::move(E));
674}
675
676void Sema::PrintStats() const {
677 llvm::errs() << "\n*** Semantic Analysis Stats:\n";
678 if (SFINAETrap *Trap = getSFINAEContext())
679 llvm::errs() << int(Trap->hasErrorOccurred())
680 << " SFINAE diagnostics trapped.\n";
681
682 BumpAlloc.PrintStats();
683 AnalysisWarnings.PrintStats();
684}
685
687 QualType SrcType,
688 SourceLocation Loc) {
689 std::optional<NullabilityKind> ExprNullability = SrcType->getNullability();
690 if (!ExprNullability || (*ExprNullability != NullabilityKind::Nullable &&
691 *ExprNullability != NullabilityKind::NullableResult))
692 return;
693
694 std::optional<NullabilityKind> TypeNullability = DstType->getNullability();
695 if (!TypeNullability || *TypeNullability != NullabilityKind::NonNull)
696 return;
697
698 Diag(Loc, diag::warn_nullability_lost) << SrcType << DstType;
699}
700
701// Generate diagnostics when adding or removing effects in a type conversion.
703 SourceLocation Loc) {
704 const auto SrcFX = FunctionEffectsRef::get(SrcType);
705 const auto DstFX = FunctionEffectsRef::get(DstType);
706 if (SrcFX != DstFX) {
707 for (const auto &Diff : FunctionEffectDiffVector(SrcFX, DstFX)) {
708 if (Diff.shouldDiagnoseConversion(SrcType, SrcFX, DstType, DstFX))
709 Diag(Loc, diag::warn_invalid_add_func_effects) << Diff.effectName();
710 }
711 }
712}
713
715 // nullptr only exists from C++11 on, so don't warn on its absence earlier.
717 return;
718
719 if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
720 return;
721
722 const Expr *EStripped = E->IgnoreParenImpCasts();
723 if (EStripped->getType()->isNullPtrType())
724 return;
725 if (isa<GNUNullExpr>(EStripped))
726 return;
727
728 if (Diags.isIgnored(diag::warn_zero_as_null_pointer_constant,
729 E->getBeginLoc()))
730 return;
731
732 // Don't diagnose the conversion from a 0 literal to a null pointer argument
733 // in a synthesized call to operator<=>.
734 if (!CodeSynthesisContexts.empty() &&
735 CodeSynthesisContexts.back().Kind ==
737 return;
738
739 // Ignore null pointers in defaulted comparison operators.
741 if (FD && FD->isDefaulted()) {
742 return;
743 }
744
745 // If it is a macro from system header, and if the macro name is not "NULL",
746 // do not warn.
747 // Note that uses of "NULL" will be ignored above on systems that define it
748 // as __null.
749 SourceLocation MaybeMacroLoc = E->getBeginLoc();
750 if (Diags.getSuppressSystemWarnings() &&
751 SourceMgr.isInSystemMacro(MaybeMacroLoc) &&
752 !findMacroSpelling(MaybeMacroLoc, "NULL"))
753 return;
754
755 Diag(E->getBeginLoc(), diag::warn_zero_as_null_pointer_constant)
757}
758
759/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
760/// If there is already an implicit cast, merge into the existing one.
761/// The result is of the given category.
764 const CXXCastPath *BasePath,
766#ifndef NDEBUG
767 if (VK == VK_PRValue && !E->isPRValue()) {
768 switch (Kind) {
769 default:
770 llvm_unreachable(
771 ("can't implicitly cast glvalue to prvalue with this cast "
772 "kind: " +
773 std::string(CastExpr::getCastKindName(Kind)))
774 .c_str());
775 case CK_Dependent:
776 case CK_LValueToRValue:
777 case CK_ArrayToPointerDecay:
778 case CK_FunctionToPointerDecay:
779 case CK_ToVoid:
780 case CK_NonAtomicToAtomic:
781 case CK_HLSLArrayRValue:
782 case CK_HLSLAggregateSplatCast:
783 break;
784 }
785 }
786 assert((VK == VK_PRValue || Kind == CK_Dependent || !E->isPRValue()) &&
787 "can't cast prvalue to glvalue");
788#endif
789
792 if (Context.hasAnyFunctionEffects() && !isCast(CCK) &&
793 Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
795
796 QualType ExprTy = Context.getCanonicalType(E->getType());
797 QualType TypeTy = Context.getCanonicalType(Ty);
798
799 // This cast is used in place of a regular LValue to RValue cast for
800 // HLSL Array Parameter Types. It needs to be emitted even if
801 // ExprTy == TypeTy, except if E is an HLSLOutArgExpr
802 // Emitting a cast in that case will prevent HLSLOutArgExpr from
803 // being handled properly in EmitCallArg
804 if (Kind == CK_HLSLArrayRValue && !isa<HLSLOutArgExpr>(E))
805 return ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK,
807
808 if (ExprTy == TypeTy)
809 return E;
810
811 if (Kind == CK_ArrayToPointerDecay) {
812 // C++1z [conv.array]: The temporary materialization conversion is applied.
813 // We also use this to fuel C++ DR1213, which applies to C++11 onwards.
814 if (getLangOpts().CPlusPlus && E->isPRValue()) {
815 // The temporary is an lvalue in C++98 and an xvalue otherwise.
817 E->getType(), E, !getLangOpts().CPlusPlus11);
818 if (Materialized.isInvalid())
819 return ExprError();
820 E = Materialized.get();
821 }
822 // C17 6.7.1p6 footnote 124: The implementation can treat any register
823 // declaration simply as an auto declaration. However, whether or not
824 // addressable storage is actually used, the address of any part of an
825 // object declared with storage-class specifier register cannot be
826 // computed, either explicitly(by use of the unary & operator as discussed
827 // in 6.5.3.2) or implicitly(by converting an array name to a pointer as
828 // discussed in 6.3.2.1).Thus, the only operator that can be applied to an
829 // array declared with storage-class specifier register is sizeof.
830 if (VK == VK_PRValue && !getLangOpts().CPlusPlus && !E->isPRValue()) {
831 if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
832 if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
833 if (VD->getStorageClass() == SC_Register) {
834 Diag(E->getExprLoc(), diag::err_typecheck_address_of)
835 << /*register variable*/ 3 << E->getSourceRange();
836 return ExprError();
837 }
838 }
839 }
840 }
841 }
842
843 if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
844 if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) {
845 ImpCast->setType(Ty);
846 ImpCast->setValueKind(VK);
847 return E;
848 }
849 }
850
851 bool IsExplicitCast = isa<CStyleCastExpr>(E) || isa<CXXStaticCastExpr>(E) ||
853
854 if ((Kind == CK_IntegralCast || Kind == CK_IntegralToBoolean ||
855 (Kind == CK_NoOp && E->getType()->isIntegerType() &&
856 Ty->isIntegerType())) &&
857 IsExplicitCast) {
858 if (const auto *SourceOBT = E->getType()->getAs<OverflowBehaviorType>()) {
859 if (Ty->isIntegerType() && !Ty->isOverflowBehaviorType()) {
860 Ty = Context.getOverflowBehaviorType(SourceOBT->getBehaviorKind(), Ty);
861 }
862 }
863 }
864
865 return ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK,
867}
868
870 switch (ScalarTy->getScalarTypeKind()) {
871 case Type::STK_Bool: return CK_NoOp;
872 case Type::STK_CPointer: return CK_PointerToBoolean;
873 case Type::STK_BlockPointer: return CK_PointerToBoolean;
874 case Type::STK_ObjCObjectPointer: return CK_PointerToBoolean;
875 case Type::STK_MemberPointer: return CK_MemberPointerToBoolean;
876 case Type::STK_Integral: return CK_IntegralToBoolean;
877 case Type::STK_Floating: return CK_FloatingToBoolean;
878 case Type::STK_IntegralComplex: return CK_IntegralComplexToBoolean;
879 case Type::STK_FloatingComplex: return CK_FloatingComplexToBoolean;
880 case Type::STK_FixedPoint: return CK_FixedPointToBoolean;
881 }
882 llvm_unreachable("unknown scalar type kind");
883}
884
885/// Used to prune the decls of Sema's UnusedFileScopedDecls vector.
886static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) {
887 if (D->getMostRecentDecl()->isUsed())
888 return true;
889
890 if (D->isExternallyVisible())
891 return true;
892
893 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
894 // If this is a function template and none of its specializations is used,
895 // we should warn.
896 if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate())
897 for (const auto *Spec : Template->specializations())
898 if (ShouldRemoveFromUnused(SemaRef, Spec))
899 return true;
900
901 // UnusedFileScopedDecls stores the first declaration.
902 // The declaration may have become definition so check again.
903 const FunctionDecl *DeclToCheck;
904 if (FD->hasBody(DeclToCheck))
905 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
906
907 // Later redecls may add new information resulting in not having to warn,
908 // so check again.
909 DeclToCheck = FD->getMostRecentDecl();
910 if (DeclToCheck != FD)
911 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
912 }
913
914 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
915 // If a variable usable in constant expressions is referenced,
916 // don't warn if it isn't used: if the value of a variable is required
917 // for the computation of a constant expression, it doesn't make sense to
918 // warn even if the variable isn't odr-used. (isReferenced doesn't
919 // precisely reflect that, but it's a decent approximation.)
920 if (VD->isReferenced() &&
921 VD->mightBeUsableInConstantExpressions(SemaRef->Context))
922 return true;
923
924 if (VarTemplateDecl *Template = VD->getDescribedVarTemplate())
925 // If this is a variable template and none of its specializations is used,
926 // we should warn.
927 for (const auto *Spec : Template->specializations())
928 if (ShouldRemoveFromUnused(SemaRef, Spec))
929 return true;
930
931 // UnusedFileScopedDecls stores the first declaration.
932 // The declaration may have become definition so check again.
933 const VarDecl *DeclToCheck = VD->getDefinition();
934 if (DeclToCheck)
935 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
936
937 // Later redecls may add new information resulting in not having to warn,
938 // so check again.
939 DeclToCheck = VD->getMostRecentDecl();
940 if (DeclToCheck != VD)
941 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck);
942 }
943
944 return false;
945}
946
947static bool isFunctionOrVarDeclExternC(const NamedDecl *ND) {
948 if (const auto *FD = dyn_cast<FunctionDecl>(ND))
949 return FD->isExternC();
950 return cast<VarDecl>(ND)->isExternC();
951}
952
953/// Determine whether ND is an external-linkage function or variable whose
954/// type has no linkage.
956 // Note: it's not quite enough to check whether VD has UniqueExternalLinkage,
957 // because we also want to catch the case where its type has VisibleNoLinkage,
958 // which does not affect the linkage of VD.
959 return getLangOpts().CPlusPlus && VD->hasExternalFormalLinkage() &&
962}
963
965 if (TUKind != TU_Complete || getLangOpts().IsHeaderFile)
966 return false;
967 return SourceMgr.isInMainFile(Loc);
968}
969
970/// Obtains a sorted list of functions and variables that are undefined but
971/// ODR-used.
973 SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined) {
974 for (const auto &UndefinedUse : UndefinedButUsed) {
975 NamedDecl *ND = UndefinedUse.first;
976
977 // Ignore attributes that have become invalid.
978 if (ND->isInvalidDecl()) continue;
979
980 // __attribute__((weakref)) is basically a definition.
981 if (ND->hasAttr<WeakRefAttr>()) continue;
982
984 continue;
985
986 if (ND->hasAttr<DLLImportAttr>() || ND->hasAttr<DLLExportAttr>()) {
987 // An exported function will always be emitted when defined, so even if
988 // the function is inline, it doesn't have to be emitted in this TU. An
989 // imported function implies that it has been exported somewhere else.
990 continue;
991 }
992
993 if (const auto *FD = dyn_cast<FunctionDecl>(ND)) {
994 if (FD->isDefined())
995 continue;
996 if (FD->isExternallyVisible() &&
998 !FD->getMostRecentDecl()->isInlined() &&
999 !FD->hasAttr<ExcludeFromExplicitInstantiationAttr>())
1000 continue;
1001 if (FD->getBuiltinID())
1002 continue;
1003 } else {
1004 const auto *VD = cast<VarDecl>(ND);
1005 if (VD->hasDefinition() != VarDecl::DeclarationOnly)
1006 continue;
1007 if (VD->isExternallyVisible() &&
1009 !VD->getMostRecentDecl()->isInline() &&
1010 !VD->hasAttr<ExcludeFromExplicitInstantiationAttr>())
1011 continue;
1012
1013 // Skip VarDecls that lack formal definitions but which we know are in
1014 // fact defined somewhere.
1015 if (VD->isKnownToBeDefined())
1016 continue;
1017 }
1018
1019 Undefined.push_back(std::make_pair(ND, UndefinedUse.second));
1020 }
1021}
1022
1023/// checkUndefinedButUsed - Check for undefined objects with internal linkage
1024/// or that are inline.
1026 if (S.UndefinedButUsed.empty()) return;
1027
1028 // Collect all the still-undefined entities with internal linkage.
1031 S.UndefinedButUsed.clear();
1032 if (Undefined.empty()) return;
1033
1034 for (const auto &Undef : Undefined) {
1035 ValueDecl *VD = cast<ValueDecl>(Undef.first);
1036 SourceLocation UseLoc = Undef.second;
1037
1038 if (S.isExternalWithNoLinkageType(VD)) {
1039 // C++ [basic.link]p8:
1040 // A type without linkage shall not be used as the type of a variable
1041 // or function with external linkage unless
1042 // -- the entity has C language linkage
1043 // -- the entity is not odr-used or is defined in the same TU
1044 //
1045 // As an extension, accept this in cases where the type is externally
1046 // visible, since the function or variable actually can be defined in
1047 // another translation unit in that case.
1049 ? diag::ext_undefined_internal_type
1050 : diag::err_undefined_internal_type)
1051 << isa<VarDecl>(VD) << VD;
1052 } else if (!VD->isExternallyVisible()) {
1053 // FIXME: We can promote this to an error. The function or variable can't
1054 // be defined anywhere else, so the program must necessarily violate the
1055 // one definition rule.
1056 bool IsImplicitBase = false;
1057 if (const auto *BaseD = dyn_cast<FunctionDecl>(VD)) {
1058 auto *DVAttr = BaseD->getAttr<OMPDeclareVariantAttr>();
1059 if (DVAttr && !DVAttr->getTraitInfo().isExtensionActive(
1060 llvm::omp::TraitProperty::
1061 implementation_extension_disable_implicit_base)) {
1062 const auto *Func = cast<FunctionDecl>(
1063 cast<DeclRefExpr>(DVAttr->getVariantFuncRef())->getDecl());
1064 IsImplicitBase = BaseD->isImplicit() &&
1065 Func->getIdentifier()->isMangledOpenMPVariantName();
1066 }
1067 }
1068 if (!S.getLangOpts().OpenMP || !IsImplicitBase)
1069 S.Diag(VD->getLocation(), diag::warn_undefined_internal)
1070 << isa<VarDecl>(VD) << VD;
1071 } else if (auto *FD = dyn_cast<FunctionDecl>(VD)) {
1072 (void)FD;
1073 assert(FD->getMostRecentDecl()->isInlined() &&
1074 "used object requires definition but isn't inline or internal?");
1075 // FIXME: This is ill-formed; we should reject.
1076 S.Diag(VD->getLocation(), diag::warn_undefined_inline) << VD;
1077 } else {
1078 assert(cast<VarDecl>(VD)->getMostRecentDecl()->isInline() &&
1079 "used var requires definition but isn't inline or internal?");
1080 S.Diag(VD->getLocation(), diag::err_undefined_inline_var) << VD;
1081 }
1082 if (UseLoc.isValid())
1083 S.Diag(UseLoc, diag::note_used_here);
1084 }
1085}
1086
1088 if (!ExternalSource)
1089 return;
1090
1092 ExternalSource->ReadWeakUndeclaredIdentifiers(WeakIDs);
1093 for (auto &WeakID : WeakIDs)
1094 (void)WeakUndeclaredIdentifiers[WeakID.first].insert(WeakID.second);
1095}
1096
1098 if (!ExternalSource)
1099 return;
1100
1102 ExternalSource->ReadExtnameUndeclaredIdentifiers(ExtnameIDs);
1103 for (auto &ExtnameID : ExtnameIDs)
1104 ExtnameUndeclaredIdentifiers[ExtnameID.first] = ExtnameID.second;
1105}
1106
1107typedef llvm::DenseMap<const CXXRecordDecl*, bool> RecordCompleteMap;
1108
1109/// Returns true, if all methods and nested classes of the given
1110/// CXXRecordDecl are defined in this translation unit.
1111///
1112/// Should only be called from ActOnEndOfTranslationUnit so that all
1113/// definitions are actually read.
1115 RecordCompleteMap &MNCComplete) {
1116 RecordCompleteMap::iterator Cache = MNCComplete.find(RD);
1117 if (Cache != MNCComplete.end())
1118 return Cache->second;
1119 if (!RD->isCompleteDefinition())
1120 return false;
1121 bool Complete = true;
1123 E = RD->decls_end();
1124 I != E && Complete; ++I) {
1125 if (const CXXMethodDecl *M = dyn_cast<CXXMethodDecl>(*I))
1126 Complete = M->isDefined() || M->isDefaulted() ||
1127 (M->isPureVirtual() && !isa<CXXDestructorDecl>(M));
1128 else if (const FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(*I))
1129 // If the template function is marked as late template parsed at this
1130 // point, it has not been instantiated and therefore we have not
1131 // performed semantic analysis on it yet, so we cannot know if the type
1132 // can be considered complete.
1133 Complete = !F->getTemplatedDecl()->isLateTemplateParsed() &&
1134 F->getTemplatedDecl()->isDefined();
1135 else if (const CXXRecordDecl *R = dyn_cast<CXXRecordDecl>(*I)) {
1136 if (R->isInjectedClassName())
1137 continue;
1138 if (R->hasDefinition())
1139 Complete = MethodsAndNestedClassesComplete(R->getDefinition(),
1140 MNCComplete);
1141 else
1142 Complete = false;
1143 }
1144 }
1145 MNCComplete[RD] = Complete;
1146 return Complete;
1147}
1148
1149/// Returns true, if the given CXXRecordDecl is fully defined in this
1150/// translation unit, i.e. all methods are defined or pure virtual and all
1151/// friends, friend functions and nested classes are fully defined in this
1152/// translation unit.
1153///
1154/// Should only be called from ActOnEndOfTranslationUnit so that all
1155/// definitions are actually read.
1157 RecordCompleteMap &RecordsComplete,
1158 RecordCompleteMap &MNCComplete) {
1159 RecordCompleteMap::iterator Cache = RecordsComplete.find(RD);
1160 if (Cache != RecordsComplete.end())
1161 return Cache->second;
1162 bool Complete = MethodsAndNestedClassesComplete(RD, MNCComplete);
1164 E = RD->friend_end();
1165 I != E && Complete; ++I) {
1166 // Check if friend classes and methods are complete.
1167 if (TypeSourceInfo *TSI = (*I)->getFriendType()) {
1168 // Friend classes are available as the TypeSourceInfo of the FriendDecl.
1169 if (CXXRecordDecl *FriendD = TSI->getType()->getAsCXXRecordDecl())
1170 Complete = MethodsAndNestedClassesComplete(FriendD, MNCComplete);
1171 else
1172 Complete = false;
1173 } else {
1174 // Friend functions are available through the NamedDecl of FriendDecl.
1175 if (const FunctionDecl *FD =
1176 dyn_cast<FunctionDecl>((*I)->getFriendDecl()))
1177 Complete = FD->isDefined();
1178 else
1179 // This is a template friend, give up.
1180 Complete = false;
1181 }
1182 }
1183 RecordsComplete[RD] = Complete;
1184 return Complete;
1185}
1186
1188 if (ExternalSource)
1189 ExternalSource->ReadUnusedLocalTypedefNameCandidates(
1192 if (TD->isReferenced())
1193 continue;
1194 Diag(TD->getLocation(), diag::warn_unused_local_typedef)
1195 << isa<TypeAliasDecl>(TD) << TD->getDeclName();
1196 }
1198}
1199
1201 if (getLangOpts().CPlusPlusModules &&
1202 getLangOpts().getCompilingModule() == LangOptions::CMK_HeaderUnit)
1203 HandleStartOfHeaderUnit();
1204}
1205
1207 if (Kind == TUFragmentKind::Global) {
1208 // Perform Pending Instantiations at the end of global module fragment so
1209 // that the module ownership of TU-level decls won't get messed.
1210 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
1212 return;
1213 }
1214
1215 // Transfer late parsed template instantiations over to the pending template
1216 // instantiation list. During normal compilation, the late template parser
1217 // will be installed and instantiating these templates will succeed.
1218 //
1219 // If we are building a TU prefix for serialization, it is also safe to
1220 // transfer these over, even though they are not parsed. The end of the TU
1221 // should be outside of any eager template instantiation scope, so when this
1222 // AST is deserialized, these templates will not be parsed until the end of
1223 // the combined TU.
1228
1229 // If DefinedUsedVTables ends up marking any virtual member functions it
1230 // might lead to more pending template instantiations, which we then need
1231 // to instantiate.
1233
1234 // C++: Perform implicit template instantiations.
1235 //
1236 // FIXME: When we perform these implicit instantiations, we do not
1237 // carefully keep track of the point of instantiation (C++ [temp.point]).
1238 // This means that name lookup that occurs within the template
1239 // instantiation will always happen at the end of the translation unit,
1240 // so it will find some names that are not required to be found. This is
1241 // valid, but we could do better by diagnosing if an instantiation uses a
1242 // name that was not visible at its first point of instantiation.
1243 if (ExternalSource) {
1244 // Load pending instantiations from the external source.
1246 ExternalSource->ReadPendingInstantiations(Pending);
1247 for (auto PII : Pending)
1248 if (auto Func = dyn_cast<FunctionDecl>(PII.first))
1249 Func->setInstantiationIsPending(true);
1251 Pending.begin(), Pending.end());
1252 }
1253
1254 {
1255 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
1257 }
1258
1260
1261 assert(LateParsedInstantiations.empty() &&
1262 "end of TU template instantiation should not create more "
1263 "late-parsed templates");
1264}
1265
1267 assert(DelayedDiagnostics.getCurrentPool() == nullptr
1268 && "reached end of translation unit with a pool attached?");
1269
1270 // If code completion is enabled, don't perform any end-of-translation-unit
1271 // work.
1272 if (PP.isCodeCompletionEnabled())
1273 return;
1274
1275 // Complete translation units and modules define vtables and perform implicit
1276 // instantiations. PCH files do not.
1277 if (TUKind != TU_Prefix) {
1279
1281 !ModuleScopes.empty() && ModuleScopes.back().Module->Kind ==
1285
1287 } else {
1288 // If we are building a TU prefix for serialization, it is safe to transfer
1289 // these over, even though they are not parsed. The end of the TU should be
1290 // outside of any eager template instantiation scope, so when this AST is
1291 // deserialized, these templates will not be parsed until the end of the
1292 // combined TU.
1297
1298 if (LangOpts.PCHInstantiateTemplates) {
1299 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
1301 }
1302 }
1303
1308
1309 // All delayed member exception specs should be checked or we end up accepting
1310 // incompatible declarations.
1313
1314 // All dllexport classes should have been processed already.
1315 assert(DelayedDllExportClasses.empty());
1316 assert(DelayedDllExportMemberFunctions.empty());
1317
1318 // Remove file scoped decls that turned out to be used.
1320 std::remove_if(UnusedFileScopedDecls.begin(nullptr, true),
1322 [this](const DeclaratorDecl *DD) {
1323 return ShouldRemoveFromUnused(this, DD);
1324 }),
1325 UnusedFileScopedDecls.end());
1326
1327 if (TUKind == TU_Prefix) {
1328 // Translation unit prefixes don't need any of the checking below.
1329 if (!PP.isIncrementalProcessingEnabled())
1330 TUScope = nullptr;
1331 return;
1332 }
1333
1334 // Check for #pragma weak identifiers that were never declared
1336 for (const auto &WeakIDs : WeakUndeclaredIdentifiers) {
1337 if (WeakIDs.second.empty())
1338 continue;
1339
1340 Decl *PrevDecl = LookupSingleName(TUScope, WeakIDs.first, SourceLocation(),
1342 if (PrevDecl != nullptr &&
1343 !(isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl)))
1344 for (const auto &WI : WeakIDs.second)
1345 Diag(WI.getLocation(), diag::warn_attribute_wrong_decl_type)
1346 << "'weak'" << /*isRegularKeyword=*/0 << ExpectedVariableOrFunction;
1347 else
1348 for (const auto &WI : WeakIDs.second)
1349 Diag(WI.getLocation(), diag::warn_weak_identifier_undeclared)
1350 << WeakIDs.first;
1351 }
1352
1353 if (LangOpts.CPlusPlus11 &&
1354 !Diags.isIgnored(diag::warn_delegating_ctor_cycle, SourceLocation()))
1356
1357 if (!Diags.hasErrorOccurred()) {
1358 if (ExternalSource)
1359 ExternalSource->ReadUndefinedButUsed(UndefinedButUsed);
1360 checkUndefinedButUsed(*this);
1361 }
1362
1363 // A global-module-fragment is only permitted within a module unit.
1364 if (!ModuleScopes.empty() && ModuleScopes.back().Module->Kind ==
1366 Diag(ModuleScopes.back().BeginLoc,
1367 diag::err_module_declaration_missing_after_global_module_introducer);
1368 } else if (getLangOpts().getCompilingModule() ==
1370 // We can't use ModuleScopes here since ModuleScopes is always
1371 // empty if we're compiling the BMI.
1372 !getASTContext().getCurrentNamedModule()) {
1373 // If we are building a module interface unit, we should have seen the
1374 // module declaration.
1375 //
1376 // FIXME: Make a better guess as to where to put the module declaration.
1377 Diag(getSourceManager().getLocForStartOfFile(
1378 getSourceManager().getMainFileID()),
1379 diag::err_module_declaration_missing);
1380 }
1381
1382 // Now we can decide whether the modules we're building need an initializer.
1383 if (Module *CurrentModule = getCurrentModule();
1384 CurrentModule && CurrentModule->isInterfaceOrPartition()) {
1385 auto DoesModNeedInit = [this](Module *M) {
1386 if (!getASTContext().getModuleInitializers(M).empty())
1387 return true;
1388 for (auto [Exported, _] : M->Exports)
1389 if (Exported->isNamedModuleInterfaceHasInit())
1390 return true;
1391 for (Module *I : M->Imports)
1393 return true;
1394
1395 return false;
1396 };
1397
1398 CurrentModule->NamedModuleHasInit =
1399 DoesModNeedInit(CurrentModule) ||
1400 llvm::any_of(CurrentModule->submodules(), DoesModNeedInit);
1401 }
1402
1403 if (TUKind == TU_ClangModule) {
1404 // If we are building a module, resolve all of the exported declarations
1405 // now.
1406 if (Module *CurrentModule = PP.getCurrentModule()) {
1407 ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap();
1408
1410 Stack.push_back(CurrentModule);
1411 while (!Stack.empty()) {
1412 Module *Mod = Stack.pop_back_val();
1413
1414 // Resolve the exported declarations and conflicts.
1415 // FIXME: Actually complain, once we figure out how to teach the
1416 // diagnostic client to deal with complaints in the module map at this
1417 // point.
1418 ModMap.resolveExports(Mod, /*Complain=*/false);
1419 ModMap.resolveUses(Mod, /*Complain=*/false);
1420 ModMap.resolveConflicts(Mod, /*Complain=*/false);
1421
1422 // Queue the submodules, so their exports will also be resolved.
1423 auto SubmodulesRange = Mod->submodules();
1424 Stack.append(SubmodulesRange.begin(), SubmodulesRange.end());
1425 }
1426 }
1427
1428 // Warnings emitted in ActOnEndOfTranslationUnit() should be emitted for
1429 // modules when they are built, not every time they are used.
1431 }
1432
1433 // C++ standard modules. Diagnose cases where a function is declared inline
1434 // in the module purview but has no definition before the end of the TU or
1435 // the start of a Private Module Fragment (if one is present).
1436 if (!PendingInlineFuncDecls.empty()) {
1437 for (auto *FD : PendingInlineFuncDecls) {
1438 bool DefInPMF = false;
1439 if (auto *FDD = FD->getDefinition()) {
1440 DefInPMF = FDD->getOwningModule()->isPrivateModule();
1441 if (!DefInPMF)
1442 continue;
1443 }
1444 Diag(FD->getLocation(), diag::err_export_inline_not_defined) << DefInPMF;
1445 // If we have a PMF it should be at the end of the ModuleScopes.
1446 if (DefInPMF &&
1447 ModuleScopes.back().Module->Kind == Module::PrivateModuleFragment) {
1448 Diag(ModuleScopes.back().BeginLoc, diag::note_private_module_fragment);
1449 }
1450 }
1451 PendingInlineFuncDecls.clear();
1452 }
1453
1454 // C99 6.9.2p2:
1455 // A declaration of an identifier for an object that has file
1456 // scope without an initializer, and without a storage-class
1457 // specifier or with the storage-class specifier static,
1458 // constitutes a tentative definition. If a translation unit
1459 // contains one or more tentative definitions for an identifier,
1460 // and the translation unit contains no external definition for
1461 // that identifier, then the behavior is exactly as if the
1462 // translation unit contains a file scope declaration of that
1463 // identifier, with the composite type as of the end of the
1464 // translation unit, with an initializer equal to 0.
1466 for (TentativeDefinitionsType::iterator
1467 T = TentativeDefinitions.begin(ExternalSource.get()),
1468 TEnd = TentativeDefinitions.end();
1469 T != TEnd; ++T) {
1470 VarDecl *VD = (*T)->getActingDefinition();
1471
1472 // If the tentative definition was completed, getActingDefinition() returns
1473 // null. If we've already seen this variable before, insert()'s second
1474 // return value is false.
1475 if (!VD || VD->isInvalidDecl() || !Seen.insert(VD).second)
1476 continue;
1477
1478 if (const IncompleteArrayType *ArrayT
1479 = Context.getAsIncompleteArrayType(VD->getType())) {
1480 // Set the length of the array to 1 (C99 6.9.2p5).
1481 Diag(VD->getLocation(), diag::warn_tentative_incomplete_array);
1482 llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true);
1483 QualType T = Context.getConstantArrayType(
1484 ArrayT->getElementType(), One, nullptr, ArraySizeModifier::Normal, 0);
1485 VD->setType(T);
1486 } else if (RequireCompleteType(VD->getLocation(), VD->getType(),
1487 diag::err_tentative_def_incomplete_type))
1488 VD->setInvalidDecl();
1489
1490 // No initialization is performed for a tentative definition.
1492
1493 // In C, if the definition is const-qualified and has no initializer, it
1494 // is left uninitialized unless it has static or thread storage duration.
1495 QualType Type = VD->getType();
1496 if (!VD->isInvalidDecl() && !getLangOpts().CPlusPlus &&
1497 Type.isConstQualified() && !VD->getAnyInitializer()) {
1498 unsigned DiagID = diag::warn_default_init_const_unsafe;
1499 if (VD->getStorageDuration() == SD_Static ||
1501 DiagID = diag::warn_default_init_const;
1502
1503 bool EmitCppCompat = !Diags.isIgnored(
1504 diag::warn_cxx_compat_hack_fake_diagnostic_do_not_emit,
1505 VD->getLocation());
1506
1507 Diag(VD->getLocation(), DiagID) << Type << EmitCppCompat;
1508 }
1509
1510 // Notify the consumer that we've completed a tentative definition.
1511 if (!VD->isInvalidDecl())
1512 Consumer.CompleteTentativeDefinition(VD);
1513 }
1514
1515 // In incremental mode, tentative definitions belong to the current
1516 // partial translation unit (PTU). Once they have been completed and
1517 // emitted to codegen, drop them to prevent re-emission in future PTUs.
1518 if (PP.isIncrementalProcessingEnabled())
1520 TentativeDefinitions.end());
1521
1522 for (auto *D : ExternalDeclarations) {
1523 if (!D || D->isInvalidDecl() || D->getPreviousDecl() || !D->isUsed())
1524 continue;
1525
1526 Consumer.CompleteExternalDeclaration(D);
1527 }
1528
1529 // Visit all pending #pragma export.
1530 for (const PendingPragmaInfo &Exported : PendingExportedNames.values()) {
1531 if (!Exported.Used)
1532 Diag(Exported.NameLoc, diag::warn_failed_to_resolve_pragma) << "export";
1533 }
1534
1535 if (LangOpts.HLSL)
1536 HLSL().ActOnEndOfTranslationUnit(getASTContext().getTranslationUnitDecl());
1537 if (LangOpts.OpenACC)
1539 getASTContext().getTranslationUnitDecl());
1540
1541 // If there were errors, disable 'unused' warnings since they will mostly be
1542 // noise. Don't warn for a use from a module: either we should warn on all
1543 // file-scope declarations in modules or not at all, but whether the
1544 // declaration is used is immaterial.
1545 if (!Diags.hasErrorOccurred() && TUKind != TU_ClangModule) {
1546 // Output warning for unused file scoped decls.
1547 for (UnusedFileScopedDeclsType::iterator
1548 I = UnusedFileScopedDecls.begin(ExternalSource.get()),
1549 E = UnusedFileScopedDecls.end();
1550 I != E; ++I) {
1551 if (ShouldRemoveFromUnused(this, *I))
1552 continue;
1553
1554 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
1555 const FunctionDecl *DiagD;
1556 if (!FD->hasBody(DiagD))
1557 DiagD = FD;
1558 if (DiagD->isDeleted())
1559 continue; // Deleted functions are supposed to be unused.
1560 SourceRange DiagRange = DiagD->getLocation();
1561 if (const ASTTemplateArgumentListInfo *ASTTAL =
1563 DiagRange.setEnd(ASTTAL->RAngleLoc);
1564 if (DiagD->isReferenced()) {
1565 if (isa<CXXMethodDecl>(DiagD))
1566 Diag(DiagD->getLocation(), diag::warn_unneeded_member_function)
1567 << DiagD << DiagRange;
1568 else {
1569 if (FD->getStorageClass() == SC_Static &&
1570 !FD->isInlineSpecified() &&
1571 !SourceMgr.isInMainFile(
1572 SourceMgr.getExpansionLoc(FD->getLocation())))
1573 Diag(DiagD->getLocation(),
1574 diag::warn_unneeded_static_internal_decl)
1575 << DiagD << DiagRange;
1576 else
1577 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
1578 << /*function=*/0 << DiagD << DiagRange;
1579 }
1580 } else if (!FD->isTargetMultiVersion() ||
1581 FD->isTargetMultiVersionDefault()) {
1582 if (FD->getDescribedFunctionTemplate())
1583 Diag(DiagD->getLocation(), diag::warn_unused_template)
1584 << /*function=*/0 << DiagD << DiagRange;
1585 else
1586 Diag(DiagD->getLocation(), isa<CXXMethodDecl>(DiagD)
1587 ? diag::warn_unused_member_function
1588 : diag::warn_unused_function)
1589 << DiagD << DiagRange;
1590 }
1591 } else {
1592 const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition();
1593 if (!DiagD)
1594 DiagD = cast<VarDecl>(*I);
1595 SourceRange DiagRange = DiagD->getLocation();
1596 if (const auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(DiagD)) {
1597 if (const ASTTemplateArgumentListInfo *ASTTAL =
1598 VTSD->getTemplateArgsAsWritten())
1599 DiagRange.setEnd(ASTTAL->RAngleLoc);
1600 }
1601 if (DiagD->isReferenced()) {
1602 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
1603 << /*variable=*/1 << DiagD << DiagRange;
1604 } else if (DiagD->getDescribedVarTemplate()) {
1605 Diag(DiagD->getLocation(), diag::warn_unused_template)
1606 << /*variable=*/1 << DiagD << DiagRange;
1607 } else if (DiagD->getType().isConstQualified()) {
1608 const SourceManager &SM = SourceMgr;
1609 if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) ||
1610 !PP.getLangOpts().IsHeaderFile)
1611 Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
1612 << DiagD << DiagRange;
1613 } else {
1614 Diag(DiagD->getLocation(), diag::warn_unused_variable)
1615 << DiagD << DiagRange;
1616 }
1617 }
1618 }
1619
1621 }
1622
1623 if (!Diags.isIgnored(diag::warn_unused_but_set_global, SourceLocation())) {
1624 // Diagnose unused-but-set static globals in a deterministic order.
1625 // Not tracking shadowing info for static globals; there's nothing to
1626 // shadow.
1627 struct LocAndDiag {
1628 SourceLocation Loc;
1630 };
1632 auto addDiag = [&DeclDiags](SourceLocation Loc, PartialDiagnostic PD) {
1633 DeclDiags.push_back(LocAndDiag{Loc, std::move(PD)});
1634 };
1635
1636 // For -Wunused-but-set-variable we only care about variables that were
1637 // referenced by the TU end.
1638 for (const auto &Ref : RefsMinusAssignments) {
1639 const VarDecl *VD = Ref.first;
1640 // Only diagnose internal linkage file vars defined in the main file to
1641 // match -Wunused-variable behavior and avoid false positives from
1642 // headers.
1644 DiagnoseUnusedButSetDecl(VD, addDiag);
1645 }
1646
1647 llvm::sort(DeclDiags,
1648 [](const LocAndDiag &LHS, const LocAndDiag &RHS) -> bool {
1649 // Sorting purely for determinism; matches behavior in
1650 // Sema::ActOnPopScope.
1651 return LHS.Loc < RHS.Loc;
1652 });
1653 for (const LocAndDiag &D : DeclDiags)
1654 Diag(D.Loc, D.PD);
1655 }
1656
1657 if (!Diags.isIgnored(diag::warn_unused_private_field, SourceLocation())) {
1658 // FIXME: Load additional unused private field candidates from the external
1659 // source.
1660 RecordCompleteMap RecordsComplete;
1661 RecordCompleteMap MNCComplete;
1662 for (const NamedDecl *D : UnusedPrivateFields) {
1663 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext());
1664 if (RD && !RD->isUnion() && !D->hasAttr<UnusedAttr>() &&
1665 IsRecordFullyDefined(RD, RecordsComplete, MNCComplete)) {
1666 Diag(D->getLocation(), diag::warn_unused_private_field)
1667 << D->getDeclName();
1668 }
1669 }
1670 }
1671
1672 if (!Diags.isIgnored(diag::warn_mismatched_delete_new, SourceLocation())) {
1673 if (ExternalSource)
1674 ExternalSource->ReadMismatchingDeleteExpressions(DeleteExprs);
1675 for (const auto &DeletedFieldInfo : DeleteExprs) {
1676 for (const auto &DeleteExprLoc : DeletedFieldInfo.second) {
1677 AnalyzeDeleteExprMismatch(DeletedFieldInfo.first, DeleteExprLoc.first,
1678 DeleteExprLoc.second);
1679 }
1680 }
1681 }
1682
1683 AnalysisWarnings.IssueWarnings(Context.getTranslationUnitDecl());
1684
1685 if (Context.hasAnyFunctionEffects())
1686 performFunctionEffectAnalysis(Context.getTranslationUnitDecl());
1687
1688 // Check we've noticed that we're no longer parsing the initializer for every
1689 // variable. If we miss cases, then at best we have a performance issue and
1690 // at worst a rejects-valid bug.
1691 assert(ParsingInitForAutoVars.empty() &&
1692 "Didn't unmark var as having its initializer parsed");
1693
1694 if (!PP.isIncrementalProcessingEnabled())
1695 TUScope = nullptr;
1696
1697 checkExposure(Context.getTranslationUnitDecl());
1698}
1699
1700
1701//===----------------------------------------------------------------------===//
1702// Helper functions.
1703//===----------------------------------------------------------------------===//
1704
1706 DeclContext *DC = CurContext;
1707
1708 while (true) {
1709 if (isa<BlockDecl>(DC) || isa<EnumDecl>(DC) || isa<CapturedDecl>(DC) ||
1711 DC = DC->getParent();
1712 } else if (!AllowLambda && isa<CXXMethodDecl>(DC) &&
1713 cast<CXXMethodDecl>(DC)->getOverloadedOperator() == OO_Call &&
1714 cast<CXXRecordDecl>(DC->getParent())->isLambda()) {
1715 DC = DC->getParent()->getParent();
1716 } else break;
1717 }
1718
1719 return DC;
1720}
1721
1722/// getCurFunctionDecl - If inside of a function body, this returns a pointer
1723/// to the function decl for the function being parsed. If we're currently
1724/// in a 'block', this returns the containing context.
1725FunctionDecl *Sema::getCurFunctionDecl(bool AllowLambda) const {
1726 DeclContext *DC = getFunctionLevelDeclContext(AllowLambda);
1727 return dyn_cast<FunctionDecl>(DC);
1728}
1729
1732 while (isa<RecordDecl>(DC))
1733 DC = DC->getParent();
1734 return dyn_cast<ObjCMethodDecl>(DC);
1735}
1736
1740 return cast<NamedDecl>(DC);
1741 return nullptr;
1742}
1743
1749
1750void Sema::EmitDiagnostic(unsigned DiagID, const DiagnosticBuilder &DB) {
1751 // FIXME: It doesn't make sense to me that DiagID is an incoming argument here
1752 // and yet we also use the current diag ID on the DiagnosticsEngine. This has
1753 // been made more painfully obvious by the refactor that introduced this
1754 // function, but it is possible that the incoming argument can be
1755 // eliminated. If it truly cannot be (for example, there is some reentrancy
1756 // issue I am not seeing yet), then there should at least be a clarifying
1757 // comment somewhere.
1758 Diagnostic DiagInfo(&Diags, DB);
1759 if (SFINAETrap *Trap = getSFINAEContext()) {
1760 sema::TemplateDeductionInfo *Info = Trap->getDeductionInfo();
1763 // We'll report the diagnostic below.
1764 break;
1765
1767 // Count this failure so that we know that template argument deduction
1768 // has failed.
1769 Trap->setErrorOccurred();
1770
1771 // Make a copy of this suppressed diagnostic and store it with the
1772 // template-deduction information.
1773 if (Info && !Info->hasSFINAEDiagnostic())
1774 Info->addSFINAEDiagnostic(
1775 DiagInfo.getLocation(),
1776 PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
1777
1778 Diags.setLastDiagnosticIgnored(true);
1779 return;
1780
1782 // Per C++ Core Issue 1170, access control is part of SFINAE.
1783 // Additionally, the WithAccessChecking flag can be used to temporarily
1784 // make access control a part of SFINAE for the purposes of checking
1785 // type traits.
1786 if (!Trap->withAccessChecking() && !getLangOpts().CPlusPlus11)
1787 break;
1788
1789 SourceLocation Loc = DiagInfo.getLocation();
1790
1791 // Suppress this diagnostic.
1792 Trap->setErrorOccurred();
1793
1794 // Make a copy of this suppressed diagnostic and store it with the
1795 // template-deduction information.
1796 if (Info && !Info->hasSFINAEDiagnostic())
1797 Info->addSFINAEDiagnostic(
1798 DiagInfo.getLocation(),
1799 PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
1800
1801 Diags.setLastDiagnosticIgnored(true);
1802
1803 // Now produce a C++98 compatibility warning.
1804 Diag(Loc, diag::warn_cxx98_compat_sfinae_access_control);
1805
1806 // The last diagnostic which Sema produced was ignored. Suppress any
1807 // notes attached to it.
1808 Diags.setLastDiagnosticIgnored(true);
1809 return;
1810 }
1811
1813 if (DiagnosticsEngine::Level Level = getDiagnostics().getDiagnosticLevel(
1814 DiagInfo.getID(), DiagInfo.getLocation());
1816 return;
1817 // Make a copy of this suppressed diagnostic and store it with the
1818 // template-deduction information;
1819 if (Info) {
1821 DiagInfo.getLocation(),
1822 PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
1823 if (!Diags.getDiagnosticIDs()->isNote(DiagID))
1825 Info->addSuppressedDiagnostic(Loc, std::move(PD));
1826 });
1827 }
1828
1829 // Suppress this diagnostic.
1830 Diags.setLastDiagnosticIgnored(true);
1831 return;
1832 }
1833 }
1834
1835 // Copy the diagnostic printing policy over the ASTContext printing policy.
1836 // TODO: Stop doing that. See: https://reviews.llvm.org/D45093#1090292
1837 Context.setPrintingPolicy(getPrintingPolicy());
1838
1839 // Emit the diagnostic.
1840 if (!Diags.EmitDiagnostic(DB))
1841 return;
1842
1843 // If this is not a note, and we're in a template instantiation
1844 // that is different from the last template instantiation where
1845 // we emitted an error, print a template instantiation
1846 // backtrace.
1847 if (!Diags.getDiagnosticIDs()->isNote(DiagID))
1849}
1850
1853 return true;
1854 auto *FD = dyn_cast<FunctionDecl>(CurContext);
1855 if (!FD)
1856 return false;
1857 auto Loc = DeviceDeferredDiags.find(FD);
1858 if (Loc == DeviceDeferredDiags.end())
1859 return false;
1860 for (auto PDAt : Loc->second) {
1861 if (Diags.getDiagnosticIDs()->isDefaultMappingAsError(
1862 PDAt.second.getDiagID()))
1863 return true;
1864 }
1865 return false;
1866}
1867
1868// Print notes showing how we can reach FD starting from an a priori
1869// known-callable function. When a function has multiple callers, emit
1870// each call chain separately. The first note in each chain uses
1871// "called by" and subsequent notes use "which is called by".
1872static void emitCallStackNotes(Sema &S, const FunctionDecl *FD) {
1873 auto FnIt = S.CUDA().DeviceKnownEmittedFns.find(FD);
1874 if (FnIt == S.CUDA().DeviceKnownEmittedFns.end())
1875 return;
1876
1877 for (const auto &CallerInfo : FnIt->second) {
1879 return;
1880 S.Diags.Report(CallerInfo.Loc, diag::note_called_by) << CallerInfo.FD;
1881 // Walk up the rest of the chain using "which is called by".
1882 auto NextIt = S.CUDA().DeviceKnownEmittedFns.find(CallerInfo.FD);
1883 while (NextIt != S.CUDA().DeviceKnownEmittedFns.end()) {
1885 return;
1886 const auto &Next = NextIt->second.front();
1887 S.Diags.Report(Next.Loc, diag::note_which_is_called_by) << Next.FD;
1888 NextIt = S.CUDA().DeviceKnownEmittedFns.find(Next.FD);
1889 }
1890 }
1891}
1892
1893namespace {
1894
1895/// Helper class that emits deferred diagnostic messages if an entity directly
1896/// or indirectly using the function that causes the deferred diagnostic
1897/// messages is known to be emitted.
1898///
1899/// During parsing of AST, certain diagnostic messages are recorded as deferred
1900/// diagnostics since it is unknown whether the functions containing such
1901/// diagnostics will be emitted. A list of potentially emitted functions and
1902/// variables that may potentially trigger emission of functions are also
1903/// recorded. DeferredDiagnosticsEmitter recursively visits used functions
1904/// by each function to emit deferred diagnostics.
1905///
1906/// During the visit, certain OpenMP directives or initializer of variables
1907/// with certain OpenMP attributes will cause subsequent visiting of any
1908/// functions enter a state which is called OpenMP device context in this
1909/// implementation. The state is exited when the directive or initializer is
1910/// exited. This state can change the emission states of subsequent uses
1911/// of functions.
1912///
1913/// Conceptually the functions or variables to be visited form a use graph
1914/// where the parent node uses the child node. At any point of the visit,
1915/// the tree nodes traversed from the tree root to the current node form a use
1916/// stack. The emission state of the current node depends on two factors:
1917/// 1. the emission state of the root node
1918/// 2. whether the current node is in OpenMP device context
1919/// If the function is decided to be emitted, its contained deferred diagnostics
1920/// are emitted, together with the information about the use stack.
1921///
1922class DeferredDiagnosticsEmitter
1923 : public UsedDeclVisitor<DeferredDiagnosticsEmitter> {
1924public:
1925 typedef UsedDeclVisitor<DeferredDiagnosticsEmitter> Inherited;
1926
1927 // Whether the function is already in the current use-path.
1928 llvm::SmallPtrSet<CanonicalDeclPtr<Decl>, 4> InUsePath;
1929
1930 // The current use-path.
1931 llvm::SmallVector<CanonicalDeclPtr<FunctionDecl>, 4> UsePath;
1932
1933 // Whether the visiting of the function has been done. Done[0] is for the
1934 // case not in OpenMP device context. Done[1] is for the case in OpenMP
1935 // device context. We need two sets because diagnostics emission may be
1936 // different depending on whether it is in OpenMP device context.
1937 llvm::SmallPtrSet<CanonicalDeclPtr<Decl>, 4> DoneMap[2];
1938
1939 // Functions that need their deferred diagnostics emitted. Collected
1940 // during the graph walk and emitted afterwards so that all callers
1941 // are known when producing call chain notes.
1942 llvm::SetVector<CanonicalDeclPtr<const FunctionDecl>> FnsToEmit;
1943
1944 // Emission state of the root node of the current use graph.
1945 bool ShouldEmitRootNode;
1946
1947 // Current OpenMP device context level. It is initialized to 0 and each
1948 // entering of device context increases it by 1 and each exit decreases
1949 // it by 1. Non-zero value indicates it is currently in device context.
1950 unsigned InOMPDeviceContext;
1951
1952 DeferredDiagnosticsEmitter(Sema &S)
1953 : Inherited(S), ShouldEmitRootNode(false), InOMPDeviceContext(0) {}
1954
1955 bool shouldVisitDiscardedStmt() const { return false; }
1956
1957 void VisitOMPTargetDirective(OMPTargetDirective *Node) {
1958 ++InOMPDeviceContext;
1959 Inherited::VisitOMPTargetDirective(Node);
1960 --InOMPDeviceContext;
1961 }
1962
1963 void visitUsedDecl(SourceLocation Loc, Decl *D) {
1964 if (isa<VarDecl>(D))
1965 return;
1966 if (auto *FD = dyn_cast<FunctionDecl>(D))
1967 checkFunc(Loc, FD);
1968 else
1969 Inherited::visitUsedDecl(Loc, D);
1970 }
1971
1972 // Visitor member and parent dtors called by this dtor.
1973 void VisitCalledDestructors(CXXDestructorDecl *DD) {
1974 const CXXRecordDecl *RD = DD->getParent();
1975
1976 // Visit the dtors of all members
1977 for (const FieldDecl *FD : RD->fields()) {
1978 QualType FT = FD->getType();
1979 if (const auto *ClassDecl = FT->getAsCXXRecordDecl();
1980 ClassDecl &&
1981 (ClassDecl->isBeingDefined() || ClassDecl->isCompleteDefinition()))
1982 if (CXXDestructorDecl *MemberDtor = ClassDecl->getDestructor())
1983 asImpl().visitUsedDecl(MemberDtor->getLocation(), MemberDtor);
1984 }
1985
1986 // Also visit base class dtors
1987 for (const auto &Base : RD->bases()) {
1988 QualType BaseType = Base.getType();
1989 if (const auto *BaseDecl = BaseType->getAsCXXRecordDecl();
1990 BaseDecl &&
1991 (BaseDecl->isBeingDefined() || BaseDecl->isCompleteDefinition()))
1992 if (CXXDestructorDecl *BaseDtor = BaseDecl->getDestructor())
1993 asImpl().visitUsedDecl(BaseDtor->getLocation(), BaseDtor);
1994 }
1995 }
1996
1997 void VisitDeclStmt(DeclStmt *DS) {
1998 // Visit dtors called by variables that need destruction
1999 for (auto *D : DS->decls())
2000 if (auto *VD = dyn_cast<VarDecl>(D))
2001 if (VD->isThisDeclarationADefinition() &&
2002 VD->needsDestruction(S.Context)) {
2003 QualType VT = VD->getType();
2004 if (const auto *ClassDecl = VT->getAsCXXRecordDecl();
2005 ClassDecl && (ClassDecl->isBeingDefined() ||
2006 ClassDecl->isCompleteDefinition()))
2007 if (CXXDestructorDecl *Dtor = ClassDecl->getDestructor())
2008 asImpl().visitUsedDecl(Dtor->getLocation(), Dtor);
2009 }
2010
2011 Inherited::VisitDeclStmt(DS);
2012 }
2013 void checkVar(VarDecl *VD) {
2014 assert(VD->isFileVarDecl() &&
2015 "Should only check file-scope variables");
2016 if (auto *Init = VD->getInit()) {
2017 auto DevTy = OMPDeclareTargetDeclAttr::getDeviceType(VD);
2018 bool IsDev = DevTy && (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost ||
2019 *DevTy == OMPDeclareTargetDeclAttr::DT_Any);
2020 if (IsDev)
2021 ++InOMPDeviceContext;
2022 this->Visit(Init);
2023 if (IsDev)
2024 --InOMPDeviceContext;
2025 }
2026 }
2027
2028 void checkFunc(SourceLocation Loc, FunctionDecl *FD) {
2029 auto &Done = DoneMap[InOMPDeviceContext > 0 ? 1 : 0];
2030 FunctionDecl *Caller = UsePath.empty() ? nullptr : UsePath.back();
2031 if ((!ShouldEmitRootNode && !S.getLangOpts().OpenMP && !Caller) ||
2032 S.shouldIgnoreInHostDeviceCheck(FD) || InUsePath.count(FD))
2033 return;
2034 // Finalize analysis of OpenMP-specific constructs.
2035 if (Caller && S.LangOpts.OpenMP && UsePath.size() == 1 &&
2036 (ShouldEmitRootNode || InOMPDeviceContext))
2037 S.OpenMP().finalizeOpenMPDelayedAnalysis(Caller, FD, Loc);
2038 if (Caller) {
2039 auto &Callers = S.CUDA().DeviceKnownEmittedFns[FD];
2040 CanonicalDeclPtr<const FunctionDecl> CanonCaller(Caller);
2041 if (llvm::none_of(Callers, [CanonCaller](const auto &C) {
2042 return C.FD == CanonCaller;
2043 }))
2044 Callers.push_back({Caller, Loc});
2045 }
2046 if (ShouldEmitRootNode || InOMPDeviceContext)
2047 FnsToEmit.insert(FD);
2048 // Do not revisit a function if the function body has been completely
2049 // visited before.
2050 if (!Done.insert(FD).second)
2051 return;
2052 InUsePath.insert(FD);
2053 UsePath.push_back(FD);
2054 if (auto *S = FD->getBody()) {
2055 this->Visit(S);
2056 }
2057 if (CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(FD))
2058 asImpl().VisitCalledDestructors(Dtor);
2059 UsePath.pop_back();
2060 InUsePath.erase(FD);
2061 }
2062
2063 void checkRecordedDecl(Decl *D) {
2064 if (auto *FD = dyn_cast<FunctionDecl>(D)) {
2065 ShouldEmitRootNode = S.getEmissionStatus(FD, /*Final=*/true) ==
2066 Sema::FunctionEmissionStatus::Emitted;
2067 checkFunc(SourceLocation(), FD);
2068 } else
2069 checkVar(cast<VarDecl>(D));
2070 }
2071
2072 void emitDeferredDiags(const FunctionDecl *FD) {
2073 auto It = S.DeviceDeferredDiags.find(FD);
2074 if (It == S.DeviceDeferredDiags.end())
2075 return;
2076 bool HasWarningOrError = false;
2077 for (PartialDiagnosticAt &PDAt : It->second) {
2078 if (S.Diags.hasFatalErrorOccurred())
2079 return;
2080 const SourceLocation &Loc = PDAt.first;
2081 const PartialDiagnostic &PD = PDAt.second;
2082 HasWarningOrError |=
2083 S.getDiagnostics().getDiagnosticLevel(PD.getDiagID(), Loc) >=
2085 {
2086 DiagnosticBuilder Builder(S.Diags.Report(Loc, PD.getDiagID()));
2087 PD.Emit(Builder);
2088 }
2089 }
2090 if (HasWarningOrError)
2091 emitCallStackNotes(S, FD);
2092 }
2093
2094 void emitCollectedDiags() {
2095 for (const auto &FD : FnsToEmit)
2096 emitDeferredDiags(FD);
2097 }
2098};
2099} // namespace
2100
2102 if (ExternalSource)
2103 ExternalSource->ReadDeclsToCheckForDeferredDiags(
2105
2106 if ((DeviceDeferredDiags.empty() && !LangOpts.OpenMP) ||
2108 return;
2109
2110 DeferredDiagnosticsEmitter DDE(*this);
2111 for (auto *D : DeclsToCheckForDeferredDiags)
2112 DDE.checkRecordedDecl(D);
2113 DDE.emitCollectedDiags();
2114}
2115
2116// In CUDA, there are some constructs which may appear in semantically-valid
2117// code, but trigger errors if we ever generate code for the function in which
2118// they appear. Essentially every construct you're not allowed to use on the
2119// device falls into this category, because you are allowed to use these
2120// constructs in a __host__ __device__ function, but only if that function is
2121// never codegen'ed on the device.
2122//
2123// To handle semantic checking for these constructs, we keep track of the set of
2124// functions we know will be emitted, either because we could tell a priori that
2125// they would be emitted, or because they were transitively called by a
2126// known-emitted function.
2127//
2128// We also keep a partial call graph of which not-known-emitted functions call
2129// which other not-known-emitted functions.
2130//
2131// When we see something which is illegal if the current function is emitted
2132// (usually by way of DiagIfDeviceCode, DiagIfHostCode, or
2133// CheckCall), we first check if the current function is known-emitted. If
2134// so, we immediately output the diagnostic.
2135//
2136// Otherwise, we "defer" the diagnostic. It sits in Sema::DeviceDeferredDiags
2137// until we discover that the function is known-emitted, at which point we take
2138// it out of this map and emit the diagnostic.
2139
2140Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(Kind K, SourceLocation Loc,
2141 unsigned DiagID,
2142 const FunctionDecl *Fn,
2143 Sema &S)
2144 : S(S), Loc(Loc), DiagID(DiagID), Fn(Fn),
2145 ShowCallStack(K == K_ImmediateWithCallStack || K == K_Deferred) {
2146 switch (K) {
2147 case K_Nop:
2148 break;
2149 case K_Immediate:
2150 case K_ImmediateWithCallStack:
2151 ImmediateDiag.emplace(
2152 ImmediateDiagBuilder(S.Diags.Report(Loc, DiagID), S, DiagID));
2153 break;
2154 case K_Deferred:
2155 assert(Fn && "Must have a function to attach the deferred diag to.");
2156 auto &Diags = S.DeviceDeferredDiags[Fn];
2157 PartialDiagId.emplace(Diags.size());
2158 Diags.emplace_back(Loc, S.PDiag(DiagID));
2159 break;
2160 }
2161}
2162
2163Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D)
2164 : S(D.S), Loc(D.Loc), DiagID(D.DiagID), Fn(D.Fn),
2165 ShowCallStack(D.ShowCallStack), ImmediateDiag(D.ImmediateDiag),
2166 PartialDiagId(D.PartialDiagId) {
2167 // Clean the previous diagnostics.
2168 D.ShowCallStack = false;
2169 D.ImmediateDiag.reset();
2170 D.PartialDiagId.reset();
2171}
2172
2173Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() {
2174 if (ImmediateDiag) {
2175 // Emit our diagnostic and, if it was a warning or error, output a callstack
2176 // if Fn isn't a priori known-emitted.
2177 ImmediateDiag.reset(); // Emit the immediate diag.
2178
2179 if (ShowCallStack) {
2180 bool IsWarningOrError = S.getDiagnostics().getDiagnosticLevel(
2181 DiagID, Loc) >= DiagnosticsEngine::Warning;
2182 if (IsWarningOrError)
2183 emitCallStackNotes(S, Fn);
2184 }
2185 } else {
2186 assert((!PartialDiagId || ShowCallStack) &&
2187 "Must always show call stack for deferred diags.");
2188 }
2189}
2190
2191Sema::SemaDiagnosticBuilder
2192Sema::targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD) {
2193 FD = FD ? FD : getCurFunctionDecl();
2194 if (LangOpts.OpenMP)
2195 return LangOpts.OpenMPIsTargetDevice
2196 ? OpenMP().diagIfOpenMPDeviceCode(Loc, DiagID, FD)
2197 : OpenMP().diagIfOpenMPHostCode(Loc, DiagID, FD);
2198 if (getLangOpts().CUDA)
2199 return getLangOpts().CUDAIsDevice ? CUDA().DiagIfDeviceCode(Loc, DiagID)
2200 : CUDA().DiagIfHostCode(Loc, DiagID);
2201
2202 if (getLangOpts().SYCLIsDevice)
2203 return SYCL().DiagIfDeviceCode(Loc, DiagID);
2204
2206 FD, *this);
2207}
2208
2210 if (isUnevaluatedContext() || Ty.isNull())
2211 return;
2212
2213 // The original idea behind checkTypeSupport function is that unused
2214 // declarations can be replaced with an array of bytes of the same size during
2215 // codegen, such replacement doesn't seem to be possible for types without
2216 // constant byte size like zero length arrays. So, do a deep check for SYCL.
2217 if (D && LangOpts.SYCLIsDevice) {
2218 llvm::DenseSet<QualType> Visited;
2219 SYCL().deepTypeCheckForDevice(Loc, Visited, D);
2220 }
2221
2223
2224 // Memcpy operations for structs containing a member with unsupported type
2225 // are ok, though.
2226 if (const auto *MD = dyn_cast<CXXMethodDecl>(C)) {
2227 if ((MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()) &&
2228 MD->isTrivial())
2229 return;
2230
2231 if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(MD))
2232 if (Ctor->isCopyOrMoveConstructor() && Ctor->isTrivial())
2233 return;
2234 }
2235
2236 // Try to associate errors with the lexical context, if that is a function, or
2237 // the value declaration otherwise.
2238 const FunctionDecl *FD = isa<FunctionDecl>(C)
2240 : dyn_cast_or_null<FunctionDecl>(D);
2241
2242 auto CheckDeviceType = [&](QualType Ty) {
2243 if (Ty->isDependentType())
2244 return;
2245
2246 if (Ty->isBitIntType()) {
2247 if (!Context.getTargetInfo().hasBitIntType()) {
2248 PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
2249 if (D)
2250 PD << D;
2251 else
2252 PD << "expression";
2253 targetDiag(Loc, PD, FD)
2254 << false /*show bit size*/ << 0 /*bitsize*/ << false /*return*/
2255 << Ty << Context.getTargetInfo().getTriple().str();
2256 }
2257 return;
2258 }
2259
2260 // Check if we are dealing with two 'long double' but with different
2261 // semantics.
2262 bool LongDoubleMismatched = false;
2263 if (Ty->isRealFloatingType() && Context.getTypeSize(Ty) == 128) {
2264 const llvm::fltSemantics &Sem = Context.getFloatTypeSemantics(Ty);
2265 if ((&Sem != &llvm::APFloat::PPCDoubleDouble() &&
2266 !Context.getTargetInfo().hasFloat128Type()) ||
2267 (&Sem == &llvm::APFloat::PPCDoubleDouble() &&
2268 !Context.getTargetInfo().hasIbm128Type()))
2269 LongDoubleMismatched = true;
2270 }
2271
2272 if ((Ty->isFloat16Type() && !Context.getTargetInfo().hasFloat16Type()) ||
2273 (Ty->isFloat128Type() && !Context.getTargetInfo().hasFloat128Type()) ||
2274 (Ty->isIbm128Type() && !Context.getTargetInfo().hasIbm128Type()) ||
2275 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
2276 !Context.getTargetInfo().hasInt128Type()) ||
2277 (Ty->isBFloat16Type() && !Context.getTargetInfo().hasBFloat16Type() &&
2278 !LangOpts.CUDAIsDevice) ||
2279 LongDoubleMismatched) {
2280 PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
2281 if (D)
2282 PD << D;
2283 else
2284 PD << "expression";
2285
2286 if (targetDiag(Loc, PD, FD)
2287 << true /*show bit size*/
2288 << static_cast<unsigned>(Context.getTypeSize(Ty)) << Ty
2289 << false /*return*/ << Context.getTargetInfo().getTriple().str()) {
2290 if (D)
2291 D->setInvalidDecl();
2292 }
2293 if (D)
2294 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2295 }
2296 };
2297
2298 auto CheckType = [&](QualType Ty, bool IsRetTy = false) {
2299 if (LangOpts.SYCLIsDevice ||
2300 (LangOpts.OpenMP && LangOpts.OpenMPIsTargetDevice) ||
2301 LangOpts.CUDAIsDevice)
2302 CheckDeviceType(Ty);
2303
2305 const TargetInfo &TI = Context.getTargetInfo();
2306 if (!TI.hasLongDoubleType() && UnqualTy == Context.LongDoubleTy) {
2307 PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
2308 if (D)
2309 PD << D;
2310 else
2311 PD << "expression";
2312
2313 if (Diag(Loc, PD) << false /*show bit size*/ << 0 << Ty
2314 << false /*return*/
2315 << TI.getTriple().str()) {
2316 if (D)
2317 D->setInvalidDecl();
2318 }
2319 if (D)
2320 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2321 }
2322
2323 bool IsDouble = UnqualTy == Context.DoubleTy;
2324 bool IsFloat = UnqualTy == Context.FloatTy;
2325 if (IsRetTy && !TI.hasFPReturn() && (IsDouble || IsFloat)) {
2326 PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
2327 if (D)
2328 PD << D;
2329 else
2330 PD << "expression";
2331
2332 if (Diag(Loc, PD) << false /*show bit size*/ << 0 << Ty << true /*return*/
2333 << TI.getTriple().str()) {
2334 if (D)
2335 D->setInvalidDecl();
2336 }
2337 if (D)
2338 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
2339 }
2340
2341 if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType() && FD) {
2342 llvm::StringMap<bool> CallerFeatureMap;
2343 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
2344 RISCV().checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
2345 }
2346
2347 // Don't allow SVE types in functions without a SVE target.
2348 if (Ty->isSVESizelessBuiltinType() && FD) {
2349 llvm::StringMap<bool> CallerFeatureMap;
2350 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
2351 ARM().checkSVETypeSupport(Ty, Loc, FD, CallerFeatureMap);
2352 }
2353
2354 if (auto *VT = Ty->getAs<VectorType>();
2355 VT && FD &&
2356 (VT->getVectorKind() == VectorKind::SveFixedLengthData ||
2357 VT->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
2358 (LangOpts.VScaleMin != LangOpts.VScaleStreamingMin ||
2359 LangOpts.VScaleMax != LangOpts.VScaleStreamingMax)) {
2360 if (IsArmStreamingFunction(FD, /*IncludeLocallyStreaming=*/true)) {
2361 Diag(Loc, diag::err_sve_fixed_vector_in_streaming_function)
2362 << Ty << /*Streaming*/ 0;
2363 } else if (const auto *FTy = FD->getType()->getAs<FunctionProtoType>()) {
2364 if (FTy->getAArch64SMEAttributes() &
2366 Diag(Loc, diag::err_sve_fixed_vector_in_streaming_function)
2367 << Ty << /*StreamingCompatible*/ 1;
2368 }
2369 }
2370 }
2371 };
2372
2373 CheckType(Ty);
2374 if (const auto *FPTy = dyn_cast<FunctionProtoType>(Ty)) {
2375 for (const auto &ParamTy : FPTy->param_types())
2376 CheckType(ParamTy);
2377 CheckType(FPTy->getReturnType(), /*IsRetTy=*/true);
2378 }
2379 if (const auto *FNPTy = dyn_cast<FunctionNoProtoType>(Ty))
2380 CheckType(FNPTy->getReturnType(), /*IsRetTy=*/true);
2381}
2382
2383bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) {
2384 SourceLocation loc = locref;
2385 if (!loc.isMacroID()) return false;
2386
2387 // There's no good way right now to look at the intermediate
2388 // expansions, so just jump to the expansion location.
2389 loc = getSourceManager().getExpansionLoc(loc);
2390
2391 // If that's written with the name, stop here.
2392 SmallString<16> buffer;
2393 if (getPreprocessor().getSpelling(loc, buffer) == name) {
2394 locref = loc;
2395 return true;
2396 }
2397 return false;
2398}
2399
2401
2402 if (!Ctx)
2403 return nullptr;
2404
2405 Ctx = Ctx->getPrimaryContext();
2406 for (Scope *S = getCurScope(); S; S = S->getParent()) {
2407 // Ignore scopes that cannot have declarations. This is important for
2408 // out-of-line definitions of static class members.
2409 if (S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope))
2410 if (DeclContext *Entity = S->getEntity())
2411 if (Ctx == Entity->getPrimaryContext())
2412 return S;
2413 }
2414
2415 return nullptr;
2416}
2417
2418/// Enter a new function scope
2420 if (FunctionScopes.empty() && CachedFunctionScope) {
2421 // Use CachedFunctionScope to avoid allocating memory when possible.
2422 CachedFunctionScope->Clear();
2423 FunctionScopes.push_back(CachedFunctionScope.release());
2424 } else {
2426 }
2427 if (LangOpts.OpenMP)
2428 OpenMP().pushOpenMPFunctionRegion();
2429}
2430
2433 BlockScope, Block));
2435}
2436
2439 FunctionScopes.push_back(LSI);
2441 return LSI;
2442}
2443
2445 if (LambdaScopeInfo *const LSI = getCurLambda()) {
2446 LSI->AutoTemplateParameterDepth = Depth;
2447 return;
2448 }
2449 llvm_unreachable(
2450 "Remove assertion if intentionally called in a non-lambda context.");
2451}
2452
2453// Check that the type of the VarDecl has an accessible copy constructor and
2454// resolve its destructor's exception specification.
2455// This also performs initialization of block variables when they are moved
2456// to the heap. It uses the same rules as applicable for implicit moves
2457// according to the C++ standard in effect ([class.copy.elision]p3).
2458static void checkEscapingByref(VarDecl *VD, Sema &S) {
2459 QualType T = VD->getType();
2462 SourceLocation Loc = VD->getLocation();
2463 Expr *VarRef =
2464 new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK_LValue, Loc);
2465 ExprResult Result;
2466 auto IE = InitializedEntity::InitializeBlock(Loc, T);
2467 if (S.getLangOpts().CPlusPlus23) {
2468 auto *E = ImplicitCastExpr::Create(S.Context, T, CK_NoOp, VarRef, nullptr,
2470 Result = S.PerformCopyInitialization(IE, SourceLocation(), E);
2471 } else {
2474 VarRef);
2475 }
2476
2477 if (!Result.isInvalid()) {
2478 Result = S.MaybeCreateExprWithCleanups(Result);
2479 Expr *Init = Result.getAs<Expr>();
2481 }
2482
2483 // The destructor's exception specification is needed when IRGen generates
2484 // block copy/destroy functions. Resolve it here.
2485 if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
2486 if (CXXDestructorDecl *DD = RD->getDestructor()) {
2487 auto *FPT = DD->getType()->castAs<FunctionProtoType>();
2488 S.ResolveExceptionSpec(Loc, FPT);
2489 }
2490}
2491
2492static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S) {
2493 // Set the EscapingByref flag of __block variables captured by
2494 // escaping blocks.
2495 for (const BlockDecl *BD : FSI.Blocks) {
2496 for (const BlockDecl::Capture &BC : BD->captures()) {
2497 VarDecl *VD = BC.getVariable();
2498 if (VD->hasAttr<BlocksAttr>()) {
2499 // Nothing to do if this is a __block variable captured by a
2500 // non-escaping block.
2501 if (BD->doesNotEscape())
2502 continue;
2503 VD->setEscapingByref();
2504 }
2505 // Check whether the captured variable is or contains an object of
2506 // non-trivial C union type.
2507 QualType CapType = BC.getVariable()->getType();
2510 S.checkNonTrivialCUnion(BC.getVariable()->getType(),
2511 BD->getCaretLocation(),
2514 }
2515 }
2516
2517 for (VarDecl *VD : FSI.ByrefBlockVars) {
2518 // __block variables might require us to capture a copy-initializer.
2519 if (!VD->isEscapingByref())
2520 continue;
2521 // It's currently invalid to ever have a __block variable with an
2522 // array type; should we diagnose that here?
2523 // Regardless, we don't want to ignore array nesting when
2524 // constructing this copy.
2525 if (VD->getType()->isStructureOrClassType())
2526 checkEscapingByref(VD, S);
2527 }
2528}
2529
2532 QualType BlockType) {
2533 assert(!FunctionScopes.empty() && "mismatched push/pop!");
2534
2535 markEscapingByrefs(*FunctionScopes.back(), *this);
2536
2539
2540 if (LangOpts.OpenMP)
2541 OpenMP().popOpenMPFunctionRegion(Scope.get());
2542
2543 // Issue any analysis-based warnings.
2544 if (WP && D) {
2545 inferNoReturnAttr(*this, D);
2546 AnalysisWarnings.IssueWarnings(*WP, Scope.get(), D, BlockType);
2547 } else
2548 for (const auto &PUD : Scope->PossiblyUnreachableDiags)
2549 Diag(PUD.Loc, PUD.PD);
2550
2551 return Scope;
2552}
2553
2556 if (!Scope->isPlainFunction())
2557 Self->CapturingFunctionScopes--;
2558 // Stash the function scope for later reuse if it's for a normal function.
2559 if (Scope->isPlainFunction() && !Self->CachedFunctionScope)
2560 Self->CachedFunctionScope.reset(Scope);
2561 else
2562 delete Scope;
2563}
2564
2565void Sema::PushCompoundScope(bool IsStmtExpr) {
2566 getCurFunction()->CompoundScopes.push_back(
2567 CompoundScopeInfo(IsStmtExpr, getCurFPFeatures()));
2568}
2569
2571 FunctionScopeInfo *CurFunction = getCurFunction();
2572 assert(!CurFunction->CompoundScopes.empty() && "mismatched push/pop");
2573
2574 CurFunction->CompoundScopes.pop_back();
2575}
2576
2578 return getCurFunction()->hasUnrecoverableErrorOccurred();
2579}
2580
2582 if (!FunctionScopes.empty())
2583 FunctionScopes.back()->setHasBranchIntoScope();
2584}
2585
2587 if (!FunctionScopes.empty())
2588 FunctionScopes.back()->setHasBranchProtectedScope();
2589}
2590
2592 if (!FunctionScopes.empty())
2593 FunctionScopes.back()->setHasIndirectGoto();
2594}
2595
2597 if (!FunctionScopes.empty())
2598 FunctionScopes.back()->setHasMustTail();
2599}
2600
2602 if (FunctionScopes.empty())
2603 return nullptr;
2604
2605 auto CurBSI = dyn_cast<BlockScopeInfo>(FunctionScopes.back());
2606 if (CurBSI && CurBSI->TheDecl &&
2607 !CurBSI->TheDecl->Encloses(CurContext)) {
2608 // We have switched contexts due to template instantiation.
2609 assert(!CodeSynthesisContexts.empty());
2610 return nullptr;
2611 }
2612
2613 return CurBSI;
2614}
2615
2617 if (FunctionScopes.empty())
2618 return nullptr;
2619
2620 for (int e = FunctionScopes.size() - 1; e >= 0; --e) {
2622 continue;
2623 return FunctionScopes[e];
2624 }
2625 return nullptr;
2626}
2627
2629 for (auto *Scope : llvm::reverse(FunctionScopes)) {
2630 if (auto *CSI = dyn_cast<CapturingScopeInfo>(Scope)) {
2631 auto *LSI = dyn_cast<LambdaScopeInfo>(CSI);
2632 if (LSI && LSI->Lambda && !LSI->Lambda->Encloses(CurContext) &&
2633 LSI->AfterParameterList) {
2634 // We have switched contexts due to template instantiation.
2635 // FIXME: We should swap out the FunctionScopes during code synthesis
2636 // so that we don't need to check for this.
2637 assert(!CodeSynthesisContexts.empty());
2638 return nullptr;
2639 }
2640 return CSI;
2641 }
2642 }
2643 return nullptr;
2644}
2645
2646LambdaScopeInfo *Sema::getCurLambda(bool IgnoreNonLambdaCapturingScope) {
2647 if (FunctionScopes.empty())
2648 return nullptr;
2649
2650 auto I = FunctionScopes.rbegin();
2651 if (IgnoreNonLambdaCapturingScope) {
2652 auto E = FunctionScopes.rend();
2653 while (I != E && isa<CapturingScopeInfo>(*I) && !isa<LambdaScopeInfo>(*I))
2654 ++I;
2655 if (I == E)
2656 return nullptr;
2657 }
2658 auto *CurLSI = dyn_cast<LambdaScopeInfo>(*I);
2659 if (CurLSI && CurLSI->Lambda && CurLSI->CallOperator &&
2660 !CurLSI->Lambda->Encloses(CurContext) && CurLSI->AfterParameterList) {
2661 // We have switched contexts due to template instantiation.
2662 assert(!CodeSynthesisContexts.empty());
2663 return nullptr;
2664 }
2665
2666 return CurLSI;
2667}
2668
2669// We have a generic lambda if we parsed auto parameters, or we have
2670// an associated template parameter list.
2672 if (LambdaScopeInfo *LSI = getCurLambda()) {
2673 return (LSI->TemplateParams.size() ||
2674 LSI->GLTemplateParameterList) ? LSI : nullptr;
2675 }
2676 return nullptr;
2677}
2678
2679
2681 if (!LangOpts.RetainCommentsFromSystemHeaders &&
2682 SourceMgr.isInSystemHeader(Comment.getBegin()))
2683 return;
2684 RawComment RC(SourceMgr, Comment, LangOpts.CommentOpts, false);
2686 SourceRange MagicMarkerRange(Comment.getBegin(),
2687 Comment.getBegin().getLocWithOffset(3));
2688 StringRef MagicMarkerText;
2689 switch (RC.getKind()) {
2691 MagicMarkerText = "///<";
2692 break;
2694 MagicMarkerText = "/**<";
2695 break;
2697 // FIXME: are there other scenarios that could produce an invalid
2698 // raw comment here?
2699 Diag(Comment.getBegin(), diag::warn_splice_in_doxygen_comment);
2700 return;
2701 default:
2702 llvm_unreachable("if this is an almost Doxygen comment, "
2703 "it should be ordinary");
2704 }
2705 Diag(Comment.getBegin(), diag::warn_not_a_doxygen_trailing_member_comment) <<
2706 FixItHint::CreateReplacement(MagicMarkerRange, MagicMarkerText);
2707 }
2708 Context.addComment(RC);
2709}
2710
2711// Pin this vtable to this file.
2713char ExternalSemaSource::ID;
2714
2717
2721
2723 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {}
2724
2726 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &) {}
2727
2728bool Sema::tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
2730 ZeroArgCallReturnTy = QualType();
2731 OverloadSet.clear();
2732
2733 const OverloadExpr *Overloads = nullptr;
2734 bool IsMemExpr = false;
2735 if (E.getType() == Context.OverloadTy) {
2737
2738 // Ignore overloads that are pointer-to-member constants.
2740 return false;
2741
2742 Overloads = FR.Expression;
2743 } else if (E.getType() == Context.BoundMemberTy) {
2744 Overloads = dyn_cast<UnresolvedMemberExpr>(E.IgnoreParens());
2745 IsMemExpr = true;
2746 }
2747
2748 bool Ambiguous = false;
2749 bool IsMV = false;
2750
2751 if (Overloads) {
2752 for (OverloadExpr::decls_iterator it = Overloads->decls_begin(),
2753 DeclsEnd = Overloads->decls_end(); it != DeclsEnd; ++it) {
2754 OverloadSet.addDecl(*it);
2755
2756 // Check whether the function is a non-template, non-member which takes no
2757 // arguments.
2758 if (IsMemExpr)
2759 continue;
2760 if (const FunctionDecl *OverloadDecl
2761 = dyn_cast<FunctionDecl>((*it)->getUnderlyingDecl())) {
2762 if (OverloadDecl->getMinRequiredArguments() == 0) {
2763 if (!ZeroArgCallReturnTy.isNull() && !Ambiguous &&
2764 (!IsMV || !(OverloadDecl->isCPUDispatchMultiVersion() ||
2765 OverloadDecl->isCPUSpecificMultiVersion()))) {
2766 ZeroArgCallReturnTy = QualType();
2767 Ambiguous = true;
2768 } else {
2769 ZeroArgCallReturnTy = OverloadDecl->getReturnType();
2770 IsMV = OverloadDecl->isCPUDispatchMultiVersion() ||
2771 OverloadDecl->isCPUSpecificMultiVersion();
2772 }
2773 }
2774 }
2775 }
2776
2777 // If it's not a member, use better machinery to try to resolve the call
2778 if (!IsMemExpr)
2779 return !ZeroArgCallReturnTy.isNull();
2780 }
2781
2782 // Attempt to call the member with no arguments - this will correctly handle
2783 // member templates with defaults/deduction of template arguments, overloads
2784 // with default arguments, etc.
2785 if (IsMemExpr && !E.isTypeDependent()) {
2786 Sema::TentativeAnalysisScope Trap(*this);
2788 SourceLocation());
2789 if (R.isUsable()) {
2790 ZeroArgCallReturnTy = R.get()->getType();
2791 return true;
2792 }
2793 return false;
2794 }
2795
2796 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(E.IgnoreParens())) {
2797 if (const auto *Fun = dyn_cast<FunctionDecl>(DeclRef->getDecl())) {
2798 if (Fun->getMinRequiredArguments() == 0)
2799 ZeroArgCallReturnTy = Fun->getReturnType();
2800 return true;
2801 }
2802 }
2803
2804 // We don't have an expression that's convenient to get a FunctionDecl from,
2805 // but we can at least check if the type is "function of 0 arguments".
2806 QualType ExprTy = E.getType();
2807 const FunctionType *FunTy = nullptr;
2808 QualType PointeeTy = ExprTy->getPointeeType();
2809 if (!PointeeTy.isNull())
2810 FunTy = PointeeTy->getAs<FunctionType>();
2811 if (!FunTy)
2812 FunTy = ExprTy->getAs<FunctionType>();
2813
2814 if (const auto *FPT = dyn_cast_if_present<FunctionProtoType>(FunTy)) {
2815 if (FPT->getNumParams() == 0)
2816 ZeroArgCallReturnTy = FunTy->getReturnType();
2817 return true;
2818 }
2819 return false;
2820}
2821
2822/// Give notes for a set of overloads.
2823///
2824/// A companion to tryExprAsCall. In cases when the name that the programmer
2825/// wrote was an overloaded function, we may be able to make some guesses about
2826/// plausible overloads based on their return types; such guesses can be handed
2827/// off to this method to be emitted as notes.
2828///
2829/// \param Overloads - The overloads to note.
2830/// \param FinalNoteLoc - If we've suppressed printing some overloads due to
2831/// -fshow-overloads=best, this is the location to attach to the note about too
2832/// many candidates. Typically this will be the location of the original
2833/// ill-formed expression.
2834static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads,
2835 const SourceLocation FinalNoteLoc) {
2836 unsigned ShownOverloads = 0;
2837 unsigned SuppressedOverloads = 0;
2838 for (UnresolvedSetImpl::iterator It = Overloads.begin(),
2839 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
2840 if (ShownOverloads >= S.Diags.getNumOverloadCandidatesToShow()) {
2841 ++SuppressedOverloads;
2842 continue;
2843 }
2844
2845 const NamedDecl *Fn = (*It)->getUnderlyingDecl();
2846 // Don't print overloads for non-default multiversioned functions.
2847 if (const auto *FD = Fn->getAsFunction()) {
2848 if (FD->isMultiVersion() && FD->hasAttr<TargetAttr>() &&
2849 !FD->getAttr<TargetAttr>()->isDefaultVersion())
2850 continue;
2851 if (FD->isMultiVersion() && FD->hasAttr<TargetVersionAttr>() &&
2852 !FD->getAttr<TargetVersionAttr>()->isDefaultVersion())
2853 continue;
2854 }
2855 S.Diag(Fn->getLocation(), diag::note_possible_target_of_call);
2856 ++ShownOverloads;
2857 }
2858
2859 S.Diags.overloadCandidatesShown(ShownOverloads);
2860
2861 if (SuppressedOverloads)
2862 S.Diag(FinalNoteLoc, diag::note_ovl_too_many_candidates)
2863 << SuppressedOverloads;
2864}
2865
2867 const UnresolvedSetImpl &Overloads,
2868 bool (*IsPlausibleResult)(QualType)) {
2869 if (!IsPlausibleResult)
2870 return noteOverloads(S, Overloads, Loc);
2871
2872 UnresolvedSet<2> PlausibleOverloads;
2873 for (OverloadExpr::decls_iterator It = Overloads.begin(),
2874 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
2875 const auto *OverloadDecl = cast<FunctionDecl>(*It);
2876 QualType OverloadResultTy = OverloadDecl->getReturnType();
2877 if (IsPlausibleResult(OverloadResultTy))
2878 PlausibleOverloads.addDecl(It.getDecl());
2879 }
2880 noteOverloads(S, PlausibleOverloads, Loc);
2881}
2882
2883/// Determine whether the given expression can be called by just
2884/// putting parentheses after it. Notably, expressions with unary
2885/// operators can't be because the unary operator will start parsing
2886/// outside the call.
2887static bool IsCallableWithAppend(const Expr *E) {
2888 E = E->IgnoreImplicit();
2889 return (!isa<CStyleCastExpr>(E) &&
2890 !isa<UnaryOperator>(E) &&
2891 !isa<BinaryOperator>(E) &&
2893}
2894
2896 if (const auto *UO = dyn_cast<UnaryOperator>(E))
2897 E = UO->getSubExpr();
2898
2899 if (const auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
2900 if (ULE->getNumDecls() == 0)
2901 return false;
2902
2903 const NamedDecl *ND = *ULE->decls_begin();
2904 if (const auto *FD = dyn_cast<FunctionDecl>(ND))
2906 }
2907 return false;
2908}
2909
2911 bool ForceComplain,
2912 bool (*IsPlausibleResult)(QualType)) {
2913 SourceLocation Loc = E.get()->getExprLoc();
2914 SourceRange Range = E.get()->getSourceRange();
2915 UnresolvedSet<4> Overloads;
2916
2917 // If this is a SFINAE context, don't try anything that might trigger ADL
2918 // prematurely.
2919 if (!isSFINAEContext()) {
2920 QualType ZeroArgCallTy;
2921 if (tryExprAsCall(*E.get(), ZeroArgCallTy, Overloads) &&
2922 !ZeroArgCallTy.isNull() &&
2923 (!IsPlausibleResult || IsPlausibleResult(ZeroArgCallTy))) {
2924 // At this point, we know E is potentially callable with 0
2925 // arguments and that it returns something of a reasonable type,
2926 // so we can emit a fixit and carry on pretending that E was
2927 // actually a CallExpr.
2928 SourceLocation ParenInsertionLoc = getLocForEndOfToken(Range.getEnd());
2930 Diag(Loc, PD) << /*zero-arg*/ 1 << IsMV << Range
2931 << (IsCallableWithAppend(E.get())
2932 ? FixItHint::CreateInsertion(ParenInsertionLoc,
2933 "()")
2934 : FixItHint());
2935 if (!IsMV)
2936 notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult);
2937
2938 // FIXME: Try this before emitting the fixit, and suppress diagnostics
2939 // while doing so.
2940 E = BuildCallExpr(nullptr, E.get(), Range.getEnd(), {},
2941 Range.getEnd().getLocWithOffset(1));
2942 return true;
2943 }
2944 }
2945 if (!ForceComplain) return false;
2946
2948 Diag(Loc, PD) << /*not zero-arg*/ 0 << IsMV << Range;
2949 if (!IsMV)
2950 notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult);
2951 E = ExprError();
2952 return true;
2953}
2954
2956 if (!Ident_super)
2957 Ident_super = &Context.Idents.get("super");
2958 return Ident_super;
2959}
2960
2963 unsigned OpenMPCaptureLevel) {
2964 auto *CSI = new CapturedRegionScopeInfo(
2965 getDiagnostics(), S, CD, RD, CD->getContextParam(), K,
2966 (getLangOpts().OpenMP && K == CR_OpenMP)
2967 ? OpenMP().getOpenMPNestingLevel()
2968 : 0,
2969 OpenMPCaptureLevel);
2970 CSI->ReturnType = Context.VoidTy;
2971 FunctionScopes.push_back(CSI);
2973}
2974
2976 if (FunctionScopes.empty())
2977 return nullptr;
2978
2979 return dyn_cast<CapturedRegionScopeInfo>(FunctionScopes.back());
2980}
2981
2982const llvm::MapVector<FieldDecl *, Sema::DeleteLocs> &
2986
2988 : S(S), OldFPFeaturesState(S.CurFPFeatures),
2989 OldOverrides(S.FpPragmaStack.CurrentValue),
2990 OldEvalMethod(S.PP.getCurrentFPEvalMethod()),
2991 OldFPPragmaLocation(S.PP.getLastFPEvalPragmaLocation()) {}
2992
2994 S.CurFPFeatures = OldFPFeaturesState;
2995 S.FpPragmaStack.CurrentValue = OldOverrides;
2996 S.PP.setCurrentFPEvalMethod(OldFPPragmaLocation, OldEvalMethod);
2997}
2998
3000 assert(D.getCXXScopeSpec().isSet() &&
3001 "can only be called for qualified names");
3002
3003 auto LR = LookupResult(*this, D.getIdentifier(), D.getBeginLoc(),
3007 if (!DC)
3008 return false;
3009
3010 LookupQualifiedName(LR, DC);
3011 bool Result = llvm::all_of(LR, [](Decl *Dcl) {
3012 if (NamedDecl *ND = dyn_cast<NamedDecl>(Dcl)) {
3013 ND = ND->getUnderlyingDecl();
3014 return isa<FunctionDecl>(ND) || isa<FunctionTemplateDecl>(ND) ||
3015 isa<UsingDecl>(ND);
3016 }
3017 return false;
3018 });
3019 return Result;
3020}
3021
3024
3025 auto *A = AnnotateAttr::Create(Context, Annot, Args.data(), Args.size(), CI);
3027 CI, MutableArrayRef<Expr *>(A->args_begin(), A->args_end()))) {
3028 return nullptr;
3029 }
3030 return A;
3031}
3032
3034 // Make sure that there is a string literal as the annotation's first
3035 // argument.
3036 StringRef Str;
3037 if (!checkStringLiteralArgumentAttr(AL, 0, Str))
3038 return nullptr;
3039
3041 Args.reserve(AL.getNumArgs() - 1);
3042 for (unsigned Idx = 1; Idx < AL.getNumArgs(); Idx++) {
3043 assert(!AL.isArgIdent(Idx));
3044 Args.push_back(AL.getArgAsExpr(Idx));
3045 }
3046
3047 return CreateAnnotationAttr(AL, Str, Args);
3048}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
FormatToken * Next
The next token in the unwrapped line.
#define SM(sm)
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::Preprocessor interface.
This file declares semantic analysis functions specific to AMDGPU.
This file declares semantic analysis functions specific to ARM.
This file declares semantic analysis functions specific to AVR.
This file declares semantic analysis functions specific to BPF.
This file declares semantic analysis for CUDA constructs.
This file declares facilities that support code completion.
This file declares semantic analysis for DirectX constructs.
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis functions specific to Hexagon.
This file declares semantic analysis functions specific to LoongArch.
This file declares semantic analysis functions specific to M68k.
This file declares semantic analysis functions specific to MIPS.
This file declares semantic analysis functions specific to MSP430.
This file declares semantic analysis functions specific to NVPTX.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenACC constructs and clauses.
This file declares semantic analysis routines for OpenCL.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis functions specific to PowerPC.
This file declares semantic analysis for expressions involving.
This file declares semantic analysis functions specific to RISC-V.
This file declares semantic analysis for SPIRV constructs.
This file declares semantic analysis for SYCL constructs.
This file declares semantic analysis functions specific to Swift.
This file declares semantic analysis functions specific to SystemZ.
This file declares semantic analysis functions specific to Wasm.
This file declares semantic analysis functions specific to X86.
static void checkEscapingByref(VarDecl *VD, Sema &S)
Definition Sema.cpp:2458
static bool IsCPUDispatchCPUSpecificMultiVersion(const Expr *E)
Definition Sema.cpp:2895
llvm::DenseMap< const CXXRecordDecl *, bool > RecordCompleteMap
Definition Sema.cpp:1107
static bool IsCallableWithAppend(const Expr *E)
Determine whether the given expression can be called by just putting parentheses after it.
Definition Sema.cpp:2887
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:1114
static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads, const SourceLocation FinalNoteLoc)
Give notes for a set of overloads.
Definition Sema.cpp:2834
static bool isFunctionOrVarDeclExternC(const NamedDecl *ND)
Definition Sema.cpp:947
static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S)
Definition Sema.cpp:2492
static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D)
Used to prune the decls of Sema's UnusedFileScopedDecls vector.
Definition Sema.cpp:886
static void emitCallStackNotes(Sema &S, const FunctionDecl *FD)
Definition Sema.cpp:1872
static void notePlausibleOverloads(Sema &S, SourceLocation Loc, const UnresolvedSetImpl &Overloads, bool(*IsPlausibleResult)(QualType))
Definition Sema.cpp:2866
static void checkUndefinedButUsed(Sema &S)
checkUndefinedButUsed - Check for undefined objects with internal linkage or that are inline.
Definition Sema.cpp:1025
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:1156
Defines the SourceManager interface.
Allows QualTypes to be sorted and hence used in maps and sets.
TypePropertyCache< Private > Cache
Definition Type.cpp:4866
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition ASTConsumer.h:35
virtual ASTMutationListener * GetASTMutationListener()
If the consumer is interested in entities getting modified after their initial creation,...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
LangAS getDefaultOpenCLPointeeAddrSpace()
Returns default address space based on OpenCL version and enabled features.
void setBlockVarCopyInit(const VarDecl *VD, Expr *CopyExpr, bool CanThrow)
Set the copy initialization expression of a block var decl.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
PtrTy get() const
Definition Ownership.h:171
bool isInvalid() const
Definition Ownership.h:167
Attr - This represents one attribute.
Definition Attr.h:46
A class which contains all the information about a particular captured value.
Definition Decl.h:4695
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4689
ArrayRef< Capture > captures() const
Definition Decl.h:4816
SourceLocation getCaretLocation() const
Definition Decl.h:4762
bool doesNotEscape() const
Definition Decl.h:4840
Represents a C++ destructor within a class.
Definition DeclCXX.h:2889
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:2136
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition DeclCXX.h:2275
An iterator over the friend declarations of a class.
Definition DeclFriend.h:198
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
friend_iterator friend_begin() const
Definition DeclFriend.h:250
base_class_range bases()
Definition DeclCXX.h:608
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition DeclCXX.cpp:2131
friend_iterator friend_end() const
Definition DeclFriend.h:254
bool isSet() const
Deprecated.
Definition DeclSpec.h:199
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:4961
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition Decl.h:5019
static const char * getCastKindName(CastKind CK)
Definition Expr.cpp:1951
Abstract interface for a consumer of code-completion information.
The information about the darwin SDK that was used during this compilation.
decl_iterator - Iterates through the declarations stored within this context.
Definition DeclBase.h:2343
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1462
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2122
decl_iterator decls_end() const
Definition DeclBase.h:2388
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
decl_iterator decls_begin() const
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1273
FriendSpecified isFriendSpecified() const
Definition DeclSpec.h:826
decl_range decls()
Definition Stmt.h:1680
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
T * getAttr() const
Definition DeclBase.h:581
void addAttr(Attr *A)
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition DeclBase.cpp:178
bool isReferenced() const
Whether any declaration of this entity was referenced.
Definition DeclBase.cpp:601
bool isInvalidDecl() const
Definition DeclBase.h:596
SourceLocation getLocation() const
Definition DeclBase.h:447
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:576
bool hasAttr() const
Definition DeclBase.h:585
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
Definition Decl.h:780
Information about one declarator, including the parsed type information and the identifier.
Definition DeclSpec.h:1921
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition DeclSpec.h:2068
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclSpec.h:2104
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
Definition DeclSpec.h:2083
const IdentifierInfo * getIdentifier() const
Definition DeclSpec.h:2351
A little helper class used to produce diagnostics.
static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID)
Determines whether the given built-in diagnostic ID is for an error that is suppressed if it occurs d...
@ SFINAE_SubstitutionFailure
The diagnostic should not be reported, but it should cause template argument deduction to fail.
@ SFINAE_Suppress
The diagnostic should be suppressed entirely.
@ SFINAE_AccessControl
The diagnostic is an access-control diagnostic, which will be substitution failures in some contexts ...
@ SFINAE_Report
The diagnostic should be reported.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
const SourceLocation & getLocation() const
unsigned getID() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
void overloadCandidatesShown(unsigned N)
Call this after showing N overload candidates.
Definition Diagnostic.h:785
unsigned getNumOverloadCandidatesToShow() const
When a call or operator fails, print out up to this many candidate overloads as suggestions.
Definition Diagnostic.h:770
Level
The level of the diagnostic, after it has been through mapping.
Definition Diagnostic.h:237
bool hasFatalErrorOccurred() const
Definition Diagnostic.h:887
RAII object that enters a new expression evaluation context.
This represents one expression.
Definition Expr.h:112
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Definition Expr.cpp:3090
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3078
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3086
bool isPRValue() const
Definition Expr.h:285
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:144
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:2716
virtual void ReadMethodPool(Selector Sel)
Load the contents of the global method pool for a given selector.
Definition Sema.cpp:2715
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:2722
~ExternalSemaSource() override
Definition Sema.cpp:2712
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:2718
virtual void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 > > &)
Definition Sema.cpp:2725
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
Definition Decl.h:3175
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...
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition Diagnostic.h:79
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:140
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:103
Represents a function declaration or definition.
Definition Decl.h:2015
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Definition Decl.h:2704
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3281
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
Definition Decl.cpp:3708
bool isDeleted() const
Whether this function has been deleted.
Definition Decl.h:2555
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
Definition Decl.cpp:3704
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2400
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition Decl.cpp:4341
static FunctionEffectsRef get(QualType QT)
Extract the effects from a Type if it is a function, block, or member function pointer,...
Definition TypeBase.h:9366
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5357
Declaration of a template function.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4553
QualType getReturnType() const
Definition TypeBase.h:4893
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3856
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2073
Represents a C array with an unspecified size.
Definition TypeBase.h:3959
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type)
@ CMK_HeaderUnit
Compiling a module header unit.
@ CMK_ModuleInterface
Compiling a C++ modules interface unit.
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
static std::optional< Token > findNextToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeComments=false)
Finds the token that comes right after the given location.
Definition Lexer.cpp:1339
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:858
Represents the results of name lookup.
Definition Lookup.h:147
Encapsulates the data about a macro definition (e.g.
Definition MacroInfo.h:39
Abstract interface for a module loader.
bool resolveExports(Module *Mod, bool Complain)
Resolve all of the unresolved exports in the given module.
bool resolveConflicts(Module *Mod, bool Complain)
Resolve all of the unresolved conflicts in the given module.
bool resolveUses(Module *Mod, bool Complain)
Resolve all of the unresolved uses in the given module.
Describes a module or submodule.
Definition Module.h:246
bool isNamedModuleInterfaceHasInit() const
Definition Module.h:787
bool isInterfaceOrPartition() const
Definition Module.h:774
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition Module.h:561
llvm::iterator_range< submodule_iterator > submodules()
Definition Module.h:952
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
Definition Module.h:282
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
Definition Module.h:279
static const unsigned NumNSNumberLiteralMethods
Definition NSAPI.h:191
This represents a decl that may have a name.
Definition Decl.h:274
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition Decl.h:429
NamedDecl * getMostRecentDecl()
Definition Decl.h:501
bool isExternallyVisible() const
Definition Decl.h:433
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:3129
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
Definition ExprCXX.h:3190
UnresolvedSetImpl::iterator decls_iterator
Definition ExprCXX.h:3220
decls_iterator decls_begin() const
Definition ExprCXX.h:3222
decls_iterator decls_end() const
Definition ExprCXX.h:3225
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition PPCallbacks.h:37
ParsedAttr - Represents a syntactic attribute.
Definition ParsedAttr.h:119
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
Definition ParsedAttr.h:371
bool isArgIdent(unsigned Arg) const
Definition ParsedAttr.h:385
Expr * getArgAsExpr(unsigned Arg) const
Definition ParsedAttr.h:383
void Emit(const DiagnosticBuilder &DB) const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
A (possibly-)qualified type.
Definition TypeBase.h:937
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:85
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
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:79
QualType getCanonicalType() const
Definition TypeBase.h:8483
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8525
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition TypeBase.h:8504
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:4342
field_range fields() const
Definition Decl.h:4545
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:111
@ K_Immediate
Emit the diagnostic immediately (i.e., behave like Sema::Diag()).
Definition SemaBase.h:117
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition SemaBase.cpp:33
SemaBase(Sema &S)
Definition SemaBase.cpp:7
const LangOptions & getLangOpts() const
Definition SemaBase.cpp:11
DiagnosticsEngine & getDiagnostics() const
Definition SemaBase.cpp:10
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition SemaBase.cpp:61
llvm::DenseMap< CanonicalDeclPtr< const FunctionDecl >, llvm::SmallVector< FunctionDeclAndLoc, 1 > > DeviceKnownEmittedFns
An inverse call graph, mapping known-emitted functions to their known-emitted callers (plus the locat...
Definition SemaCUDA.h:83
An abstract interface that should be implemented by clients that read ASTs and then require further s...
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU)
ObjCMethodDecl * NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]
The Objective-C NSNumber methods used to create NSNumber literals.
Definition SemaObjC.h:606
void DiagnoseUseOfUnimplementedSelectors()
std::unique_ptr< NSAPI > NSAPIObj
Caches identifiers/selectors for NSFoundation APIs.
Definition SemaObjC.h:591
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU)
void DiagnoseUnterminatedOpenMPDeclareTarget()
Report unterminated 'omp declare target' or 'omp begin declare target' at the end of a compilation un...
A class which encapsulates the logic for delaying diagnostics during parsing and other processing.
Definition Sema.h:1386
sema::DelayedDiagnosticPool * getCurrentPool() const
Returns the current delayed-diagnostics pool.
Definition Sema.h:1401
Custom deleter to allow FunctionScopeInfos to be kept alive for a short time after they've been poppe...
Definition Sema.h:1073
void operator()(sema::FunctionScopeInfo *Scope) const
Definition Sema.cpp:2555
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Definition Sema.h:12542
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
Definition Sema.h:12586
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:868
SmallVector< DeclaratorDecl *, 4 > ExternalDeclarations
All the external declarations encoutered and used in the TU.
Definition Sema.h:3624
bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, MutableArrayRef< Expr * > Args)
ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs (unless they are value dependent ...
Definition SemaAttr.cpp:509
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
Definition Sema.h:13685
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition Sema.h:13139
sema::CapturingScopeInfo * getEnclosingLambdaOrBlock() const
Get the innermost lambda or block enclosing the current location, if any.
Definition Sema.cpp:2628
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition Sema.h:1141
bool IsBuildingRecoveryCallExpr
Flag indicating if Sema is building a recovery call expression.
Definition Sema.h:10136
void LoadExternalWeakUndeclaredIdentifiers()
Load weak undeclared identifiers from the external source.
Definition Sema.cpp:1087
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:955
bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, UnresolvedSetImpl &NonTemplateOverloads)
Figure out if an expression could be turned into a call.
Definition Sema.cpp:2728
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition Sema.h:9406
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the pragma attribute stack.
Definition Sema.h:2141
OpaquePtr< QualType > TypeTy
Definition Sema.h:1301
void addImplicitTypedef(StringRef Name, QualType T)
Definition Sema.cpp:366
void PrintContextStack()
Definition Sema.h:13772
SemaOpenMP & OpenMP()
Definition Sema.h:1533
void CheckDelegatingCtorCycles()
SmallVector< CXXMethodDecl *, 4 > DelayedDllExportMemberFunctions
Definition Sema.h:6352
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
Definition Sema.h:1262
llvm::SmallSetVector< const TypedefNameDecl *, 4 > UnusedLocalTypedefNameCandidates
Set containing all typedefs that are likely unused.
Definition Sema.h:3606
void emitAndClearUnusedLocalTypedefWarnings()
Definition Sema.cpp:1187
std::unique_ptr< CXXFieldCollector > FieldCollector
FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
Definition Sema.h:6569
unsigned CapturingFunctionScopes
Track the number of currently active capturing scopes.
Definition Sema.h:1251
SemaCUDA & CUDA()
Definition Sema.h:1473
void Initialize()
Perform initialization that occurs after the parser has been initialized but before it parses anythin...
Definition Sema.cpp:372
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
Definition Sema.h:1244
Preprocessor & getPreprocessor() const
Definition Sema.h:938
Scope * getScopeForContext(DeclContext *Ctx)
Determines the active Scope associated with the given declaration context.
Definition Sema.cpp:2400
PragmaStack< FPOptionsOverride > FpPragmaStack
Definition Sema.h:2076
PragmaStack< StringLiteral * > CodeSegStack
Definition Sema.h:2070
void setFunctionHasBranchIntoScope()
Definition Sema.cpp:2581
void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver)
If VD is set but not otherwise used, diagnose, for a parameter or a variable.
void ActOnComment(SourceRange Comment)
Definition Sema.cpp:2680
void ActOnEndOfTranslationUnit()
ActOnEndOfTranslationUnit - This is called at the very end of the translation unit when EOF is reache...
Definition Sema.cpp:1266
FPOptionsOverride CurFPFeatureOverrides()
Definition Sema.h:2077
ExprResult BuildCallToMemberFunction(Scope *S, Expr *MemExpr, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr, bool IsExecConfig=false, bool AllowRecovery=false)
BuildCallToMemberFunction - Build a call to a member function.
void ActOnTranslationUnitScope(Scope *S)
Scope actions.
Definition Sema.cpp:173
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
Look up a name, looking for a single declaration.
SemaSYCL & SYCL()
Definition Sema.h:1558
IdentifierInfo * getSuperIdentifier() const
Definition Sema.cpp:2955
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:1725
void DiagnosePrecisionLossInComplexDivision()
bool DisableTypoCorrection
Tracks whether we are in a context where typo correction is disabled.
Definition Sema.h:9346
ASTContext & Context
Definition Sema.h:1308
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:686
llvm::DenseMap< IdentifierInfo *, PendingPragmaInfo > PendingExportedNames
Definition Sema.h:2358
DiagnosticsEngine & getDiagnostics() const
Definition Sema.h:936
SemaObjC & ObjC()
Definition Sema.h:1518
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:2910
SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags
Diagnostics that are emitted only if we discover that the given function must be codegen'ed.
Definition Sema.h:1443
void CheckDelayedMemberExceptionSpecs()
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
ClassTemplateDecl * StdCoroutineTraitsCache
The C++ "std::coroutine_traits" template, which is defined in <coroutine_traits>
Definition Sema.h:3199
PragmaStack< bool > StrictGuardStackCheckStack
Definition Sema.h:2073
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:3614
ASTContext & getASTContext() const
Definition Sema.h:939
std::unique_ptr< sema::FunctionScopeInfo, PoppedFunctionScopeDeleter > PoppedFunctionScopePtr
Definition Sema.h:1081
void addExternalSource(IntrusiveRefCntPtr< ExternalSemaSource > E)
Registers an external source.
Definition Sema.cpp:661
ClassTemplateDecl * StdInitializerList
The C++ "std::initializer_list" template, which is defined in <initializer_list>.
Definition Sema.h:6595
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:6679
PragmaStack< StringLiteral * > ConstSegStack
Definition Sema.h:2069
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:762
unsigned TyposCorrected
The number of typos corrected by CorrectTypo.
Definition Sema.h:9349
static const unsigned MaxAlignmentExponent
The maximum alignment, same as in llvm::Value.
Definition Sema.h:1234
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
Definition Sema.h:1212
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
Definition Sema.cpp:1730
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
Definition Sema.cpp:2671
void setFunctionHasIndirectGoto()
Definition Sema.cpp:2591
LangAS getDefaultCXXMethodAddrSpace() const
Returns default addr space for method qualifiers.
Definition Sema.cpp:1744
void PushFunctionScope()
Enter a new function scope.
Definition Sema.cpp:2419
FPOptions & getCurFPFeatures()
Definition Sema.h:934
RecordDecl * StdSourceLocationImplDecl
The C++ "std::source_location::__impl" struct, defined in <source_location>.
Definition Sema.h:8389
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr)
Definition Sema.cpp:273
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition Sema.cpp:84
sema::LambdaScopeInfo * PushLambdaScope()
Definition Sema.cpp:2437
void PopCompoundScope()
Definition Sema.cpp:2570
api_notes::APINotesManager APINotes
Definition Sema.h:1312
const LangOptions & getLangOpts() const
Definition Sema.h:932
PoppedFunctionScopePtr PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP=nullptr, Decl *D=nullptr, QualType BlockType=QualType())
Pop a function (or block or lambda or captured region) scope from the stack.
Definition Sema.cpp:2531
SemaOpenACC & OpenACC()
Definition Sema.h:1523
const FunctionProtoType * ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT)
ASTConsumer & getASTConsumer() const
Definition Sema.h:940
void * OpaqueParser
Definition Sema.h:1352
Preprocessor & PP
Definition Sema.h:1307
ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr, bool IsExecConfig=false, bool AllowRecovery=false)
BuildCallExpr - Handle a call to Fn with the specified array of arguments.
threadSafety::BeforeSet * ThreadSafetyDeclCache
Definition Sema.h:1347
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:2209
const LangOptions & LangOpts
Definition Sema.h:1306
std::unique_ptr< sema::FunctionScopeInfo > CachedFunctionScope
Definition Sema.h:1240
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition Sema.cpp:2646
static const uint64_t MaximumAlignment
Definition Sema.h:1235
NamedDeclSetType UnusedPrivateFields
Set containing all declared private fields that are not used.
Definition Sema.h:6573
SemaHLSL & HLSL()
Definition Sema.h:1483
bool CollectStats
Flag indicating whether or not to collect detailed statistics.
Definition Sema.h:1238
void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind)
Definition Sema.cpp:1206
bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const
IdentifierInfo * InventAbbreviatedTemplateParameterTypeName(const IdentifierInfo *ParamName, unsigned Index)
Invent a new identifier for parameters of abbreviated templates.
Definition Sema.cpp:140
SemaRISCV & RISCV()
Definition Sema.h:1548
SmallVector< PendingImplicitInstantiation, 1 > LateParsedInstantiations
Queue of implicit template instantiations that cannot be performed eagerly.
Definition Sema.h:14103
void performFunctionEffectAnalysis(TranslationUnitDecl *TU)
PragmaStack< AlignPackInfo > AlignPackStack
Definition Sema.h:2058
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:6671
PragmaStack< StringLiteral * > BSSSegStack
Definition Sema.h:2068
DeclContext * getCurLexicalContext() const
Definition Sema.h:1145
NamedDecl * getCurFunctionOrMethodDecl() const
getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method or C function we're in,...
Definition Sema.cpp:1737
static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy)
ScalarTypeToBooleanCastKind - Returns the cast kind corresponding to the conversion from scalar type ...
Definition Sema.cpp:869
llvm::SmallSetVector< Decl *, 4 > DeclsToCheckForDeferredDiags
Function or variable declarations to be checked for whether the deferred diagnostics should be emitte...
Definition Sema.h:4811
sema::FunctionScopeInfo * getCurFunction() const
Definition Sema.h:1341
void PushCompoundScope(bool IsStmtExpr)
Definition Sema.cpp:2565
bool isDeclaratorFunctionLike(Declarator &D)
Determine whether.
Definition Sema.cpp:2999
llvm::DenseMap< const VarDecl *, int > RefsMinusAssignments
Increment when we find a reference; decrement when we find an ignored assignment.
Definition Sema.h:7033
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:2383
StringLiteral * CurInitSeg
Last section used with pragma init_seg.
Definition Sema.h:2111
Module * getCurrentModule() const
Get the module unit whose scope we are currently within.
Definition Sema.h:9932
static bool isCast(CheckedConversionKind CCK)
Definition Sema.h:2572
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2601
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1446
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
ClassTemplateDecl * StdTypeIdentity
The C++ "std::type_identity" template, which is defined in <type_traits>.
Definition Sema.h:6599
SemaOpenCL & OpenCL()
Definition Sema.h:1528
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5.
Definition Sema.h:8252
DeclContext * getFunctionLevelDeclContext(bool AllowLambda=false) const
If AllowLambda is true, treat lambda as function.
Definition Sema.cpp:1705
bool DefineUsedVTables()
Define all of the vtables that have been used in this translation unit and reference any virtual memb...
bool GlobalNewDeleteDeclared
A flag to remember whether the implicit forms of operator new and delete have been declared.
Definition Sema.h:8448
DeclContext * OriginalLexicalContext
Generally null except when we temporarily switch decl contexts, like in.
Definition Sema.h:3628
bool MSStructPragmaOn
Definition Sema.h:1832
unsigned NonInstantiationEntries
The number of CodeSynthesisContexts that are not template instantiations and, therefore,...
Definition Sema.h:13716
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
Definition Sema.h:14051
SourceManager & getSourceManager() const
Definition Sema.h:937
bool makeUnavailableInSystemHeader(SourceLocation loc, UnavailableAttr::ImplicitReason reason)
makeUnavailableInSystemHeader - There is an error in the current context.
Definition Sema.cpp:636
void getUndefinedButUsed(SmallVectorImpl< std::pair< NamedDecl *, SourceLocation > > &Undefined)
Obtain a sorted list of functions that are undefined but ODR-used.
Definition Sema.cpp:972
void diagnoseFunctionEffectConversion(QualType DstType, QualType SrcType, SourceLocation Loc)
Warn when implicitly changing function effects.
Definition Sema.cpp:702
void PerformPendingInstantiations(bool LocalOnly=false, bool AtEndOfTU=true)
Performs template instantiation for all implicit template instantiations we have seen until this poin...
ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, const NamedReturnInfo &NRInfo, Expr *Value, bool SupressSimplerImplicitMoves=false)
Perform the initialization of a potentially-movable value, which is the result of return value.
CanThrowResult canThrow(const Stmt *E)
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
@ NTCUK_Destruct
Definition Sema.h:4138
@ NTCUK_Copy
Definition Sema.h:4139
void PushBlockScope(Scope *BlockScope, BlockDecl *Block)
Definition Sema.cpp:2431
PragmaStack< MSVtorDispMode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
Definition Sema.h:2057
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
Definition Sema.h:2118
bool isSFINAEContext() const
Definition Sema.h:13784
UnsignedOrNone ArgPackSubstIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition Sema.h:13740
void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, RecordDecl *RD, CapturedRegionKind K, unsigned OpenMPCaptureLevel=0)
Definition Sema.cpp:2961
void emitDeferredDiags()
Definition Sema.cpp:2101
void setFunctionHasMustTail()
Definition Sema.cpp:2596
RecordDecl * CXXTypeInfoDecl
The C++ "type_info" declaration, which is defined in <typeinfo>.
Definition Sema.h:8444
void CheckCompleteVariableDeclaration(VarDecl *VD)
void setFunctionHasBranchProtectedScope()
Definition Sema.cpp:2586
RedeclarationKind forRedeclarationInCurContext() const
void ActOnStartOfTranslationUnit()
This is called before the very first declaration in the translation unit is parsed.
Definition Sema.cpp:1200
llvm::DenseMap< IdentifierInfo *, AsmLabelAttr * > ExtnameUndeclaredIdentifiers
ExtnameUndeclaredIdentifiers - Identifiers contained in #pragma redefine_extname before declared.
Definition Sema.h:3602
IntrusiveRefCntPtr< ExternalSemaSource > ExternalSource
Source of additional semantic information.
Definition Sema.h:1584
ASTConsumer & Consumer
Definition Sema.h:1309
llvm::SmallPtrSet< const Decl *, 4 > ParsingInitForAutoVars
ParsingInitForAutoVars - a set of declarations with auto types for which we are currently parsing the...
Definition Sema.h:4697
sema::AnalysisBasedWarnings AnalysisWarnings
Worker object for performing CFG-based warnings.
Definition Sema.h:1346
bool hasUncompilableErrorOccurred() const
Whether uncompilable error has occurred.
Definition Sema.cpp:1851
std::deque< PendingImplicitInstantiation > PendingInstantiations
The queue of implicit template instantiations that are required but have not yet been performed.
Definition Sema.h:14099
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with the preprocessor.
Definition Sema.cpp:110
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6811
std::pair< SourceLocation, bool > DeleteExprLoc
Definition Sema.h:988
void RecordParsingTemplateParameterDepth(unsigned Depth)
This is used to inform Sema what the current TemplateParameterDepth is during Parsing.
Definition Sema.cpp:2444
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
Definition Sema.h:1267
void DiagnoseUnterminatedPragmaAttribute()
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
LateTemplateParserCB * LateTemplateParser
Definition Sema.h:1351
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:8455
TentativeDefinitionsType TentativeDefinitions
All the tentative definitions encountered in the TU.
Definition Sema.h:3621
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
DarwinSDKInfo * getDarwinSDKInfoForAvailabilityChecking()
Definition Sema.cpp:124
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:2983
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition Sema.h:8392
void PushDeclContext(Scope *S, DeclContext *DC)
Set the current declaration context until it gets popped.
SourceManager & SourceMgr
Definition Sema.h:1311
DiagnosticsEngine & Diags
Definition Sema.h:1310
void DiagnoseUnterminatedPragmaAlignPack()
Definition SemaAttr.cpp:595
OpenCLOptions & getOpenCLOptions()
Definition Sema.h:933
FPOptions CurFPFeatures
Definition Sema.h:1304
void LoadExternalExtnameUndeclaredIdentifiers()
Load pragma redefine_extname'd undeclared identifiers from the external source.
Definition Sema.cpp:1097
PragmaStack< StringLiteral * > DataSegStack
Definition Sema.h:2067
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
Attr * CreateAnnotationAttr(const AttributeCommonInfo &CI, StringRef Annot, MutableArrayRef< Expr * > Args)
CreateAnnotationAttr - Creates an annotation Annot with Args arguments.
Definition Sema.cpp:3022
bool isMainFileLoc(SourceLocation Loc) const
Determines whether the given source location is in the main file and we're in a context where we shou...
Definition Sema.cpp:964
llvm::MapVector< NamedDecl *, SourceLocation > UndefinedButUsed
UndefinedInternals - all the used, undefined objects which require a definition in this translation u...
Definition Sema.h:6607
void PrintStats() const
Print out statistics about the semantic analysis.
Definition Sema.cpp:676
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition Sema.h:1830
llvm::BumpPtrAllocator BumpAlloc
Definition Sema.h:1253
SourceRange getRangeForNextToken(SourceLocation Loc, bool IncludeMacros, bool IncludeComments, std::optional< tok::TokenKind > ExpectedToken=std::nullopt)
Calls Lexer::findNextToken() to find the next token, and if the locations of both ends of the token c...
Definition Sema.cpp:89
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
Definition Sema.cpp:631
SmallVector< CXXRecordDecl *, 4 > DelayedDllExportClasses
Definition Sema.h:6351
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:3596
SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD=nullptr)
Definition Sema.cpp:2192
DeclarationName VAListTagName
VAListTagName - The declaration name corresponding to __va_list_tag.
Definition Sema.h:1365
sema::FunctionScopeInfo * getEnclosingFunction() const
Definition Sema.cpp:2616
sema::CapturedRegionScopeInfo * getCurCapturedRegion()
Retrieve the current captured region, if any.
Definition Sema.cpp:2975
void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E)
Warn when implicitly casting 0 to nullptr.
Definition Sema.cpp:714
void EmitDiagnostic(unsigned DiagID, const DiagnosticBuilder &DB)
Cause the built diagnostic to be emitted on the DiagosticsEngine.
Definition Sema.cpp:1750
void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, NonTrivialCUnionContext UseContext, unsigned NonTrivialKind)
Emit diagnostics if a non-trivial C union type or a struct that contains a non-trivial C union is use...
IdentifierResolver IdResolver
Definition Sema.h:3519
bool hasAnyUnrecoverableErrorsInThisFunction() const
Determine whether any errors occurred within this function/method/ block.
Definition Sema.cpp:2577
bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, const Expr *E, StringRef &Str, SourceLocation *ArgLocation=nullptr)
Check if the argument E is a ASCII string literal.
SemaARM & ARM()
Definition Sema.h:1453
llvm::DenseSet< InstantiatingSpecializationsKey > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
Definition Sema.h:13688
ASTMutationListener * getASTMutationListener() const
Definition Sema.cpp:657
SFINAETrap * getSFINAEContext() const
Returns a pointer to the current SFINAE context, if any.
Definition Sema.h:13781
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
void setEnd(SourceLocation e)
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3833
bool isUnion() const
Definition Decl.h:3943
Exposes information about the current target.
Definition TargetInfo.h:227
virtual bool hasLongDoubleType() const
Determine whether the long double type is supported on this target.
Definition TargetInfo.h:736
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual bool hasFPReturn() const
Determine whether return of a floating point value is supported on this target.
Definition TargetInfo.h:740
bool hasRISCVVTypes() const
Returns whether or not the RISC-V V built-in types are available on this target.
A container of type source information.
Definition TypeBase.h:8402
The base class of the type hierarchy.
Definition TypeBase.h:1866
bool isFloat16Type() const
Definition TypeBase.h:9043
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition TypeBase.h:9078
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
Definition Type.cpp:2620
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9328
bool isFloat128Type() const
Definition TypeBase.h:9063
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:754
bool isBitIntType() const
Definition TypeBase.h:8943
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2832
ScalarTypeKind getScalarTypeKind() const
Given that this is a scalar type, classify it.
Definition Type.cpp:2407
bool isIbm128Type() const
Definition TypeBase.h:9067
bool isOverflowBehaviorType() const
Definition TypeBase.h:8839
bool isBFloat16Type() const
Definition TypeBase.h:9055
bool isStructureOrClassType() const
Definition Type.cpp:708
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2358
bool isRVVSizelessBuiltinType() const
Returns true for RVV scalable vector types.
Definition Type.cpp:2641
Linkage getLinkage() const
Determine the linkage of this type.
Definition Type.cpp:4974
@ STK_FloatingComplex
Definition TypeBase.h:2814
@ STK_ObjCObjectPointer
Definition TypeBase.h:2808
@ STK_IntegralComplex
Definition TypeBase.h:2813
@ STK_MemberPointer
Definition TypeBase.h:2809
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9261
bool isNullPtrType() const
Definition TypeBase.h:9071
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
Definition Type.cpp:5100
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3577
A set of unresolved declarations.
UnresolvedSetIterator iterator
void addDecl(NamedDecl *D)
A set of unresolved declarations.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
void setType(QualType newType)
Definition Decl.h:724
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2823
void setEscapingByref()
Definition Decl.h:1622
VarDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
bool isInternalLinkageFileVar() const
Returns true if this is a file-scope variable with internal linkage.
Definition Decl.h:1216
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2379
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1357
const Expr * getInit() const
Definition Decl.h:1383
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
Definition Decl.cpp:2358
@ DeclarationOnly
This declaration is only a declaration.
Definition Decl.h:1310
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
Definition Decl.h:1244
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Definition Decl.cpp:2711
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition Decl.h:1373
Declaration of a variable template.
Represents a GCC generic vector type.
Definition TypeBase.h:4225
Retains information about a block that is currently being parsed.
Definition ScopeInfo.h:794
Retains information about a captured region.
Definition ScopeInfo.h:820
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:191
void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity Mapping, StringRef Str) override
Callback invoked when a #pragma gcc diagnostic directive is read.
Definition Sema.cpp:228
Provides information about an attempted template argument deduction, whose success or failure was des...
void addSuppressedDiagnostic(SourceLocation Loc, PartialDiagnostic PD)
Add a new diagnostic to the set of diagnostics.
void addSFINAEDiagnostic(SourceLocation Loc, PartialDiagnostic PD)
Set the diagnostic which caused the SFINAE failure.
bool hasSFINAEDiagnostic() const
Is a SFINAE diagnostic available?
Defines the clang::TargetInfo interface.
Definition SPIR.cpp:47
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Flavor
Flavors of diagnostics we can emit.
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
@ Remark
A diagnostic that indicates normal progress through compilation.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
void threadSafetyCleanup(BeforeSet *Cache)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
Definition FileEntry.h:208
@ CPlusPlus
@ CPlusPlus11
@ ExpectedVariableOrFunction
@ Nullable
Values of this type can be null.
Definition Specifiers.h:352
@ NonNull
Values of this type can never be null.
Definition Specifiers.h:350
Expected< std::optional< DarwinSDKInfo > > parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath)
Parse the SDK information from the SDKSettings.json file.
@ Override
Merge availability attributes for an override, which requires an exact match or a weakening of constr...
Definition Sema.h:636
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
CapturedRegionKind
The different kinds of captured statement.
@ CR_OpenMP
@ SC_Register
Definition Specifiers.h:257
@ SC_Static
Definition Specifiers.h:252
void inferNoReturnAttr(Sema &S, Decl *D)
@ SD_Thread
Thread storage duration.
Definition Specifiers.h:342
@ SD_Static
Static storage duration.
Definition Specifiers.h:343
@ Result
The result type of a method or function.
Definition TypeBase.h:905
@ Template
We are parsing a template declaration.
Definition Parser.h:81
TUFragmentKind
Definition Sema.h:487
@ Private
The private module fragment, between 'module :private;' and the end of the translation unit.
Definition Sema.h:496
@ Global
The global module fragment, between 'module;' and a module-declaration.
Definition Sema.h:489
@ Normal
A normal translation unit fragment.
Definition Sema.h:493
ExprResult ExprError()
Definition Ownership.h:265
@ OverloadSet
The name was classified as an overload set, and an expression representing that overload set has been...
Definition Sema.h:581
LangAS
Defines the address space values used by the address space qualifier of QualType.
CastKind
CastKind - The kind of operation required for a conversion.
TranslationUnitKind
Describes the kind of translation unit being processed.
@ TU_Complete
The translation unit is a complete translation unit.
@ TU_ClangModule
The translation unit is a clang module.
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
ComparisonCategoryType
An enumeration representing the different comparison categories types.
void FormatASTNodeDiagnosticArgument(DiagnosticsEngine::ArgumentKind Kind, intptr_t Val, StringRef Modifier, StringRef Argument, ArrayRef< DiagnosticsEngine::ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, void *Cookie, ArrayRef< intptr_t > QualTypeVals)
DiagnosticsEngine argument formatting function for diagnostics that involve AST nodes.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:132
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:135
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
Definition Specifiers.h:144
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:139
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:150
bool isExternalFormalLinkage(Linkage L)
Definition Linkage.h:117
@ SveFixedLengthData
is AArch64 SVE fixed-length data vector
Definition TypeBase.h:4204
@ SveFixedLengthPredicate
is AArch64 SVE fixed-length predicate vector
Definition TypeBase.h:4207
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5967
bool IsArmStreamingFunction(const FunctionDecl *FD, bool IncludeLocallyStreaming)
Returns whether the given FunctionDecl has an __arm[_locally]_streaming attribute.
Definition Decl.cpp:6101
bool isExternallyVisible(Linkage L)
Definition Linkage.h:90
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
CheckedConversionKind
The kind of conversion being performed.
Definition Sema.h:438
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>".
Describes how types, statements, expressions, and declarations should be printed.
unsigned Bool
Whether we can use 'bool' rather than '_Bool' (even if the language doesn't actually have 'bool',...
unsigned EntireContentsOfLargeArray
Whether to print the entire array initializers, especially on non-type template parameters,...
@ RewritingOperatorAsSpaceship
We are rewriting a comparison operator in terms of an operator<=>.
Definition Sema.h:13278
Information from a C++ pragma export, for a symbol that we haven't seen the declaration for yet.
Definition Sema.h:2353