@@ -179,6 +179,9 @@ DiagnosticState::DiagnosticState() {
179179 warningsAsErrors.resize (LocalDiagID::NumDiags);
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);
@@ -1294,7 +1298,8 @@ void DiagnosticEngine::forwardTentativeDiagnosticsTo(
12941298}
12951299
12961300std::optional<DiagnosticInfo>
1297- DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic) {
1301+ DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic,
1302+ bool includeDiagnosticName) {
12981303 auto behavior = state.determineBehavior (diagnostic);
12991304 if (behavior == DiagnosticBehavior::Ignore)
13001305 return std::nullopt ;
@@ -1347,12 +1352,19 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
13471352 }
13481353 }
13491354
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 ());
13561368}
13571369
13581370static DeclName
@@ -1462,7 +1474,9 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
14621474 ArrayRef<Diagnostic> childNotes = diagnostic.getChildNotes ();
14631475 std::vector<Diagnostic> extendedChildNotes;
14641476
1465- if (auto info = diagnosticInfoForDiagnostic (diagnostic)) {
1477+ if (auto info =
1478+ diagnosticInfoForDiagnostic (diagnostic,
1479+ /* includeDiagnosticName= */ true )) {
14661480 // If the diagnostic location is within a buffer containing generated
14671481 // source code, add child notes showing where the generation occurred.
14681482 // 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) {
14781492
14791493 SmallVector<DiagnosticInfo, 1 > childInfo;
14801494 for (unsigned i : indices (childNotes)) {
1481- auto child = diagnosticInfoForDiagnostic (childNotes[i]);
1495+ auto child =
1496+ diagnosticInfoForDiagnostic (childNotes[i],
1497+ /* includeDiagnosticName= */ true );
14821498 assert (child);
14831499 assert (child->Kind == DiagnosticKind::Note &&
14841500 " Expected child diagnostics to all be notes?!" );
@@ -1516,12 +1532,18 @@ DiagnosticKind DiagnosticEngine::declaredDiagnosticKindFor(const DiagID id) {
15161532 return storedDiagnosticInfos[(unsigned )id].kind ;
15171533}
15181534
1519- llvm::StringRef DiagnosticEngine::diagnosticStringFor (
1520- const DiagID id, PrintDiagnosticNamesMode printDiagnosticNamesMode) {
1535+ llvm::StringRef DiagnosticEngine::diagnosticStringFor (DiagID id) {
15211536 llvm::StringRef message = diagnosticStrings[(unsigned )id];
15221537 if (auto localizationProducer = localization.get ()) {
15231538 message = localizationProducer->getMessageOr (id, message);
15241539 }
1540+ return message;
1541+ }
1542+
1543+ llvm::StringRef DiagnosticEngine::diagnosticStringWithNameFor (
1544+ DiagID id, DiagGroupID groupID,
1545+ PrintDiagnosticNamesMode printDiagnosticNamesMode) {
1546+ auto message = diagnosticStringFor (id);
15251547 auto formatMessageWithName = [&](StringRef message, StringRef name) {
15261548 const int additionalCharsLength = 3 ; // ' ', '[', ']'
15271549 std::string messageWithName;
@@ -1540,7 +1562,6 @@ llvm::StringRef DiagnosticEngine::diagnosticStringFor(
15401562 message = formatMessageWithName (message, diagnosticIDStringFor (id));
15411563 break ;
15421564 case PrintDiagnosticNamesMode::Group:
1543- auto groupID = storedDiagnosticInfos[(unsigned )id].groupID ;
15441565 if (groupID != DiagGroupID::no_group) {
15451566 message =
15461567 formatMessageWithName (message, getDiagGroupInfoByID (groupID).name );
0 commit comments