[clang] [NFC][Clang][Diagnostics] Remove the DeferHint parameter of Diags(...) in favour of DeferHintRAII (PR #161517)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 1 06:18:45 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Juan Manuel Martinez CaamaƱo (jmmartinez)
<details>
<summary>Changes</summary>
The `DeferHint` was misused at several callsites, where a `Decl*` was implicitly casted to `bool`.
---
Full diff: https://github.com/llvm/llvm-project/pull/161517.diff
6 Files Affected:
- (modified) clang/include/clang/Sema/Sema.h (+1-1)
- (modified) clang/include/clang/Sema/SemaBase.h (+3-6)
- (modified) clang/lib/Sema/Sema.cpp (+6-7)
- (modified) clang/lib/Sema/SemaBase.cpp (+7-10)
- (modified) clang/lib/Sema/SemaOverload.cpp (+8-5)
- (modified) clang/lib/Sema/SemaRISCV.cpp (+8-8)
``````````diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f53aafdeb4f36..3a902caa63fda 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10005,7 +10005,7 @@ class Sema final : public SemaBase {
public:
DeferDiagsRAII(Sema &S, bool DeferDiags)
: S(S), SavedDeferDiags(S.DeferDiags) {
- S.DeferDiags = DeferDiags;
+ S.DeferDiags = SavedDeferDiags || DeferDiags;
}
~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; }
};
diff --git a/clang/include/clang/Sema/SemaBase.h b/clang/include/clang/Sema/SemaBase.h
index 550f530af72f5..8e43b0b1ae7ff 100644
--- a/clang/include/clang/Sema/SemaBase.h
+++ b/clang/include/clang/Sema/SemaBase.h
@@ -212,16 +212,13 @@ class SemaBase {
};
/// Emit a diagnostic.
- SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID,
- bool DeferHint = false);
+ SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
/// Emit a partial diagnostic.
- SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
- bool DeferHint = false);
+ SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD);
/// Emit a compatibility diagnostic.
- SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId,
- bool DeferHint = false);
+ SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId);
/// Build a partial diagnostic.
PartialDiagnostic PDiag(unsigned DiagID = 0);
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 39fa25f66f3b7..882ad2dce3689 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2214,9 +2214,9 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
else
PD << "expression";
- if (Diag(Loc, PD, FD)
- << false /*show bit size*/ << 0 << Ty << false /*return*/
- << TI.getTriple().str()) {
+ if (Diag(Loc, PD) << false /*show bit size*/ << 0 << Ty
+ << false /*return*/
+ << TI.getTriple().str()) {
if (D)
D->setInvalidDecl();
}
@@ -2233,14 +2233,13 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
else
PD << "expression";
- if (Diag(Loc, PD, FD)
- << false /*show bit size*/ << 0 << Ty << true /*return*/
- << TI.getTriple().str()) {
+ if (Diag(Loc, PD) << false /*show bit size*/ << 0 << Ty << true /*return*/
+ << TI.getTriple().str()) {
if (D)
D->setInvalidDecl();
}
if (D)
- targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
+ targetDiag(D->getLocation(), diag::note_defined_here) << D;
}
if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType() && FD) {
diff --git a/clang/lib/Sema/SemaBase.cpp b/clang/lib/Sema/SemaBase.cpp
index 9b677f446f3e6..bf32491be31ba 100644
--- a/clang/lib/Sema/SemaBase.cpp
+++ b/clang/lib/Sema/SemaBase.cpp
@@ -58,13 +58,13 @@ SemaBase::SemaDiagnosticBuilder::getDeviceDeferredDiags() const {
return S.DeviceDeferredDiags;
}
-Sema::SemaDiagnosticBuilder SemaBase::Diag(SourceLocation Loc, unsigned DiagID,
- bool DeferHint) {
+Sema::SemaDiagnosticBuilder SemaBase::Diag(SourceLocation Loc,
+ unsigned DiagID) {
bool IsError =
getDiagnostics().getDiagnosticIDs()->isDefaultMappingAsError(DiagID);
bool ShouldDefer = getLangOpts().CUDA && getLangOpts().GPUDeferDiag &&
DiagnosticIDs::isDeferrable(DiagID) &&
- (DeferHint || SemaRef.DeferDiags || !IsError);
+ (SemaRef.DeferDiags || !IsError);
auto SetIsLastErrorImmediate = [&](bool Flag) {
if (IsError)
SemaRef.IsLastErrorImmediate = Flag;
@@ -83,16 +83,13 @@ Sema::SemaDiagnosticBuilder SemaBase::Diag(SourceLocation Loc, unsigned DiagID,
}
Sema::SemaDiagnosticBuilder SemaBase::Diag(SourceLocation Loc,
- const PartialDiagnostic &PD,
- bool DeferHint) {
- return Diag(Loc, PD.getDiagID(), DeferHint) << PD;
+ const PartialDiagnostic &PD) {
+ return Diag(Loc, PD.getDiagID()) << PD;
}
SemaBase::SemaDiagnosticBuilder SemaBase::DiagCompat(SourceLocation Loc,
- unsigned CompatDiagId,
- bool DeferHint) {
+ unsigned CompatDiagId) {
return Diag(Loc,
- DiagnosticIDs::getCXXCompatDiagId(getLangOpts(), CompatDiagId),
- DeferHint);
+ DiagnosticIDs::getCXXCompatDiagId(getLangOpts(), CompatDiagId));
}
} // namespace clang
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ea5c4265d736d..be1ffc9c8205c 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13221,7 +13221,10 @@ void OverloadCandidateSet::NoteCandidates(
auto Cands = CompleteCandidates(S, OCD, Args, OpLoc, Filter);
- S.Diag(PD.first, PD.second, shouldDeferDiags(S, Args, OpLoc));
+ {
+ Sema::DeferDiagsRAII RAII{S, shouldDeferDiags(S, Args, OpLoc)};
+ S.Diag(PD.first, PD.second);
+ }
// In WebAssembly we don't want to emit further diagnostics if a table is
// passed as an argument to a function.
@@ -13284,10 +13287,10 @@ void OverloadCandidateSet::NoteCandidates(Sema &S, ArrayRef<Expr *> Args,
// inform the future value of S.Diags.getNumOverloadCandidatesToShow().
S.Diags.overloadCandidatesShown(CandsShown);
- if (I != E)
- S.Diag(OpLoc, diag::note_ovl_too_many_candidates,
- shouldDeferDiags(S, Args, OpLoc))
- << int(E - I);
+ if (I != E) {
+ Sema::DeferDiagsRAII RAII{S, shouldDeferDiags(S, Args, OpLoc)};
+ S.Diag(OpLoc, diag::note_ovl_too_many_candidates) << int(E - I);
+ }
}
static SourceLocation
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index 3ba93ff98898b..465e14aeab59d 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -1445,39 +1445,39 @@ void SemaRISCV::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Double) &&
!FeatureMap.lookup("zve64d"))
- Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64d";
+ Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zve64d";
// (ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1) requires at
// least zve64x
else if (((EltSize == 64 && Info.ElementType->isIntegerType()) ||
MinElts == 1) &&
!FeatureMap.lookup("zve64x"))
- Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
+ Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zve64x";
else if (Info.ElementType->isFloat16Type() && !FeatureMap.lookup("zvfh") &&
!FeatureMap.lookup("zvfhmin") &&
!FeatureMap.lookup("xandesvpackfph"))
if (DeclareAndesVectorBuiltins) {
- Diag(Loc, diag::err_riscv_type_requires_extension, D)
+ Diag(Loc, diag::err_riscv_type_requires_extension)
<< Ty << "zvfh, zvfhmin or xandesvpackfph";
} else {
- Diag(Loc, diag::err_riscv_type_requires_extension, D)
+ Diag(Loc, diag::err_riscv_type_requires_extension)
<< Ty << "zvfh or zvfhmin";
}
else if (Info.ElementType->isBFloat16Type() &&
!FeatureMap.lookup("zvfbfmin") &&
!FeatureMap.lookup("xandesvbfhcvt"))
if (DeclareAndesVectorBuiltins) {
- Diag(Loc, diag::err_riscv_type_requires_extension, D)
+ Diag(Loc, diag::err_riscv_type_requires_extension)
<< Ty << "zvfbfmin or xandesvbfhcvt";
} else {
- Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zvfbfmin";
+ Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zvfbfmin";
}
else if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Float) &&
!FeatureMap.lookup("zve32f"))
- Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve32f";
+ Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zve32f";
// Given that caller already checked isRVVType() before calling this function,
// if we don't have at least zve32x supported, then we need to emit error.
else if (!FeatureMap.lookup("zve32x"))
- Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve32x";
+ Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zve32x";
}
/// Are the two types RVV-bitcast-compatible types? I.e. is bitcasting from the
``````````
</details>
https://github.com/llvm/llvm-project/pull/161517
More information about the cfe-commits
mailing list