@@ -179,6 +179,9 @@ DiagnosticState::DiagnosticState() {
179
179
warningsAsErrors.resize (LocalDiagID::NumDiags);
180
180
}
181
181
182
+ Diagnostic::Diagnostic (DiagID ID)
183
+ : Diagnostic(ID, storedDiagnosticInfos[(unsigned )ID].groupID) {}
184
+
182
185
static CharSourceRange toCharSourceRange (SourceManager &SM, SourceRange SR) {
183
186
return CharSourceRange (SM, SR.Start , Lexer::getLocForEndOfToken (SM, SR.End ));
184
187
}
@@ -464,8 +467,8 @@ InFlightDiagnostic::wrapIn(const Diagnostic &wrapper) {
464
467
limit (Engine->getActiveDiagnostic ().BehaviorLimit ,
465
468
DiagnosticBehavior::Unspecified);
466
469
467
- Engine->WrappedDiagnostics .push_back (
468
- * Engine->diagnosticInfoForDiagnostic (Engine-> getActiveDiagnostic ()));
470
+ Engine->WrappedDiagnostics .push_back (*Engine-> diagnosticInfoForDiagnostic (
471
+ Engine->getActiveDiagnostic (), /* includeDiagnosticName= */ false ));
469
472
470
473
Engine->state .swap (tempState);
471
474
@@ -478,6 +481,7 @@ InFlightDiagnostic::wrapIn(const Diagnostic &wrapper) {
478
481
// Overwrite the ID and argument with those from the wrapper.
479
482
Engine->getActiveDiagnostic ().ID = wrapper.ID ;
480
483
Engine->getActiveDiagnostic ().Args = wrapper.Args ;
484
+ // Intentionally keeping the original GroupID here
481
485
482
486
// Set the argument to the diagnostic being wrapped.
483
487
assert (wrapper.getArgs ().front ().getKind () == DiagnosticArgumentKind::Diagnostic);
@@ -1294,7 +1298,8 @@ void DiagnosticEngine::forwardTentativeDiagnosticsTo(
1294
1298
}
1295
1299
1296
1300
std::optional<DiagnosticInfo>
1297
- DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic) {
1301
+ DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic,
1302
+ bool includeDiagnosticName) {
1298
1303
auto behavior = state.determineBehavior (diagnostic);
1299
1304
if (behavior == DiagnosticBehavior::Ignore)
1300
1305
return std::nullopt;
@@ -1347,12 +1352,19 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
1347
1352
}
1348
1353
}
1349
1354
1350
- return DiagnosticInfo (
1351
- diagnostic.getID (), loc, toDiagnosticKind (behavior),
1352
- diagnosticStringFor (diagnostic.getID (), getPrintDiagnosticNamesMode ()),
1353
- diagnostic.getArgs (), Category, getDefaultDiagnosticLoc (),
1354
- /* child note info*/ {}, diagnostic.getRanges (), fixIts,
1355
- diagnostic.isChildNote ());
1355
+ llvm::StringRef format;
1356
+ if (includeDiagnosticName)
1357
+ format =
1358
+ diagnosticStringWithNameFor (diagnostic.getID (), diagnostic.getGroupID (),
1359
+ getPrintDiagnosticNamesMode ());
1360
+ else
1361
+ format = diagnosticStringFor (diagnostic.getID ());
1362
+
1363
+ return DiagnosticInfo (diagnostic.getID (), loc, toDiagnosticKind (behavior),
1364
+ format, diagnostic.getArgs (), Category,
1365
+ getDefaultDiagnosticLoc (),
1366
+ /* child note info*/ {}, diagnostic.getRanges (), fixIts,
1367
+ diagnostic.isChildNote ());
1356
1368
}
1357
1369
1358
1370
static DeclName
@@ -1462,7 +1474,9 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
1462
1474
ArrayRef<Diagnostic> childNotes = diagnostic.getChildNotes ();
1463
1475
std::vector<Diagnostic> extendedChildNotes;
1464
1476
1465
- if (auto info = diagnosticInfoForDiagnostic (diagnostic)) {
1477
+ if (auto info =
1478
+ diagnosticInfoForDiagnostic (diagnostic,
1479
+ /* includeDiagnosticName= */ true )) {
1466
1480
// If the diagnostic location is within a buffer containing generated
1467
1481
// source code, add child notes showing where the generation occurred.
1468
1482
// We need to avoid doing this if this is itself a child note, as otherwise
@@ -1478,7 +1492,9 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
1478
1492
1479
1493
SmallVector<DiagnosticInfo, 1 > childInfo;
1480
1494
for (unsigned i : indices (childNotes)) {
1481
- auto child = diagnosticInfoForDiagnostic (childNotes[i]);
1495
+ auto child =
1496
+ diagnosticInfoForDiagnostic (childNotes[i],
1497
+ /* includeDiagnosticName= */ true );
1482
1498
assert (child);
1483
1499
assert (child->Kind == DiagnosticKind::Note &&
1484
1500
" Expected child diagnostics to all be notes?!" );
@@ -1516,12 +1532,18 @@ DiagnosticKind DiagnosticEngine::declaredDiagnosticKindFor(const DiagID id) {
1516
1532
return storedDiagnosticInfos[(unsigned )id].kind ;
1517
1533
}
1518
1534
1519
- llvm::StringRef DiagnosticEngine::diagnosticStringFor (
1520
- const DiagID id, PrintDiagnosticNamesMode printDiagnosticNamesMode) {
1535
+ llvm::StringRef DiagnosticEngine::diagnosticStringFor (DiagID id) {
1521
1536
llvm::StringRef message = diagnosticStrings[(unsigned )id];
1522
1537
if (auto localizationProducer = localization.get ()) {
1523
1538
message = localizationProducer->getMessageOr (id, message);
1524
1539
}
1540
+ return message;
1541
+ }
1542
+
1543
+ llvm::StringRef DiagnosticEngine::diagnosticStringWithNameFor (
1544
+ DiagID id, DiagGroupID groupID,
1545
+ PrintDiagnosticNamesMode printDiagnosticNamesMode) {
1546
+ auto message = diagnosticStringFor (id);
1525
1547
auto formatMessageWithName = [&](StringRef message, StringRef name) {
1526
1548
const int additionalCharsLength = 3 ; // ' ', '[', ']'
1527
1549
std::string messageWithName;
@@ -1540,7 +1562,6 @@ llvm::StringRef DiagnosticEngine::diagnosticStringFor(
1540
1562
message = formatMessageWithName (message, diagnosticIDStringFor (id));
1541
1563
break ;
1542
1564
case PrintDiagnosticNamesMode::Group:
1543
- auto groupID = storedDiagnosticInfos[(unsigned )id].groupID ;
1544
1565
if (groupID != DiagGroupID::no_group) {
1545
1566
message =
1546
1567
formatMessageWithName (message, getDiagGroupInfoByID (groupID).name );
0 commit comments