clang 20.0.0git
SemaBase.cpp
Go to the documentation of this file.
2#include "clang/Sema/Sema.h"
4
5namespace clang {
6
7SemaBase::SemaBase(Sema &S) : SemaRef(S) {}
8
12
14 // If we aren't active, there is nothing to do.
15 if (!isActive())
16 return;
17
18 // Otherwise, we need to emit the diagnostic. First clear the diagnostic
19 // builder itself so it won't emit the diagnostic in its own destructor.
20 //
21 // This seems wasteful, in that as written the DiagnosticBuilder dtor will
22 // do its own needless checks to see if the diagnostic needs to be
23 // emitted. However, because we take care to ensure that the builder
24 // objects never escape, a sufficiently smart compiler will be able to
25 // eliminate that code.
26 Clear();
27
28 // Dispatch to Sema to emit the diagnostic.
29 SemaRef.EmitCurrentDiagnostic(DiagID);
30}
31
34}
35
38 const PartialDiagnostic &PD) {
39 if (Diag.ImmediateDiag)
40 PD.Emit(*Diag.ImmediateDiag);
41 else if (Diag.PartialDiagId)
42 Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD;
43 return Diag;
44}
45
47 const FixItHint &Hint) const {
48 if (ImmediateDiag)
49 ImmediateDiag->AddFixItHint(Hint);
50 else if (PartialDiagId)
51 S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint);
52}
53
54llvm::DenseMap<CanonicalDeclPtr<const FunctionDecl>,
55 std::vector<PartialDiagnosticAt>> &
56SemaBase::SemaDiagnosticBuilder::getDeviceDeferredDiags() const {
57 return S.DeviceDeferredDiags;
58}
59
61 bool DeferHint) {
62 bool IsError =
63 getDiagnostics().getDiagnosticIDs()->isDefaultMappingAsError(DiagID);
64 bool ShouldDefer = getLangOpts().CUDA && getLangOpts().GPUDeferDiag &&
66 (DeferHint || SemaRef.DeferDiags || !IsError);
67 auto SetIsLastErrorImmediate = [&](bool Flag) {
68 if (IsError)
70 };
71 if (!ShouldDefer) {
72 SetIsLastErrorImmediate(true);
75 }
76
77 SemaDiagnosticBuilder DB = getLangOpts().CUDAIsDevice
78 ? SemaRef.CUDA().DiagIfDeviceCode(Loc, DiagID)
79 : SemaRef.CUDA().DiagIfHostCode(Loc, DiagID);
80 SetIsLastErrorImmediate(DB.isImmediate());
81 return DB;
82}
83
85 const PartialDiagnostic &PD,
86 bool DeferHint) {
87 return Diag(Loc, PD.getDiagID(), DeferHint) << PD;
88}
89
90} // namespace clang
This file declares semantic analysis for CUDA constructs.
SourceLocation Loc
Definition: SemaObjC.cpp:759
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
PartialDiagnostic::DiagStorageAllocator & getDiagAllocator()
Definition: ASTContext.h:775
void Clear() const
Clear out the current diagnostic.
Definition: Diagnostic.h:1303
bool isActive() const
Determine whether this diagnostic is still active.
Definition: Diagnostic.h:1310
static bool isDeferrable(unsigned DiagID)
Whether the diagnostic message can be deferred.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Definition: Diagnostic.h:557
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:71
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:476
void Emit(const DiagnosticBuilder &DB) const
A generic diagnostic builder for errors which may or may not be deferred.
Definition: SemaBase.h:110
@ K_Immediate
Emit the diagnostic immediately (i.e., behave like Sema::Diag()).
Definition: SemaBase.h:116
void AddFixItHint(const FixItHint &Hint) const
Definition: SemaBase.cpp:46
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaBase.cpp:32
SemaBase(Sema &S)
Definition: SemaBase.cpp:7
ASTContext & getASTContext() const
Definition: SemaBase.cpp:9
Sema & SemaRef
Definition: SemaBase.h:40
const LangOptions & getLangOpts() const
Definition: SemaBase.cpp:11
DiagnosticsEngine & getDiagnostics() const
Definition: SemaBase.cpp:10
SemaDiagnosticBuilder DiagIfHostCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as host cod...
Definition: SemaCUDA.cpp:851
SemaDiagnosticBuilder DiagIfDeviceCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device c...
Definition: SemaCUDA.cpp:819
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:493
bool IsLastErrorImmediate
Is the last error level diagnostic immediate.
Definition: Sema.h:1025
SemaCUDA & CUDA()
Definition: Sema.h:1124
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:1567
ASTContext & Context
Definition: Sema.h:962
SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags
Diagnostics that are emitted only if we discover that the given function must be codegen'ed.
Definition: Sema.h:1094
void EmitCurrentDiagnostic(unsigned DiagID)
Cause the active diagnostic on the DiagosticsEngine to be emitted.
Definition: Sema.cpp:1592
const LangOptions & LangOpts
Definition: Sema.h:960
bool DeferDiags
Whether deferrable diagnostics should be deferred.
Definition: Sema.h:9780
DiagnosticsEngine & Diags
Definition: Sema.h:964
Encodes a location in the source.
The JSON file list parser is used to communicate input to InstallAPI.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.