Skip to content

Commit 80887c7

Browse files
authored
[clang][NFC][diagnostics] Remove most usage of getCustomDiagID() from CodeGen (#172557)
1 parent 42b3483 commit 80887c7

14 files changed

+115
-92
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,69 @@ def warn_hlsl_langstd_minimal :
403403
"recommend using %1 instead">,
404404
InGroup<HLSLDXCCompat>;
405405

406+
def err_data_layout_mismatch : Error<"backend data layout '%0' does not match "
407+
"expected target description '%1'">;
408+
def err_failed_to_open_for_embedding
409+
: Error<"could not open '%0' for embedding">;
410+
def err_unsupported_cxx_abi_feature
411+
: Error<"cannot yet compile %0 in this ABI">;
412+
413+
def err_target_region_offloading_entry_incorrect
414+
: Error<"offloading entry for target region in %0 is incorrect: either the "
415+
"address or the ID is invalid">;
416+
def err_target_var_offloading_entry_incorrect_with_parent
417+
: Error<"offloading entry for declare target variable %0 is incorrect: the "
418+
"address is invalid">;
419+
def err_target_var_offloading_entry_incorrect
420+
: Error<"offloading entry for declare target variable is incorrect: the "
421+
"address is invalid">;
422+
423+
def err_missing_mandatory_offloading
424+
: Error<"no offloading entry generated while offloading is mandatory">;
425+
426+
def err_reading_profile : Error<"error in reading profile %0: %1">;
427+
def err_open_hotpatch_file_failed
428+
: Error<"failed to open hotpatch functions file "
429+
"(-fms-hotpatch-functions-file): %0 : %1">;
430+
431+
def err_codegen_unsupported : Error<"cannot compile this %0 yet">;
432+
433+
def warn_trivial_auto_var_limit
434+
: Warning<"-ftrivial-auto-var-init-stop-after=%0 has been enabled to limit "
435+
"the number of times ftrivial-auto-var-init=%1 gets applied">,
436+
InGroup<TrivialAutoVarInit>;
437+
438+
def warn_simdlen_1_no_effect
439+
: Warning<"the clause simdlen(1) has no effect when targeting aarch64">,
440+
InGroup<SIMDLen>;
441+
def warn_simdlen_requires_power_of_2
442+
: Warning<"the value specified in simdlen must be a power of 2 when "
443+
"targeting Advanced SIMD">,
444+
InGroup<SIMDLen>;
445+
def warn_simdlen_must_fit_lanes
446+
: Warning<"the clause simdlen must fit the %0-bit lanes in the "
447+
"architectural constraints for SVE (min is 128-bit, max is "
448+
"2048-bit, by steps of 128-bit)">,
449+
InGroup<SIMDLen>;
450+
451+
def warn_pgo_nested_boolean_expr
452+
: Warning<
453+
"unsupported MC/DC boolean expression; contains an operation with a "
454+
"nested boolean expression. Expression will not be covered">,
455+
InGroup<PGOCoverage>;
456+
def warn_pgo_condition_limit
457+
: Warning<"unsupported MC/DC boolean expression; number of conditions (%0) "
458+
"exceeds max (%1). Expression will not be covered">,
459+
InGroup<PGOCoverage>;
460+
def warn_pgo_test_vector_limit
461+
: Warning<"unsupported MC/DC boolean expression; number of test vectors "
462+
"(%0) exceeds max (%1). Expression will not be covered">,
463+
InGroup<PGOCoverage>;
464+
465+
def err_member_ptr_requires_complete_type
466+
: Error<"member pointer representation requires a complete class type for "
467+
"%0 to perform this expression">;
468+
406469
// ClangIR frontend errors
407470
def err_cir_to_cir_transform_failed : Error<
408471
"CIR-to-CIR transformation failed">, DefaultFatal;

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,5 +1789,14 @@ def ExtractAPIMisuse : DiagGroup<"extractapi-misuse">;
17891789
// with a storage class specifier.
17901790
def ExplicitSpecializationStorageClass : DiagGroup<"explicit-specialization-storage-class">;
17911791

1792+
// Warnings related to the simdlen intrinsic
1793+
def SIMDLen : DiagGroup<"simdlen">;
1794+
1795+
// Warnings related to PGO coverage limitations
1796+
def PGOCoverage : DiagGroup<"pgo-coverage">;
1797+
1798+
// Warnings related to -ftrivial-auto-var-init
1799+
def TrivialAutoVarInit : DiagGroup<"trivial-auto-var-init">;
1800+
17921801
// A warning for options that enable a feature that is not yet complete
17931802
def ExperimentalOption : DiagGroup<"experimental-option">;

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,10 +1511,7 @@ void clang::emitBackendOutput(CompilerInstance &CI, CodeGenOptions &CGOpts,
15111511
if (AsmHelper.TM) {
15121512
std::string DLDesc = M->getDataLayout().getStringRepresentation();
15131513
if (DLDesc != TDesc) {
1514-
unsigned DiagID = Diags.getCustomDiagID(
1515-
DiagnosticsEngine::Error, "backend data layout '%0' does not match "
1516-
"expected target description '%1'");
1517-
Diags.Report(DiagID) << DLDesc << TDesc;
1514+
Diags.Report(diag::err_data_layout_mismatch) << DLDesc << TDesc;
15181515
}
15191516
}
15201517
}
@@ -1540,9 +1537,7 @@ void clang::EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
15401537
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
15411538
VFS.getBufferForFile(OffloadObject);
15421539
if (ObjectOrErr.getError()) {
1543-
auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
1544-
"could not open '%0' for embedding");
1545-
Diags.Report(DiagID) << OffloadObject;
1540+
Diags.Report(diag::err_failed_to_open_for_embedding) << OffloadObject;
15461541
return;
15471542
}
15481543

