clang 22.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
13
15 // If we aren't active, there is nothing to do.
16 if (!isActive())
17 return;
18
19 // Otherwise, we need to emit the diagnostic. First clear the diagnostic
20 // builder itself so it won't emit the diagnostic in its own destructor.
21 //
22 // This seems wasteful, in that as written the DiagnosticBuilder dtor will
23 // do its own needless checks to see if the diagnostic needs to be
24 // emitted. However, because we take care to ensure that the builder
25 // objects never escape, a sufficiently smart compiler will be able to
26 // eliminate that code.
27 Clear();
28
29 // Dispatch to Sema to emit the diagnostic.
30 SemaRef.EmitDiagnostic(DiagID, *this);
31}
32
35}
36
39 const PartialDiagnostic &PD) {
40 if (Diag.ImmediateDiag)
41 PD.Emit(*Diag.ImmediateDiag);
42 else if (Diag.PartialDiagId)
43 Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD;
44 return Diag;
45}
46
48 const FixItHint &Hint) const {
49 if (ImmediateDiag)
50 ImmediateDiag->AddFixItHint(Hint);
51 else if (PartialDiagId)
52 S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint);
53}
54
55llvm::DenseMap<CanonicalDeclPtr<const FunctionDecl>,
56 std::vector<PartialDiagnosticAt>> &
57SemaBase::SemaDiagnosticBuilder::getDeviceDeferredDiags() const {
58 return S.DeviceDeferredDiags;
59}
60
62 bool DeferHint) {
63 bool IsError =
64 getDiagnostics().getDiagnosticIDs()->isDefaultMappingAsError(DiagID);
65 bool ShouldDefer = getLangOpts().CUDA && getLangOpts().GPUDeferDiag &&
67 (DeferHint || SemaRef.DeferDiags || !IsError);
68 auto SetIsLastErrorImmediate = [&](bool Flag) {
69 if (IsError)
71 };
72 if (!ShouldDefer) {
73 SetIsLastErrorImmediate(true);
76 }
77
78 SemaDiagnosticBuilder DB = getLangOpts().CUDAIsDevice
79 ? SemaRef.CUDA().DiagIfDeviceCode(Loc, DiagID)
80 : SemaRef.CUDA().DiagIfHostCode(Loc, DiagID);
81 SetIsLastErrorImmediate(DB.isImmediate());
82 return DB;
83}
84
86 const PartialDiagnostic &PD,
87 bool DeferHint) {
88 return Diag(Loc, PD.getDiagID(), DeferHint) << PD;
89}
90
92 unsigned CompatDiagId,
93 bool DeferHint) {
94 return Diag(Loc,
96 DeferHint);
97}
98} // namespace clang
This file declares semantic analysis for CUDA constructs.
SourceLocation Loc
Definition: SemaObjC.cpp:754
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
PartialDiagnostic::DiagStorageAllocator & getDiagAllocator()
Definition: ASTContext.h:855
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1449
void Clear() const
Clear out the current diagnostic.
Definition: Diagnostic.h:1271
bool isActive() const
Determine whether this diagnostic is still active.
Definition: Diagnostic.h:1278
static unsigned getCXXCompatDiagId(const LangOptions &LangOpts, unsigned CompatDiagId)
Get the appropriate diagnostic Id to use for issuing a compatibility diagnostic.
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:231
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Definition: Diagnostic.h:591
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:78
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
void Emit(const DiagnosticBuilder &DB) const
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
void AddFixItHint(const FixItHint &Hint) const
Definition: SemaBase.cpp:47
SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId, bool DeferHint=false)
Emit a compatibility diagnostic.
Definition: SemaBase.cpp:91
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:61
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaBase.cpp:33
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
DeclContext * getCurContext() const
Definition: SemaBase.cpp:12
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:868
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:836
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:850
bool IsLastErrorImmediate
Is the last error level diagnostic immediate.
Definition: Sema.h:1339
SemaCUDA & CUDA()
Definition: Sema.h:1438
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:1647
ASTContext & Context
Definition: Sema.h:1276
SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags
Diagnostics that are emitted only if we discover that the given function must be codegen'ed.
Definition: Sema.h:1408
const LangOptions & LangOpts
Definition: Sema.h:1274
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:1411
bool DeferDiags
Whether deferrable diagnostics should be deferred.
Definition: Sema.h:9985
DiagnosticsEngine & Diags
Definition: Sema.h:1278
void EmitDiagnostic(unsigned DiagID, const DiagnosticBuilder &DB)
Cause the built diagnostic to be emitted on the DiagosticsEngine.
Definition: Sema.cpp:1672
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.