@@ -197,7 +197,7 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
197
197
formatted_text = !s.empty () ? std::move (s) : std::string (text);
198
198
}
199
199
RawDiagnostic diagnostic (
200
- formatted_text, info.Kind , bufferName, bufferID, line_col.first ,
200
+ formatted_text, info.Kind , bufferName. str () , bufferID, line_col.first ,
201
201
line_col.second ,
202
202
use_fixits ? info.FixIts : llvm::ArrayRef<swift::Diagnostic::FixIt>());
203
203
if (info.ID == swift::diag::error_from_clang.ID ||
@@ -287,8 +287,7 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
287
287
288
288
// Need to remap the error/warning to a different line.
289
289
StreamString match;
290
- match.Printf (" %s:%u:" , diagnostic.bufferName .str ().c_str (),
291
- diagnostic.line );
290
+ match.Printf (" %s:%u:" , diagnostic.bufferName .c_str (), diagnostic.line );
292
291
const size_t match_len = match.GetString ().size ();
293
292
size_t match_pos = diagnostic.description .find (match.GetString ().str ());
294
293
if (match_pos == std::string::npos)
@@ -302,7 +301,7 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
302
301
fixed_description.Printf (
303
302
" %s" ,
304
303
diagnostic.description .substr (start_pos, match_pos).c_str ());
305
- fixed_description.Printf (" %s:%u:" , diagnostic.bufferName .str (). c_str (),
304
+ fixed_description.Printf (" %s:%u:" , diagnostic.bufferName .c_str (),
306
305
diagnostic.line - first_line + 1 );
307
306
start_pos = match_pos + match_len;
308
307
match_pos =
@@ -373,30 +372,29 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
373
372
struct RawDiagnostic {
374
373
RawDiagnostic () = default ;
375
374
RawDiagnostic (std::string in_desc, swift::DiagnosticKind in_kind,
376
- llvm::StringRef in_bufferName, unsigned in_bufferID,
375
+ std::string in_bufferName, unsigned in_bufferID,
377
376
uint32_t in_line, uint32_t in_column,
378
377
llvm::ArrayRef<swift::Diagnostic::FixIt> in_fixits)
379
- : description(in_desc), kind(in_kind), bufferName(in_bufferName),
380
- bufferID (in_bufferID), line(in_line), column(in_column),
381
- fixits(in_fixits) {}
382
- RawDiagnostic (const RawDiagnostic &other)
383
- : description(other.description), kind(other.kind),
384
- bufferName(other.bufferName), bufferID(other.bufferID),
385
- line(other.line), column(other.column), fixits(other.fixits) {}
378
+ : description(in_desc), bufferName(in_bufferName), fixits(in_fixits),
379
+ kind (in_kind), bufferID(in_bufferID), line(in_line),
380
+ column(in_column) {}
381
+ RawDiagnostic (const RawDiagnostic &other) = default;
386
382
bool operator ==(const RawDiagnostic& other) {
387
- return kind == other.kind && bufferID == other.bufferID &&
388
- line == other.line && column == other.column &&
389
- description == other.description ;
383
+ return kind == other.kind && line == other.line &&
384
+ bufferID == other.bufferID && column == other.column &&
385
+ bufferName == other. bufferName && description == other.description ;
390
386
}
391
387
bool operator !=(const RawDiagnostic &other) { return !(*this == other); }
392
388
393
389
std::string description;
390
+ std::string bufferName;
391
+ std::vector<swift::DiagnosticInfo::FixIt> fixits;
394
392
swift::DiagnosticKind kind = swift::DiagnosticKind::Error;
395
- llvm::StringRef bufferName;
393
+ // / Only stored for comparison in HandleDiagnostic. There is no
394
+ // / guarantee that the SourceMgr is still alive in a stored diagnostic.
396
395
unsigned bufferID;
397
396
uint32_t line;
398
397
uint32_t column;
399
- std::vector<swift::DiagnosticInfo::FixIt> fixits;
400
398
};
401
399
402
400
SwiftASTContext &m_ast_context;
0 commit comments