clang/lib/CodeGen/CGCXXABI.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "CGCXXABI.h"
1515
#include "CGCleanup.h"
1616
#include "clang/AST/Attr.h"
17+
#include "clang/Basic/DiagnosticFrontend.h"
1718

1819
using namespace clang;
1920
using namespace CodeGen;
@@ -28,11 +29,9 @@ Address CGCXXABI::getThisAddress(CodeGenFunction &CGF) {
2829

2930
void CGCXXABI::ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S) {
3031
DiagnosticsEngine &Diags = CGF.CGM.getDiags();
31-
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
32-
"cannot yet compile %0 in this ABI");
3332
Diags.Report(CGF.getContext().getFullLoc(CGF.CurCodeDecl->getLocation()),
34-
DiagID)
35-
<< S;
33+
diag::err_unsupported_cxx_abi_feature)
34+
<< S;
3635
}
3736

3837
llvm::Constant *CGCXXABI::GetBogusMemberPointer(QualType T) {

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "clang/AST/OpenMPClause.h"
2525
#include "clang/AST/StmtOpenMP.h"
2626
#include "clang/AST/StmtVisitor.h"
27+
#include "clang/Basic/DiagnosticFrontend.h"
2728
#include "clang/Basic/OpenMPKinds.h"
2829
#include "clang/Basic/SourceManager.h"
2930
#include "clang/CodeGen/ConstantInitBuilder.h"
@@ -2832,25 +2833,17 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
28322833
}
28332834
switch (Kind) {
28342835
case llvm::OpenMPIRBuilder::EMIT_MD_TARGET_REGION_ERROR: {
2835-
unsigned DiagID = CGM.getDiags().getCustomDiagID(
2836-
DiagnosticsEngine::Error, "Offloading entry for target region in "
2837-
"%0 is incorrect: either the "
2838-
"address or the ID is invalid.");
2839-
CGM.getDiags().Report(Loc, DiagID) << EntryInfo.ParentName;
2836+
CGM.getDiags().Report(Loc,
2837+
diag::err_target_region_offloading_entry_incorrect)
2838+
<< EntryInfo.ParentName;
28402839
} break;
28412840
case llvm::OpenMPIRBuilder::EMIT_MD_DECLARE_TARGET_ERROR: {
2842-
unsigned DiagID = CGM.getDiags().getCustomDiagID(
2843-
DiagnosticsEngine::Error, "Offloading entry for declare target "
2844-
"variable %0 is incorrect: the "
2845-
"address is invalid.");
2846-
CGM.getDiags().Report(Loc, DiagID) << EntryInfo.ParentName;
2841+
CGM.getDiags().Report(
2842+
Loc, diag::err_target_var_offloading_entry_incorrect_with_parent)
2843+
<< EntryInfo.ParentName;
28472844
} break;
28482845
case llvm::OpenMPIRBuilder::EMIT_MD_GLOBAL_VAR_LINK_ERROR: {
2849-
unsigned DiagID = CGM.getDiags().getCustomDiagID(
2850-
DiagnosticsEngine::Error,
2851-
"Offloading entry for declare target variable is incorrect: the "
2852-
"address is invalid.");
2853-
CGM.getDiags().Report(DiagID);
2846+
CGM.getDiags().Report(diag::err_target_var_offloading_entry_incorrect);
28542847
} break;
28552848
}
28562849
};
@@ -11988,33 +11981,22 @@ static void emitAArch64DeclareSimdFunction(
1198811981
// Check the values provided via `simdlen` by the user.
1198911982
// 1. A `simdlen(1)` doesn't produce vector signatures,
1199011983
if (UserVLEN == 1) {
11991-
unsigned DiagID = CGM.getDiags().getCustomDiagID(
11992-
DiagnosticsEngine::Warning,
11993-
"The clause simdlen(1) has no effect when targeting aarch64.");
11994-
CGM.getDiags().Report(SLoc, DiagID);
11984+
CGM.getDiags().Report(SLoc, diag::warn_simdlen_1_no_effect);
1199511985
return;
1199611986
}
1199711987

1199811988
// 2. Section 3.3.1, item 1: user input must be a power of 2 for
1199911989
// Advanced SIMD output.
1200011990
if (ISA == 'n' && UserVLEN && !llvm::isPowerOf2_32(UserVLEN)) {
12001-
unsigned DiagID = CGM.getDiags().getCustomDiagID(
12002-
DiagnosticsEngine::Warning, "The value specified in simdlen must be a "
12003-
"power of 2 when targeting Advanced SIMD.");
12004-
CGM.getDiags().Report(SLoc, DiagID);
11991+
CGM.getDiags().Report(SLoc, diag::warn_simdlen_requires_power_of_2);
1200511992
return;
1200611993
}
1200711994

1200811995
// 3. Section 3.4.1. SVE fixed lengh must obey the architectural
1200911996
// limits.
1201011997
if (ISA == 's' && UserVLEN != 0) {
1201111998
if ((UserVLEN * WDS > 2048) || (UserVLEN * WDS % 128 != 0)) {
12012-
unsigned DiagID = CGM.getDiags().getCustomDiagID(
12013-
DiagnosticsEngine::Warning, "The clause simdlen must fit the %0-bit "
12014-
"lanes in the architectural constraints "
12015-
"for SVE (min is 128-bit, max is "
12016-
"2048-bit, by steps of 128-bit)");
12017-
CGM.getDiags().Report(SLoc, DiagID) << WDS;
11999+
CGM.getDiags().Report(SLoc, diag::warn_simdlen_must_fit_lanes) << WDS;
1201812000
return;
1201912001
}
1202012002
}

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "clang/AST/Stmt.h"
2525
#include "clang/AST/StmtOpenMP.h"
2626
#include "clang/AST/StmtVisitor.h"
27+
#include "clang/Basic/DiagnosticFrontend.h"
2728
#include "clang/Basic/OpenMPKinds.h"
2829
#include "clang/Basic/PrettyStackTrace.h"
2930
#include "clang/Basic/SourceManager.h"
@@ -6989,10 +6990,7 @@ static void emitCommonOMPTargetDirective(CodeGenFunction &CGF,
69896990
IsOffloadEntry = false;
69906991

69916992
if (CGM.getLangOpts().OpenMPOffloadMandatory && !IsOffloadEntry) {
6992-
unsigned DiagID = CGM.getDiags().getCustomDiagID(
6993-
DiagnosticsEngine::Error,
6994-
"No offloading entry generated while offloading is mandatory.");
6995-
CGM.getDiags().Report(DiagID);
6993+
CGM.getDiags().Report(diag::err_missing_mandatory_offloading);
69966994
}
69976995

69986996
assert(CGF.CurFuncDecl && "No parent declaration for target region!");

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,8 @@ CodeGenModule::CodeGenModule(ASTContext &C,
490490
CodeGenOpts.ProfileInstrumentUsePath, *FS,
491491
CodeGenOpts.ProfileRemappingFile);
492492
if (auto E = ReaderOrErr.takeError()) {
493-
unsigned DiagID = Diags.getCustomDiagID(
494-
DiagnosticsEngine::Error, "Error in reading profile %0: %1");
495493
llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EI) {
496-
Diags.Report(DiagID)
494+
Diags.Report(diag::err_reading_profile)
497495
<< CodeGenOpts.ProfileInstrumentUsePath << EI.message();
498496
});
499497
return;
@@ -537,12 +535,9 @@ CodeGenModule::CodeGenModule(ASTContext &C,
537535
this->MSHotPatchFunctions.push_back(std::string{*I});
538536
} else {
539537
auto &DE = Context.getDiagnostics();
540-
unsigned DiagID =
541-
DE.getCustomDiagID(DiagnosticsEngine::Error,
542-
"failed to open hotpatch functions file "
543-
"(-fms-hotpatch-functions-file): %0 : %1");
544-
DE.Report(DiagID) << CGO.MSSecureHotPatchFunctionsFile
545-
<< BufOrErr.getError().message();
538+
DE.Report(diag::err_open_hotpatch_file_failed)
539+
<< CGO.MSSecureHotPatchFunctionsFile
540+
<< BufOrErr.getError().message();
546541
}
547542
}
548543

