@@ -176,9 +176,12 @@ DiagnosticState::DiagnosticState() {
176
176
// Initialize our ignored diagnostics to default
177
177
ignoredDiagnostics.resize (LocalDiagID::NumDiags);
178
178
// Initialize warningsAsErrors to default
179
- warningsAsErrors.resize (LocalDiagID::NumDiags );
179
+ warningsAsErrors.resize (DiagGroupsCount );
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);
@@ -547,9 +551,7 @@ void DiagnosticEngine::setWarningsAsErrorsRules(
547
551
if (auto groupID = getDiagGroupIDByName (name);
548
552
groupID && *groupID != DiagGroupID::no_group) {
549
553
getDiagGroupInfoByID (*groupID).traverseDepthFirst ([&](auto group) {
550
- for (DiagID diagID : group.diagnostics ) {
551
- state.setWarningAsErrorForDiagID (diagID, isEnabled);
552
- }
554
+ state.setWarningsAsErrorsForDiagGroupID (*groupID, isEnabled);
553
555
});
554
556
} else {
555
557
unknownGroups.push_back (std::string (name));
@@ -1228,7 +1230,7 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
1228
1230
// 4) If the user substituted a different behavior for this behavior, apply
1229
1231
// that change
1230
1232
if (lvl == DiagnosticBehavior::Warning) {
1231
- if (getWarningAsErrorForDiagID (diag.getID ()))
1233
+ if (getWarningsAsErrorsForDiagGroupID (diag.getGroupID ()))
1232
1234
lvl = DiagnosticBehavior::Error;
1233
1235
if (suppressWarnings)
1234
1236
lvl = DiagnosticBehavior::Ignore;
@@ -1294,7 +1296,8 @@ void DiagnosticEngine::forwardTentativeDiagnosticsTo(
1294
1296
}
1295
1297
1296
1298
std::optional<DiagnosticInfo>
1297
- DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic) {
1299
+ DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic,
1300
+ bool includeDiagnosticName) {
1298
1301
auto behavior = state.determineBehavior (diagnostic);
1299
1302
if (behavior == DiagnosticBehavior::Ignore)
1300
1303
return std::nullopt;
@@ -1347,12 +1350,19 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
1347
1350
}
1348
1351
}
1349
1352
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 ());
1353
+ llvm::StringRef format;
1354
+ if (includeDiagnosticName)
1355
+ format =
1356
+ diagnosticStringWithNameFor (diagnostic.getID (), diagnostic.getGroupID (),
1357
+ getPrintDiagnosticNamesMode ());
1358
+ else
1359
+ format = diagnosticStringFor (diagnostic.getID ());
1360
+
1361
+ return DiagnosticInfo (diagnostic.getID (), loc, toDiagnosticKind (behavior),
1362
+ format, diagnostic.getArgs (), Category,
1363
+ getDefaultDiagnosticLoc (),
1364
+ /* child note info*/ {}, diagnostic.getRanges (), fixIts,
1365
+ diagnostic.isChildNote ());
1356
1366
}
1357
1367
1358
1368
static DeclName
@@ -1462,7 +1472,9 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
1462
1472
ArrayRef<Diagnostic> childNotes = diagnostic.getChildNotes ();
1463
1473
std::vector<Diagnostic> extendedChildNotes;
1464
1474
1465
- if (auto info = diagnosticInfoForDiagnostic (diagnostic)) {
1475
+ if (auto info =
1476
+ diagnosticInfoForDiagnostic (diagnostic,
1477
+ /* includeDiagnosticName= */ true )) {
1466
1478
// If the diagnostic location is within a buffer containing generated
1467
1479
// source code, add child notes showing where the generation occurred.
1468
1480
// We need to avoid doing this if this is itself a child note, as otherwise
@@ -1478,7 +1490,9 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
1478
1490
1479
1491
SmallVector<DiagnosticInfo, 1 > childInfo;
1480
1492
for (unsigned i : indices (childNotes)) {
1481
- auto child = diagnosticInfoForDiagnostic (childNotes[i]);
1493
+ auto child =
1494
+ diagnosticInfoForDiagnostic (childNotes[i],
1495
+ /* includeDiagnosticName= */ true );
1482
1496
assert (child);
1483
1497
assert (child->Kind == DiagnosticKind::Note &&
1484
1498
" Expected child diagnostics to all be notes?!" );
@@ -1516,12 +1530,18 @@ DiagnosticKind DiagnosticEngine::declaredDiagnosticKindFor(const DiagID id) {
1516
1530
return storedDiagnosticInfos[(unsigned )id].kind ;
1517
1531
}
1518
1532
1519
- llvm::StringRef DiagnosticEngine::diagnosticStringFor (
1520
- const DiagID id, PrintDiagnosticNamesMode printDiagnosticNamesMode) {
1533
+ llvm::StringRef DiagnosticEngine::diagnosticStringFor (DiagID id) {
1521
1534
llvm::StringRef message = diagnosticStrings[(unsigned )id];
1522
1535
if (auto localizationProducer = localization.get ()) {
1523
1536
message = localizationProducer->getMessageOr (id, message);
1524
1537
}
1538
+ return message;
1539
+ }
1540
+
1541
+ llvm::StringRef DiagnosticEngine::diagnosticStringWithNameFor (
1542
+ DiagID id, DiagGroupID groupID,
1543
+ PrintDiagnosticNamesMode printDiagnosticNamesMode) {
1544
+ auto message = diagnosticStringFor (id);
1525
1545
auto formatMessageWithName = [&](StringRef message, StringRef name) {
1526
1546
const int additionalCharsLength = 3 ; // ' ', '[', ']'
1527
1547
std::string messageWithName;
@@ -1540,7 +1560,6 @@ llvm::StringRef DiagnosticEngine::diagnosticStringFor(
1540
1560
message = formatMessageWithName (message, diagnosticIDStringFor (id));
1541
1561
break ;
1542
1562
case PrintDiagnosticNamesMode::Group:
1543
- auto groupID = storedDiagnosticInfos[(unsigned )id].groupID ;
1544
1563
if (groupID != DiagGroupID::no_group) {
1545
1564
message =
1546
1565
formatMessageWithName (message, getDiagGroupInfoByID (groupID).name );
0 commit comments