diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-10 05:03:45 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-10 05:03:45 +0000 |
commit | 16afdf76b6f12e41ff6f6e6828bfb1d4732523ba (patch) | |
tree | ff1e52eb429bff15196fbb565d94225d940c70f6 /lib/Frontend/SerializedDiagnosticPrinter.cpp | |
parent | dd44f34301316b814277d6a8c146d86c7115330b (diff) |
Fix an assertion hit when the serialized diagnostics writer receive a diagnostic
from the frontend when the location is invalid and the SourceManager null.
Instead of keeping the SourceManager object in DiagnosticRenderer, propagate it
to the calls accordingly (as reference when it is expected to not be null, or pointer
when it may be null).
This effectively makes DiagnosticRenderer not tied to a specific SourceManager,
removing a hack from TextDiagnosticPrinter.
rdar://11386874
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156536 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/SerializedDiagnosticPrinter.cpp')
-rw-r--r-- | lib/Frontend/SerializedDiagnosticPrinter.cpp | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/lib/Frontend/SerializedDiagnosticPrinter.cpp b/lib/Frontend/SerializedDiagnosticPrinter.cpp index 7bf8742a80..a20f30d6be 100644 --- a/lib/Frontend/SerializedDiagnosticPrinter.cpp +++ b/lib/Frontend/SerializedDiagnosticPrinter.cpp @@ -53,10 +53,9 @@ class SDiagsRenderer : public DiagnosticNoteRenderer { RecordData &Record; public: SDiagsRenderer(SDiagsWriter &Writer, RecordData &Record, - const SourceManager &SM, const LangOptions &LangOpts, const DiagnosticOptions &DiagOpts) - : DiagnosticNoteRenderer(SM, LangOpts, DiagOpts), + : DiagnosticNoteRenderer(LangOpts, DiagOpts), Writer(Writer), Record(Record){} virtual ~SDiagsRenderer() {} @@ -67,18 +66,21 @@ protected: DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<CharSourceRange> Ranges, + const SourceManager *SM, DiagOrStoredDiag D); virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, - ArrayRef<CharSourceRange> Ranges) {} + ArrayRef<CharSourceRange> Ranges, + const SourceManager &SM) {} - void emitNote(SourceLocation Loc, StringRef Message); + void emitNote(SourceLocation Loc, StringRef Message, const SourceManager *SM); virtual void emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level, SmallVectorImpl<CharSourceRange>& Ranges, - ArrayRef<FixItHint> Hints); + ArrayRef<FixItHint> Hints, + const SourceManager &SM); virtual void beginDiagnostic(DiagOrStoredDiag D, DiagnosticsEngine::Level Level); @@ -137,15 +139,16 @@ private: unsigned getEmitFile(const char *Filename); /// \brief Add SourceLocation information the specified record. - void AddLocToRecord(SourceLocation Loc, const SourceManager &SM, + void AddLocToRecord(SourceLocation Loc, const SourceManager *SM, PresumedLoc PLoc, RecordDataImpl &Record, unsigned TokSize = 0); /// \brief Add SourceLocation information the specified record. void AddLocToRecord(SourceLocation Loc, RecordDataImpl &Record, - const SourceManager &SM, + const SourceManager *SM, unsigned TokSize = 0) { - AddLocToRecord(Loc, SM, SM.getPresumedLoc(Loc), Record, TokSize); + AddLocToRecord(Loc, SM, SM ? SM->getPresumedLoc(Loc) : PresumedLoc(), + Record, TokSize); } /// \brief Add CharSourceRange information the specified record. @@ -241,7 +244,7 @@ static void EmitRecordID(unsigned ID, const char *Name, } void SDiagsWriter::AddLocToRecord(SourceLocation Loc, - const SourceManager &SM, + const SourceManager *SM, PresumedLoc PLoc, RecordDataImpl &Record, unsigned TokSize) { @@ -257,19 +260,19 @@ void SDiagsWriter::AddLocToRecord(SourceLocation Loc, Record.push_back(getEmitFile(PLoc.getFilename())); Record.push_back(PLoc.getLine()); Record.push_back(PLoc.getColumn()+TokSize); - Record.push_back(SM.getFileOffset(Loc)); + Record.push_back(SM->getFileOffset(Loc)); } void SDiagsWriter::AddCharSourceRangeToRecord(CharSourceRange Range, RecordDataImpl &Record, const SourceManager &SM) { - AddLocToRecord(Range.getBegin(), Record, SM); + AddLocToRecord(Range.getBegin(), Record, &SM); unsigned TokSize = 0; if (Range.isTokenRange()) TokSize = Lexer::MeasureTokenLength(Range.getEnd(), SM, *LangOpts); - AddLocToRecord(Range.getEnd(), Record, SM, TokSize); + AddLocToRecord(Range.getEnd(), Record, &SM, TokSize); } unsigned SDiagsWriter::getEmitFile(const char *FileName){ @@ -484,13 +487,15 @@ void SDiagsWriter::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, diagBuf.clear(); Info.FormatDiagnostic(diagBuf); - SourceManager &SM = Info.getSourceManager(); - SDiagsRenderer Renderer(*this, Record, SM, *LangOpts, DiagOpts); + const SourceManager * + SM = Info.hasSourceManager() ? &Info.getSourceManager() : 0; + SDiagsRenderer Renderer(*this, Record, *LangOpts, DiagOpts); Renderer.emitDiagnostic(Info.getLocation(), DiagLevel, diagBuf.str(), Info.getRanges(), llvm::makeArrayRef(Info.getFixItHints(), Info.getNumFixItHints()), + SM, &Info); } @@ -500,6 +505,7 @@ SDiagsRenderer::emitDiagnosticMessage(SourceLocation Loc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<clang::CharSourceRange> Ranges, + const SourceManager *SM, DiagOrStoredDiag D) { // Emit the RECORD_DIAG record. Writer.Record.clear(); @@ -539,7 +545,8 @@ void SDiagsRenderer::endDiagnostic(DiagOrStoredDiag D, void SDiagsRenderer::emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level, SmallVectorImpl<CharSourceRange> &Ranges, - ArrayRef<FixItHint> Hints) { + ArrayRef<FixItHint> Hints, + const SourceManager &SM) { // Emit Source Ranges. for (ArrayRef<CharSourceRange>::iterator it=Ranges.begin(), ei=Ranges.end(); it != ei; ++it) { @@ -562,7 +569,8 @@ void SDiagsRenderer::emitCodeContext(SourceLocation Loc, } } -void SDiagsRenderer::emitNote(SourceLocation Loc, StringRef Message) { +void SDiagsRenderer::emitNote(SourceLocation Loc, StringRef Message, + const SourceManager *SM) { Writer.Stream.EnterSubblock(BLOCK_DIAG, 4); RecordData Record; Record.push_back(RECORD_DIAG); |