Skip to content

Commit 4b0fa40

Browse files
jmmartinezLukacma
authored andcommitted
[NFC][Clang][Diagnostics] Remove the DeferHint parameter of Diags(...) in favour of DeferHintRAII (llvm#161517)
The `DeferHint` was misused at several callsites, where a `Decl*` was implicitly casted to `bool`. This patch proposes removing the `DeferHint` parameter and relying on `DeferDiagsRAII` to set if Clang should defer the diagnostics.
1 parent 4137682 commit 4b0fa40

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10021,7 +10021,7 @@ class Sema final : public SemaBase {
1002110021
public:
1002210022
DeferDiagsRAII(Sema &S, bool DeferDiags)
1002310023
: S(S), SavedDeferDiags(S.DeferDiags) {
10024-
S.DeferDiags = DeferDiags;
10024+
S.DeferDiags = SavedDeferDiags || DeferDiags;
1002510025
}
1002610026
~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; }
1002710027
};

clang/include/clang/Sema/SemaBase.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,13 @@ class SemaBase {
212212
};
213213

214214
/// Emit a diagnostic.
215-
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID,
216-
bool DeferHint = false);
215+
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
217216

218217
/// Emit a partial diagnostic.
219-
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
220-
bool DeferHint = false);
218+
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD);
221219

222220
/// Emit a compatibility diagnostic.
223-
SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId,
224-
bool DeferHint = false);
221+
SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId);
225222

226223
/// Build a partial diagnostic.
227224
PartialDiagnostic PDiag(unsigned DiagID = 0);

clang/lib/Sema/Sema.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,9 +2214,9 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
22142214
else
22152215
PD << "expression";
22162216

