@@ -176,9 +176,12 @@ DiagnosticState::DiagnosticState() {
176176 // Initialize our ignored diagnostics to default
177177 ignoredDiagnostics.resize (LocalDiagID::NumDiags);
178178 // Initialize warningsAsErrors to default
179- warningsAsErrors.resize (LocalDiagID::NumDiags );
179+ warningsAsErrors.resize (DiagGroupsCount );
180180}
181181
182+ Diagnostic::Diagnostic (DiagID ID)
183+ : Diagnostic(ID, storedDiagnosticInfos[(unsigned )ID].groupID) {}
184+
182185static CharSourceRange toCharSourceRange (SourceManager &SM, SourceRange SR) {
183186 return CharSourceRange (SM, SR.Start , Lexer::getLocForEndOfToken (SM, SR.End ));
184187}
@@ -464,8 +467,8 @@ InFlightDiagnostic::wrapIn(const Diagnostic &wrapper) {
464467 limit (Engine->getActiveDiagnostic ().BehaviorLimit ,
465468 DiagnosticBehavior::Unspecified);
466469
467- Engine->WrappedDiagnostics .push_back (
468- * Engine->diagnosticInfoForDiagnostic (Engine-> getActiveDiagnostic ()));
470+ Engine->WrappedDiagnostics .push_back (*Engine-> diagnosticInfoForDiagnostic (
471+ Engine->getActiveDiagnostic (), /* includeDiagnosticName= */ false ));
469472
470473 Engine->state .swap (tempState);
471474
@@ -478,6 +481,7 @@ InFlightDiagnostic::wrapIn(const Diagnostic &wrapper) {
478481 // Overwrite the ID and argument with those from the wrapper.
479482 Engine->getActiveDiagnostic ().ID = wrapper.ID ;
480483 Engine->getActiveDiagnostic ().Args = wrapper.Args ;
484+ // Intentionally keeping the original GroupID here
481485
482486 // Set the argument to the diagnostic being wrapped.
483487 assert (wrapper.getArgs ().front ().getKind () == DiagnosticArgumentKind::Diagnostic);
@@ -547,9 +551,7 @@ void DiagnosticEngine::setWarningsAsErrorsRules(
547551 if (auto groupID = getDiagGroupIDByName (name);
548552 groupID && *groupID != DiagGroupID::no_group) {
549553 getDiagGroupInfoByID (*groupID).traverseDepthFirst ([&](auto group) {
550- for (DiagID diagID : group.diagnostics ) {
551- state.setWarningAsErrorForDiagID (diagID, isEnabled);
552- }
554+ state.setWarningsAsErrorsForDiagGroupID (*groupID, isEnabled);
553555 });
554556 } else {
555557 unknownGroups.push_back (std::string (name));
@@ -1228,7 +1230,7 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
12281230 // 4) If the user substituted a different behavior for this behavior, apply
12291231 // that change
12301232 if (lvl == DiagnosticBehavior::Warning) {
1231- if (getWarningAsErrorForDiagID (diag.getID ()))
1233+ if (getWarningsAsErrorsForDiagGroupID (diag.getGroupID ()))
12321234 lvl = DiagnosticBehavior::Error;
12331235 if (suppressWarnings)
12341236 lvl = DiagnosticBehavior::Ignore;
@@ -1294,7 +1296,8 @@ void DiagnosticEngine::forwardTentativeDiagnosticsTo(
12941296}
12951297
12961298std::optional<DiagnosticInfo>
1297- DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic) {
1299+ DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic,
1300+ bool includeDiagnosticName) {
12981301 auto behavior = state.determineBehavior (diagnostic);
12991302 if (behavior == DiagnosticBehavior::Ignore)
13001303 return std::nullopt ;
@@ -1347,12 +1350,19 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
13471350 }
13481351 }
13491352
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 ());
13561366}
13571367
13581368static DeclName
@@ -1462,7 +1472,9 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
14621472 ArrayRef<Diagnostic> childNotes = diagnostic.getChildNotes ();
14631473 std::vector<Diagnostic> extendedChildNotes;
14641474
1465- if (auto info = diagnosticInfoForDiagnostic (diagnostic)) {
1475+ if (auto info =
1476+ diagnosticInfoForDiagnostic (diagnostic,
1477+ /* includeDiagnosticName= */ true )) {
14661478 // If the diagnostic location is within a buffer containing generated
14671479 // source code, add child notes showing where the generation occurred.
14681480 // 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) {
14781490
14791491 SmallVector<DiagnosticInfo, 1 > childInfo;
14801492 for (unsigned i : indices (childNotes)) {
1481- auto child = diagnosticInfoForDiagnostic (childNotes[i]);
1493+ auto child =
1494+ diagnosticInfoForDiagnostic (childNotes[i],
1495+ /* includeDiagnosticName= */ true );
14821496 assert (child);
14831497 assert (child->Kind == DiagnosticKind::Note &&
14841498 " Expected child diagnostics to all be notes?!" );
@@ -1516,12 +1530,18 @@ DiagnosticKind DiagnosticEngine::declaredDiagnosticKindFor(const DiagID id) {
15161530 return storedDiagnosticInfos[(unsigned )id].kind ;
15171531}
15181532
1519- llvm::StringRef DiagnosticEngine::diagnosticStringFor (
1520- const DiagID id, PrintDiagnosticNamesMode printDiagnosticNamesMode) {
1533+ llvm::StringRef DiagnosticEngine::diagnosticStringFor (DiagID id) {
15211534 llvm::StringRef message = diagnosticStrings[(unsigned )id];
15221535 if (auto localizationProducer = localization.get ()) {
15231536 message = localizationProducer->getMessageOr (id, message);
15241537 }
1538+ return message;
1539+ }
1540+
1541+ llvm::StringRef DiagnosticEngine::diagnosticStringWithNameFor (
1542+ DiagID id, DiagGroupID groupID,
1543+ PrintDiagnosticNamesMode printDiagnosticNamesMode) {
1544+ auto message = diagnosticStringFor (id);
15251545 auto formatMessageWithName = [&](StringRef message, StringRef name) {
15261546 const int additionalCharsLength = 3 ; // ' ', '[', ']'
15271547 std::string messageWithName;
@@ -1540,7 +1560,6 @@ llvm::StringRef DiagnosticEngine::diagnosticStringFor(
15401560 message = formatMessageWithName (message, diagnosticIDStringFor (id));
15411561 break ;
15421562 case PrintDiagnosticNamesMode::Group:
1543- auto groupID = storedDiagnosticInfos[(unsigned )id].groupID ;
15441563 if (groupID != DiagGroupID::no_group) {
15451564 message =
15461565 formatMessageWithName (message, getDiagGroupInfoByID (groupID).name );
0 commit comments