clang 19.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 const PartialDiagnostic &PD) {
35 if (Diag.ImmediateDiag)
36 PD.Emit(*Diag.ImmediateDiag);
37 else if (Diag.PartialDiagId)
38 Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD;
39 return Diag;
40}
41
43 const FixItHint &Hint) const {
44 if (ImmediateDiag)
45 ImmediateDiag->AddFixItHint(Hint);
46 else if (PartialDiagId)
47 S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint);
48}
49
50llvm::DenseMap<CanonicalDeclPtr<const FunctionDecl>,
51 std::vector<PartialDiagnosticAt>> &
52SemaBase::SemaDiagnosticBuilder::getDeviceDeferredDiags() const {
53 return S.DeviceDeferredDiags;
54}
55
57 bool DeferHint) {
58 bool IsError =
59 getDiagnostics().getDiagnosticIDs()->isDefaultMappingAsError(DiagID);
60 bool ShouldDefer = getLangOpts().CUDA && getLangOpts().GPUDeferDiag &&
62 (DeferHint || SemaRef.DeferDiags || !IsError);
63 auto SetIsLastErrorImmediate = [&](bool Flag) {
64 if (IsError)
66 };
67 if (!ShouldDefer) {
68 SetIsLastErrorImmediate(true);
71 }
72
73 SemaDiagnosticBuilder DB = getLangOpts().CUDAIsDevice
74 ? SemaRef.CUDA().DiagIfDeviceCode(Loc, DiagID)
75 : SemaRef.CUDA().DiagIfHostCode(Loc, DiagID);
76 SetIsLastErrorImmediate(DB.isImmediate());
77 return DB;
78}
79
81 const PartialDiagnostic &PD,
82 bool DeferHint) {
83 return Diag(Loc, PD.getDiagID(), DeferHint) << PD;
84}
85
86} // namespace clang
This file declares semantic analysis for CUDA constructs.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
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:461
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:42
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:56
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:457
bool IsLastErrorImmediate
Is the last error level diagnostic immediate.
Definition: Sema.h:924
SemaCUDA & CUDA()
Definition: Sema.h:998
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:1499
ASTContext & Context
Definition: Sema.h:858
SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags
Diagnostics that are emitted only if we discover that the given function must be codegen'ed.
Definition: Sema.h:993
void EmitCurrentDiagnostic(unsigned DiagID)
Cause the active diagnostic on the DiagosticsEngine to be emitted.
Definition: Sema.cpp:1524
const LangOptions & LangOpts
Definition: Sema.h:856
bool DeferDiags
Whether deferrable diagnostics should be deferred.
Definition: Sema.h:7902
DiagnosticsEngine & Diags
Definition: Sema.h:860
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.