@@ -1759,20 +1754,19 @@ void CodeGenModule::Error(SourceLocation loc, StringRef message) {
17591754
/// ErrorUnsupported - Print out an error that codegen doesn't support the
17601755
/// specified stmt yet.
17611756
void CodeGenModule::ErrorUnsupported(const Stmt *S, const char *Type) {
1762-
unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error,
1763-
"cannot compile this %0 yet");
17641757
std::string Msg = Type;
1765-
getDiags().Report(Context.getFullLoc(S->getBeginLoc()), DiagID)
1758+
getDiags().Report(Context.getFullLoc(S->getBeginLoc()),
1759+
diag::err_codegen_unsupported)
17661760
<< Msg << S->getSourceRange();
17671761
}
17681762

17691763
/// ErrorUnsupported - Print out an error that codegen doesn't support the
17701764
/// specified decl yet.
17711765
void CodeGenModule::ErrorUnsupported(const Decl *D, const char *Type) {
1772-
unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error,
1773-
"cannot compile this %0 yet");
17741766
std::string Msg = Type;
1775-
getDiags().Report(Context.getFullLoc(D->getLocation()), DiagID) << Msg;
1767+
getDiags().Report(Context.getFullLoc(D->getLocation()),
1768+
diag::err_codegen_unsupported)
1769+
<< Msg;
17761770
}
17771771

