From: Douglas Gregor Date: Mon, 11 Oct 2010 22:02:06 +0000 (+0000) Subject: Eliminate -fdiagnostics-binary and all of the infrastructure for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3ab63e0f66429abf2a3e4cde889e420e41e8790;p=clang Eliminate -fdiagnostics-binary and all of the infrastructure for emitting diagnostics in a binary form to be consumed by libclang, since libclang no longer does any of its work out-of-process, making this code dead. Besides, this stuff never worked at 100% anyway. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116250 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 37d26947c3..0d1caca00a 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -930,8 +930,8 @@ public: }; /** - * \brief Represents a diagnostic in a form that can be serialized and - * deserialized. + * \brief Represents a diagnostic in a form that can be retained until its + * corresponding source manager is destroyed. */ class StoredDiagnostic { Diagnostic::Level Level; @@ -964,19 +964,6 @@ public: fixit_iterator fixit_begin() const { return FixIts.begin(); } fixit_iterator fixit_end() const { return FixIts.end(); } unsigned fixit_size() const { return FixIts.size(); } - - /// Serialize - Serialize the given diagnostic (with its diagnostic - /// level) to the given stream. Serialization is a lossy operation, - /// since the specific diagnostic ID and any macro-instantiation - /// information is lost. - void Serialize(llvm::raw_ostream &OS) const; - - /// Deserialize - Deserialize the first diagnostic within the memory - /// [Memory, MemoryEnd), producing a new diagnostic builder describing the - /// deserialized diagnostic. If the memory does not contain a - /// diagnostic, returns a diagnostic builder with no diagnostic ID. - static StoredDiagnostic Deserialize(FileManager &FM, SourceManager &SM, - const char *&Memory, const char *MemoryEnd); }; /// DiagnosticClient - This is an abstract interface implemented by clients of diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index e6463b07c1..aad7d95ad2 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -211,7 +211,6 @@ def fno_caret_diagnostics : Flag<"-fno-caret-diagnostics">, HelpText<"Do not include source line and caret with diagnostics">; def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">, HelpText<"Do not include fixit information in diagnostics">; -def fdiagnostics_binary : Flag<"-fdiagnostics-binary">; def w : Flag<"-w">, HelpText<"Suppress all warnings">; def pedantic : Flag<"-pedantic">; def pedantic_errors : Flag<"-pedantic-errors">; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index c39a79dfa1..4d31ce48ff 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -261,7 +261,6 @@ def fconstant_string_class_EQ : Joined<"-fconstant-string-class=">, Group, Group; def fdebug_pass_arguments : Flag<"-fdebug-pass-arguments">, Group; def fdebug_pass_structure : Flag<"-fdebug-pass-structure">, Group; -def fdiagnostics_binary : Flag<"-fdiagnostics-binary">, Group, Flags<[HelpHidden]>; def fdiagnostics_fixit_info : Flag<"-fdiagnostics-fixit-info">, Group; def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-range-info">, Group; def fdiagnostics_parseable_fixits : Flag<"-fdiagnostics-parseable-fixits">, Group; diff --git a/include/clang/Frontend/DiagnosticOptions.h b/include/clang/Frontend/DiagnosticOptions.h index c80bc03721..f7f498bff0 100644 --- a/include/clang/Frontend/DiagnosticOptions.h +++ b/include/clang/Frontend/DiagnosticOptions.h @@ -41,9 +41,6 @@ public: unsigned VerifyDiagnostics: 1; /// Check that diagnostics match the expected /// diagnostics, indicated by markers in the /// input source file. - unsigned BinaryOutput : 1; /// Emit diagnostics via the diagnostic - /// binary serialization mechanism, to be - /// deserialized by, e.g., the CIndex library. unsigned ErrorLimit; /// Limit # errors emitted. unsigned MacroBacktraceLimit; /// Limit depth of macro instantiation @@ -86,7 +83,6 @@ public: ShowSourceRanges = 0; ShowParseableFixits = 0; VerifyDiagnostics = 0; - BinaryOutput = 0; ErrorLimit = 0; TemplateBacktraceLimit = DefaultTemplateBacktraceLimit; MacroBacktraceLimit = DefaultMacroBacktraceLimit; diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index d8095f4f6d..6430b7ec1c 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -1065,251 +1065,6 @@ StoredDiagnostic::StoredDiagnostic(Diagnostic::Level Level, StoredDiagnostic::~StoredDiagnostic() { } -static void WriteUnsigned(llvm::raw_ostream &OS, unsigned Value) { - OS.write((const char *)&Value, sizeof(unsigned)); -} - -static void WriteString(llvm::raw_ostream &OS, llvm::StringRef String) { - WriteUnsigned(OS, String.size()); - OS.write(String.data(), String.size()); -} - -static void WriteSourceLocation(llvm::raw_ostream &OS, - SourceManager *SM, - SourceLocation Location) { - if (!SM || Location.isInvalid()) { - // If we don't have a source manager or this location is invalid, - // just write an invalid location. - WriteUnsigned(OS, 0); - WriteUnsigned(OS, 0); - WriteUnsigned(OS, 0); - return; - } - - Location = SM->getInstantiationLoc(Location); - std::pair Decomposed = SM->getDecomposedLoc(Location); - - const FileEntry *FE = SM->getFileEntryForID(Decomposed.first); - if (FE) - WriteString(OS, FE->getName()); - else { - // Fallback to using the buffer name when there is no entry. - WriteString(OS, SM->getBuffer(Decomposed.first)->getBufferIdentifier()); - } - - WriteUnsigned(OS, SM->getLineNumber(Decomposed.first, Decomposed.second)); - WriteUnsigned(OS, SM->getColumnNumber(Decomposed.first, Decomposed.second)); -} - -void StoredDiagnostic::Serialize(llvm::raw_ostream &OS) const { - SourceManager *SM = 0; - if (getLocation().isValid()) - SM = &const_cast(getLocation().getManager()); - - // Write a short header to help identify diagnostics. - OS << (char)0x06 << (char)0x07; - - // Write the diagnostic level and location. - WriteUnsigned(OS, (unsigned)Level); - WriteSourceLocation(OS, SM, getLocation()); - - // Write the diagnostic message. - llvm::SmallString<64> Message; - WriteString(OS, getMessage()); - - // Count the number of ranges that don't point into macros, since - // only simple file ranges serialize well. - unsigned NumNonMacroRanges = 0; - for (range_iterator R = range_begin(), REnd = range_end(); R != REnd; ++R) { - if (R->getBegin().isMacroID() || R->getEnd().isMacroID()) - continue; - - ++NumNonMacroRanges; - } - - // Write the ranges. - WriteUnsigned(OS, NumNonMacroRanges); - if (NumNonMacroRanges) { - for (range_iterator R = range_begin(), REnd = range_end(); R != REnd; ++R) { - if (R->getBegin().isMacroID() || R->getEnd().isMacroID()) - continue; - - WriteSourceLocation(OS, SM, R->getBegin()); - WriteSourceLocation(OS, SM, R->getEnd()); - WriteUnsigned(OS, R->isTokenRange()); - } - } - - // Determine if all of the fix-its involve rewrites with simple file - // locations (not in macro instantiations). If so, we can write - // fix-it information. - unsigned NumFixIts = 0; - for (fixit_iterator F = fixit_begin(), FEnd = fixit_end(); F != FEnd; ++F) { - if (F->RemoveRange.isValid() && - (F->RemoveRange.getBegin().isMacroID() || - F->RemoveRange.getEnd().isMacroID())) { - NumFixIts = 0; - break; - } - - ++NumFixIts; - } - - // Write the fix-its. - WriteUnsigned(OS, NumFixIts); - for (fixit_iterator F = fixit_begin(), FEnd = fixit_end(); F != FEnd; ++F) { - WriteSourceLocation(OS, SM, F->RemoveRange.getBegin()); - WriteSourceLocation(OS, SM, F->RemoveRange.getEnd()); - WriteUnsigned(OS, F->RemoveRange.isTokenRange()); - WriteString(OS, F->CodeToInsert); - } -} - -static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd, - unsigned &Value) { - if (Memory + sizeof(unsigned) > MemoryEnd) - return true; - - memmove(&Value, Memory, sizeof(unsigned)); - Memory += sizeof(unsigned); - return false; -} - -static bool ReadSourceLocation(FileManager &FM, SourceManager &SM, - const char *&Memory, const char *MemoryEnd, - SourceLocation &Location) { - // Read the filename. - unsigned FileNameLen = 0; - if (ReadUnsigned(Memory, MemoryEnd, FileNameLen) || - Memory + FileNameLen > MemoryEnd) - return true; - - llvm::StringRef FileName(Memory, FileNameLen); - Memory += FileNameLen; - - // Read the line, column. - unsigned Line = 0, Column = 0; - if (ReadUnsigned(Memory, MemoryEnd, Line) || - ReadUnsigned(Memory, MemoryEnd, Column)) - return true; - - if (FileName.empty()) { - Location = SourceLocation(); - return false; - } - - const FileEntry *File = FM.getFile(FileName); - if (!File) - return true; - - // Make sure that this file has an entry in the source manager. - if (!SM.hasFileInfo(File)) - SM.createFileID(File, SourceLocation(), SrcMgr::C_User); - - Location = SM.getLocation(File, Line, Column); - return false; -} - -StoredDiagnostic -StoredDiagnostic::Deserialize(FileManager &FM, SourceManager &SM, - const char *&Memory, const char *MemoryEnd) { - while (true) { - if (Memory == MemoryEnd) - return StoredDiagnostic(); - - if (*Memory != 0x06) { - ++Memory; - continue; - } - - ++Memory; - if (Memory == MemoryEnd) - return StoredDiagnostic(); - - if (*Memory != 0x07) { - ++Memory; - continue; - } - - // We found the header. We're done. - ++Memory; - break; - } - - // Read the severity level. - unsigned Level = 0; - if (ReadUnsigned(Memory, MemoryEnd, Level) || Level > Diagnostic::Fatal) - return StoredDiagnostic(); - - // Read the source location. - SourceLocation Location; - if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, Location)) - return StoredDiagnostic(); - - // Read the diagnostic text. - if (Memory == MemoryEnd) - return StoredDiagnostic(); - - unsigned MessageLen = 0; - if (ReadUnsigned(Memory, MemoryEnd, MessageLen) || - Memory + MessageLen > MemoryEnd) - return StoredDiagnostic(); - - llvm::StringRef Message(Memory, MessageLen); - Memory += MessageLen; - - - // At this point, we have enough information to form a diagnostic. Do so. - StoredDiagnostic Diag; - Diag.Level = (Diagnostic::Level)Level; - Diag.Loc = FullSourceLoc(Location, SM); - Diag.Message = Message; - if (Memory == MemoryEnd) - return Diag; - - // Read the source ranges. - unsigned NumSourceRanges = 0; - if (ReadUnsigned(Memory, MemoryEnd, NumSourceRanges)) - return Diag; - for (unsigned I = 0; I != NumSourceRanges; ++I) { - SourceLocation Begin, End; - unsigned IsTokenRange; - if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, Begin) || - ReadSourceLocation(FM, SM, Memory, MemoryEnd, End) || - ReadUnsigned(Memory, MemoryEnd, IsTokenRange)) - return Diag; - - Diag.Ranges.push_back(CharSourceRange(SourceRange(Begin, End), - IsTokenRange)); - } - - // Read the fix-it hints. - unsigned NumFixIts = 0; - if (ReadUnsigned(Memory, MemoryEnd, NumFixIts)) - return Diag; - for (unsigned I = 0; I != NumFixIts; ++I) { - SourceLocation RemoveBegin, RemoveEnd; - unsigned InsertLen = 0, RemoveIsTokenRange; - if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveBegin) || - ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveEnd) || - ReadUnsigned(Memory, MemoryEnd, RemoveIsTokenRange) || - ReadUnsigned(Memory, MemoryEnd, InsertLen) || - Memory + InsertLen > MemoryEnd) { - Diag.FixIts.clear(); - return Diag; - } - - FixItHint Hint; - Hint.RemoveRange = CharSourceRange(SourceRange(RemoveBegin, RemoveEnd), - RemoveIsTokenRange); - Hint.CodeToInsert.assign(Memory, Memory + InsertLen); - Memory += InsertLen; - Diag.FixIts.push_back(Hint); - } - - return Diag; -} - /// IncludeInDiagnosticCounts - This method (whose default implementation /// returns true) indicates whether the diagnostics handled by this /// DiagnosticClient should be included in the number of diagnostics diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 31f9c08eeb..5ea1cbb357 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1418,8 +1418,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_diagnostics_fixit_info)) CmdArgs.push_back("-fno-diagnostics-fixit-info"); - Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_binary); - // Enable -fdiagnostics-show-option by default. if (Args.hasFlag(options::OPT_fdiagnostics_show_option, options::OPT_fno_diagnostics_show_option)) diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 939766351d..44e5fd2215 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -90,24 +90,6 @@ void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) { } // Diagnostics -namespace { - class BinaryDiagnosticSerializer : public DiagnosticClient { - llvm::raw_ostream &OS; - SourceManager *SourceMgr; - public: - explicit BinaryDiagnosticSerializer(llvm::raw_ostream &OS) - : OS(OS), SourceMgr(0) { } - - virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, - const DiagnosticInfo &Info); - }; -} - -void BinaryDiagnosticSerializer::HandleDiagnostic(Diagnostic::Level DiagLevel, - const DiagnosticInfo &Info) { - StoredDiagnostic(DiagLevel, Info).Serialize(OS); -} - static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts, unsigned argc, const char* const *argv, Diagnostic &Diags) { @@ -143,21 +125,7 @@ CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts, // Create the diagnostic client for reporting errors or for // implementing -verify. llvm::OwningPtr DiagClient; - if (Opts.BinaryOutput) { - if (llvm::sys::Program::ChangeStderrToBinary()) { - // We weren't able to set standard error to binary, which is a - // bit of a problem. So, just create a text diagnostic printer - // to complain about this problem, and pretend that the user - // didn't try to use binary output. - Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts)); - Diags->Report(diag::err_fe_stderr_binary); - return Diags; - } else { - Diags->setClient(new BinaryDiagnosticSerializer(llvm::errs())); - } - } else { - Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts)); - } + Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts)); // Chain in -verify checker, if requested. if (Opts.VerifyDiagnostics) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 942bc0d5e6..b4bb61327f 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -253,8 +253,6 @@ static void DiagnosticOptsToArgs(const DiagnosticOptions &Opts, Res.push_back("-fcolor-diagnostics"); if (Opts.VerifyDiagnostics) Res.push_back("-verify"); - if (Opts.BinaryOutput) - Res.push_back("-fdiagnostics-binary"); if (Opts.ShowOptionNames) Res.push_back("-fdiagnostics-show-option"); if (Opts.ShowCategories == 1) @@ -960,7 +958,6 @@ static void ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits); Opts.VerifyDiagnostics = Args.hasArg(OPT_verify); - Opts.BinaryOutput = Args.hasArg(OPT_fdiagnostics_binary); Opts.ErrorLimit = Args.getLastArgIntValue(OPT_ferror_limit, 0, Diags); Opts.MacroBacktraceLimit = Args.getLastArgIntValue(OPT_fmacro_backtrace_limit, diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp index 531992efeb..85f451e855 100644 --- a/tools/libclang/CIndexDiagnostic.cpp +++ b/tools/libclang/CIndexDiagnostic.cpp @@ -217,56 +217,3 @@ CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, unsigned FixIt, } } // end extern "C" - -void clang::LoadSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath, - unsigned num_unsaved_files, - struct CXUnsavedFile *unsaved_files, - FileManager &FileMgr, - SourceManager &SourceMgr, - SmallVectorImpl &Diags) { - using llvm::MemoryBuffer; - using llvm::StringRef; - MemoryBuffer *F = MemoryBuffer::getFile(DiagnosticsPath.c_str()); - if (!F) - return; - - // Enter the unsaved files into the file manager. - for (unsigned I = 0; I != num_unsaved_files; ++I) { - const FileEntry *File = FileMgr.getVirtualFile(unsaved_files[I].Filename, - unsaved_files[I].Length, - 0); - if (!File) { - // FIXME: Hard to localize when we have no diagnostics engine! - Diags.push_back(StoredDiagnostic(Diagnostic::Fatal, - (Twine("could not remap from missing file ") + - unsaved_files[I].Filename).str())); - delete F; - return; - } - - MemoryBuffer *Buffer - = MemoryBuffer::getMemBuffer(unsaved_files[I].Contents, - unsaved_files[I].Contents + unsaved_files[I].Length); - if (!Buffer) { - delete F; - return; - } - - SourceMgr.overrideFileContents(File, Buffer); - SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User); - } - - // Parse the diagnostics, emitting them one by one until we've - // exhausted the data. - StringRef Buffer = F->getBuffer(); - const char *Memory = Buffer.data(), *MemoryEnd = Memory + Buffer.size(); - while (Memory != MemoryEnd) { - StoredDiagnostic Stored = StoredDiagnostic::Deserialize(FileMgr, SourceMgr, - Memory, MemoryEnd); - if (!Stored) - break; - - Diags.push_back(Stored); - } - delete F; -} diff --git a/tools/libclang/CIndexDiagnostic.h b/tools/libclang/CIndexDiagnostic.h index 919c21cfdb..0d935fae66 100644 --- a/tools/libclang/CIndexDiagnostic.h +++ b/tools/libclang/CIndexDiagnostic.h @@ -13,21 +13,10 @@ #ifndef LLVM_CLANG_CINDEX_DIAGNOSTIC_H #define LLVM_CLANG_CINDEX_DIAGNOSTIC_H -struct CXUnsavedFile; - -namespace llvm { -template class SmallVectorImpl; -namespace sys { class Path; } -} - namespace clang { -class Diagnostic; -class FileManager; class LangOptions; -class Preprocessor; class StoredDiagnostic; -class SourceManager; /// \brief The storage behind a CXDiagnostic struct CXStoredDiagnostic { @@ -38,15 +27,6 @@ struct CXStoredDiagnostic { const LangOptions &LangOpts) : Diag(Diag), LangOpts(LangOpts) { } }; - -/// \brief Given the path to a file that contains binary, serialized -/// diagnostics produced by Clang, load those diagnostics. -void LoadSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath, - unsigned num_unsaved_files, - struct CXUnsavedFile *unsaved_files, - FileManager &FileMgr, - SourceManager &SourceMgr, - llvm::SmallVectorImpl &Diags); } // end namespace clang