clang 19.0.0git
Go to the documentation of this file.
2#include "clang/Sema/Sema.h"
5namespace clang {
7SemaBase::SemaBase(Sema &S) : SemaRef(S) {}
14 // If we aren't active, there is nothing to do.
15 if (!isActive())
16 return;
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();
28 // Dispatch to Sema to emit the diagnostic.
29 SemaRef.EmitCurrentDiagnostic(DiagID);
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;
43 const FixItHint &Hint) const {
44 if (ImmediateDiag)
45 ImmediateDiag->AddFixItHint(Hint);
46 else if (PartialDiagId)
47 S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint);
50llvm::DenseMap<CanonicalDeclPtr<const FunctionDecl>,
51 std::vector<PartialDiagnosticAt>> &
52SemaBase::SemaDiagnosticBuilder::getDeviceDeferredDiags() const {
53 return S.DeviceDeferredDiags;
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 }
73 SemaDiagnosticBuilder DB = getLangOpts().CUDAIsDevice
74 ? SemaRef.CUDA().DiagIfDeviceCode(Loc, DiagID)
75 : SemaRef.CUDA().DiagIfHostCode(Loc, DiagID);
76 SetIsLastErrorImmediate(DB.isImmediate());
77 return DB;
81 const PartialDiagnostic &PD,
82 bool DeferHint) {
83 return Diag(Loc, PD.getDiagID(), DeferHint) << PD;
86} // namespace clang
This file declares semantic analysis for CUDA constructs.
SourceLocation Loc
Definition: SemaObjC.cpp:755
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
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:461
bool IsLastErrorImmediate
Is the last error level diagnostic immediate.
Definition: Sema.h:922
Definition: Sema.h:1001
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:1505
ASTContext & Context
Definition: Sema.h:856
SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags
Diagnostics that are emitted only if we discover that the given function must be codegen'ed.
Definition: Sema.h:991
void EmitCurrentDiagnostic(unsigned DiagID)
Cause the active diagnostic on the DiagosticsEngine to be emitted.
Definition: Sema.cpp:1530
const LangOptions & LangOpts
Definition: Sema.h:854
bool DeferDiags
Whether deferrable diagnostics should be deferred.
Definition: Sema.h:7852
DiagnosticsEngine & Diags
Definition: Sema.h:858
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.