17781772
void CodeGenModule::runWithSufficientStackSpace(SourceLocation Loc,
@@ -8265,11 +8259,7 @@ bool CodeGenModule::stopAutoInit() {
82658259
return true;
82668260
}
82678261
if (!NumAutoVarInit) {
8268-
unsigned DiagID = getDiags().getCustomDiagID(
8269-
DiagnosticsEngine::Warning,
8270-
"-ftrivial-auto-var-init-stop-after=%0 has been enabled to limit the "
8271-
"number of times ftrivial-auto-var-init=%1 gets applied.");
8272-
getDiags().Report(DiagID)
8262+
getDiags().Report(diag::warn_trivial_auto_var_limit)
82738263
<< StopAfter
82748264
<< (getContext().getLangOpts().getTrivialAutoVarInit() ==
82758265
LangOptions::TrivialAutoVarInitKind::Zero

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "CoverageMappingGen.h"
1717
#include "clang/AST/RecursiveASTVisitor.h"
1818
#include "clang/AST/StmtVisitor.h"
19+
#include "clang/Basic/DiagnosticFrontend.h"
1920
#include "llvm/IR/Intrinsics.h"
2021
#include "llvm/IR/MDBuilder.h"
2122
#include "llvm/Support/CommandLine.h"
@@ -293,23 +294,14 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
293294
if (LogOpStack.empty()) {
294295
/// Was the "split-nested" logical operator case encountered?
295296
if (SplitNestedLogicalOp) {
296-
unsigned DiagID = Diag.getCustomDiagID(
297-
DiagnosticsEngine::Warning,
298-
"unsupported MC/DC boolean expression; "
299-
"contains an operation with a nested boolean expression. "
300-
"Expression will not be covered");
301-
Diag.Report(S->getBeginLoc(), DiagID);
297+
Diag.Report(S->getBeginLoc(), diag::warn_pgo_nested_boolean_expr);
302298
return true;
303299
}
304300

305301
/// Was the maximum number of conditions encountered?
306302
if (NumCond > MCDCMaxCond) {
307-
unsigned DiagID = Diag.getCustomDiagID(
308-
DiagnosticsEngine::Warning,
309-
"unsupported MC/DC boolean expression; "
310-
"number of conditions (%0) exceeds max (%1). "
311-
"Expression will not be covered");
312-
Diag.Report(S->getBeginLoc(), DiagID) << NumCond << MCDCMaxCond;
303+
Diag.Report(S->getBeginLoc(), diag::warn_pgo_condition_limit)
304+
<< NumCond << MCDCMaxCond;
313305
return true;
314306
}
315307

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "CodeGenPGO.h"
1616
#include "clang/AST/StmtVisitor.h"
1717
#include "clang/Basic/Diagnostic.h"
18+
#include "clang/Basic/DiagnosticFrontend.h"
1819
#include "clang/Lex/Lexer.h"
1920
#include "llvm/ADT/DenseSet.h"
2021
#include "llvm/ADT/SmallSet.h"
@@ -2223,12 +2224,8 @@ struct CounterCoverageMappingBuilder
22232224
void cancelDecision(const BinaryOperator *E, unsigned Since, int NumTVs,
22242225
int MaxTVs) {
22252226
auto &Diag = CVM.getCodeGenModule().getDiags();
2226-
unsigned DiagID =
2227-
Diag.getCustomDiagID(DiagnosticsEngine::Warning,
2228-
"unsupported MC/DC boolean expression; "
2229-
"number of test vectors (%0) exceeds max (%1). "
2230-
"Expression will not be covered");
2231-
Diag.Report(E->getBeginLoc(), DiagID) << NumTVs << MaxTVs;
2227+
Diag.Report(E->getBeginLoc(), diag::warn_pgo_test_vector_limit)
2228+
<< NumTVs << MaxTVs;
22322229

22332230
// Restore MCDCBranch to Branch.
22342231
for (auto &SR : MutableArrayRef(SourceRegions).slice(Since)) {

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "clang/AST/DeclCXX.h"
2828
#include "clang/AST/StmtCXX.h"
2929
#include "clang/AST/VTableBuilder.h"
30+
#include "clang/Basic/DiagnosticFrontend.h"
3031
#include "clang/CodeGen/ConstantInitBuilder.h"
3132
#include "llvm/ADT/StringExtras.h"
3233
#include "llvm/ADT/StringSet.h"
@@ -3248,11 +3249,8 @@ llvm::Value *MicrosoftCXXABI::AdjustVirtualBase(
32483249
CharUnits offs = CharUnits::Zero();
32493250
if (!RD->hasDefinition()) {
32503251
DiagnosticsEngine &Diags = CGF.CGM.getDiags();
3251-
unsigned DiagID = Diags.getCustomDiagID(
3252-
DiagnosticsEngine::Error,
3253-
"member pointer representation requires a "
3254-
"complete class type for %0 to perform this expression");
3255-
Diags.Report(E->getExprLoc(), DiagID) << RD << E->getSourceRange();
3252+
Diags.Report(E->getExprLoc(), diag::err_member_ptr_requires_complete_type)
3253+
<< RD << E->getSourceRange();
32563254
} else if (RD->getNumVBases())
32573255
offs = getContext().getASTRecordLayout(RD).getVBPtrOffset();
32583256
VBPtrOffset = llvm::ConstantInt::get(CGM.IntTy, offs.getQuantity());

0 commit comments

Comments
 (0)