2217-
if (Diag(Loc, PD, FD)
2218-
<< false /*show bit size*/ << 0 << Ty << false /*return*/
2219-
<< TI.getTriple().str()) {
2217+
if (Diag(Loc, PD) << false /*show bit size*/ << 0 << Ty
2218+
<< false /*return*/
2219+
<< TI.getTriple().str()) {
22202220
if (D)
22212221
D->setInvalidDecl();
22222222
}
@@ -2233,9 +2233,8 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
22332233
else
22342234
PD << "expression";
22352235

2236-
if (Diag(Loc, PD, FD)
2237-
<< false /*show bit size*/ << 0 << Ty << true /*return*/
2238-
<< TI.getTriple().str()) {
2236+
if (Diag(Loc, PD) << false /*show bit size*/ << 0 << Ty << true /*return*/
2237+
<< TI.getTriple().str()) {
22392238
if (D)
22402239
D->setInvalidDecl();
22412240
}

clang/lib/Sema/SemaBase.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ SemaBase::SemaDiagnosticBuilder::getDeviceDeferredDiags() const {
5858
return S.DeviceDeferredDiags;
5959
}
6060

61-
Sema::SemaDiagnosticBuilder SemaBase::Diag(SourceLocation Loc, unsigned DiagID,
62-
bool DeferHint) {
61+
Sema::SemaDiagnosticBuilder SemaBase::Diag(SourceLocation Loc,
62+
unsigned DiagID) {
6363
bool IsError =
6464
getDiagnostics().getDiagnosticIDs()->isDefaultMappingAsError(DiagID);
6565
bool ShouldDefer = getLangOpts().CUDA && getLangOpts().GPUDeferDiag &&
6666
DiagnosticIDs::isDeferrable(DiagID) &&
67-
(DeferHint || SemaRef.DeferDiags || !IsError);
67+
(SemaRef.DeferDiags || !IsError);
6868
auto SetIsLastErrorImmediate = [&](bool Flag) {
6969
if (IsError)
7070
SemaRef.IsLastErrorImmediate = Flag;
@@ -83,16 +83,13 @@ Sema::SemaDiagnosticBuilder SemaBase::Diag(SourceLocation Loc, unsigned DiagID,
8383
}
8484

8585
Sema::SemaDiagnosticBuilder SemaBase::Diag(SourceLocation Loc,
86-
const PartialDiagnostic &PD,
87-
bool DeferHint) {
88-
return Diag(Loc, PD.getDiagID(), DeferHint) << PD;
86+
const PartialDiagnostic &PD) {
87+
return Diag(Loc, PD.getDiagID()) << PD;
8988
}
9089

9190
SemaBase::SemaDiagnosticBuilder SemaBase::DiagCompat(SourceLocation Loc,
92-
unsigned CompatDiagId,
93-
bool DeferHint) {
91+
unsigned CompatDiagId) {
9492
return Diag(Loc,
95-
DiagnosticIDs::getCXXCompatDiagId(getLangOpts(), CompatDiagId),
96-
DeferHint);
93+
DiagnosticIDs::getCXXCompatDiagId(getLangOpts(), CompatDiagId));
9794
}
9895
} // namespace clang

clang/lib/Sema/SemaOverload.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13208,7 +13208,10 @@ void OverloadCandidateSet::NoteCandidates(
1320813208

1320913209
auto Cands = CompleteCandidates(S, OCD, Args, OpLoc, Filter);
1321013210

13211-
S.Diag(PD.first, PD.second, shouldDeferDiags(S, Args, OpLoc));
13211+
{
13212+
Sema::DeferDiagsRAII RAII{S, shouldDeferDiags(S, Args, OpLoc)};
13213+
S.Diag(PD.first, PD.second);
13214+
}
1321213215

1321313216
// In WebAssembly we don't want to emit further diagnostics if a table is
1321413217
// passed as an argument to a function.
@@ -13271,10 +13274,10 @@ void OverloadCandidateSet::NoteCandidates(Sema &S, ArrayRef<Expr *> Args,
1327113274
// inform the future value of S.Diags.getNumOverloadCandidatesToShow().
1327213275
S.Diags.overloadCandidatesShown(CandsShown);
1327313276

13274-
if (I != E)
13275-
S.Diag(OpLoc, diag::note_ovl_too_many_candidates,
13276-
shouldDeferDiags(S, Args, OpLoc))
13277-
<< int(E - I);
13277+
if (I != E) {
13278+
Sema::DeferDiagsRAII RAII{S, shouldDeferDiags(S, Args, OpLoc)};
13279+
S.Diag(OpLoc, diag::note_ovl_too_many_candidates) << int(E - I);
13280+
}
1327813281
}
1327913282

1328013283
static SourceLocation

clang/lib/Sema/SemaRISCV.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,40 +1445,40 @@ void SemaRISCV::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
14451445

14461446
if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Double) &&
14471447
!FeatureMap.lookup("zve64d"))
1448-
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64d";
1448+
Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zve64d";
14491449
// (ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1) requires at
14501450
// least zve64x
14511451
else if (((EltSize == 64 && Info.ElementType->isIntegerType()) ||
14521452
MinElts == 1) &&
14531453
!FeatureMap.lookup("zve64x"))
1454-
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
1454+
Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zve64x";
14551455
else if (Info.ElementType->isFloat16Type() && !FeatureMap.lookup("zvfh") &&
14561456
!FeatureMap.lookup("zvfhmin") &&
14571457
!FeatureMap.lookup("xandesvpackfph"))
14581458
if (DeclareAndesVectorBuiltins) {
1459-
Diag(Loc, diag::err_riscv_type_requires_extension, D)
1459+
Diag(Loc, diag::err_riscv_type_requires_extension)
14601460
<< Ty << "zvfh, zvfhmin or xandesvpackfph";
14611461
} else {
1462-
Diag(Loc, diag::err_riscv_type_requires_extension, D)
1462+
Diag(Loc, diag::err_riscv_type_requires_extension)
14631463
<< Ty << "zvfh or zvfhmin";
14641464
}
14651465
else if (Info.ElementType->isBFloat16Type() &&
14661466
!FeatureMap.lookup("zvfbfmin") &&
14671467
!FeatureMap.lookup("xandesvbfhcvt") &&
14681468
!FeatureMap.lookup("experimental-zvfbfa"))
14691469
if (DeclareAndesVectorBuiltins) {
1470-
Diag(Loc, diag::err_riscv_type_requires_extension, D)
1470+
Diag(Loc, diag::err_riscv_type_requires_extension)
14711471
<< Ty << "zvfbfmin or xandesvbfhcvt";
14721472
} else {
1473-
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zvfbfmin";
1473+
Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zvfbfmin";
14741474
}
14751475
else if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Float) &&
14761476
!FeatureMap.lookup("zve32f"))
1477-
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve32f";
1477+
Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zve32f";
14781478
// Given that caller already checked isRVVType() before calling this function,
14791479
// if we don't have at least zve32x supported, then we need to emit error.
14801480
else if (!FeatureMap.lookup("zve32x"))
1481-
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve32x";
1481+
Diag(Loc, diag::err_riscv_type_requires_extension) << Ty << "zve32x";
14821482
}
14831483

14841484
/// Are the two types RVV-bitcast-compatible types? I.e. is bitcasting from the

0 commit comments

Comments
 (0)