std::unique_ptr<CheckerManager> ento::createCheckerManager( ASTContext &context, AnalyzerOptions &opts, ArrayRef<std::string> plugins, ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns, DiagnosticsEngine &diags) { auto checkerMgr = llvm::make_unique<CheckerManager>(context, opts); SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(opts); ClangCheckerRegistry allCheckers(plugins, &diags); for (const auto &Fn : checkerRegistrationFns) Fn(allCheckers); allCheckers.initializeManager(*checkerMgr, checkerOpts); allCheckers.validateCheckerOptions(opts, diags); checkerMgr->finishedCheckerRegistration(); for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) { if (checkerOpts[i].isUnclaimed()) { diags.Report(diag::err_unknown_analyzer_checker) << checkerOpts[i].getName(); diags.Report(diag::note_suggest_disabling_all_checkers); } } return checkerMgr; }
bool Bytecode::Finalize(DiagnosticsEngine& diags) { for (std::vector<Fixup>::iterator i=m_fixed_fixups.begin(), end=m_fixed_fixups.end(); i != end; ++i) { if (!i->Finalize(diags, i->isJumpTarget() ? diag::err_too_complex_jump : diag::err_too_complex_expression)) return false; if (i->isJumpTarget() && i->isComplexRelative()) { diags.Report(i->getSource().getBegin(), diag::err_invalid_jump_target); return false; } // Do curpos subtraction for IP-relative flagged values. if (i->isIPRelative()) { Location sub_loc = {this, i->getOffset()}; if (!i->SubRelative(m_container->getSection()->getObject(), sub_loc)) diags.Report(i->getSource().getBegin(), diag::err_too_complex_expression); } } if (m_contents.get() != 0) return m_contents->Finalize(*this, diags); return true; }
void clang::EmitBackendOutput(DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts, const clang::TargetOptions &TOpts, const LangOptions &LOpts, const llvm::DataLayout &TDesc, Module *M, BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS) { if (!CGOpts.ThinLTOIndexFile.empty()) { runThinLTOBackend(CGOpts, M, std::move(OS)); return; } EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, LOpts, M); AsmHelper.EmitAssembly(Action, std::move(OS)); // Verify clang's TargetInfo DataLayout against the LLVM TargetMachine's // DataLayout. if (AsmHelper.TM) { std::string DLDesc = M->getDataLayout().getStringRepresentation(); if (DLDesc != TDesc.getStringRepresentation()) { unsigned DiagID = Diags.getCustomDiagID( DiagnosticsEngine::Error, "backend data layout '%0' does not match " "expected target description '%1'"); Diags.Report(DiagID) << DLDesc << TDesc.getStringRepresentation(); } } }
std::unique_ptr<CheckerManager> ento::createCheckerManager(AnalyzerOptions &opts, const LangOptions &langOpts, ArrayRef<std::string> plugins, DiagnosticsEngine &diags) { std::unique_ptr<CheckerManager> checkerMgr( new CheckerManager(langOpts, &opts)); SmallVector<CheckerOptInfo, 8> checkerOpts; for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) { const std::pair<std::string, bool> &opt = opts.CheckersControlList[i]; checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second)); } ClangCheckerRegistry allCheckers(plugins, &diags); allCheckers.initializeManager(*checkerMgr, checkerOpts); checkerMgr->finishedCheckerRegistration(); for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) { if (checkerOpts[i].isUnclaimed()) { diags.Report(diag::err_unknown_analyzer_checker) << checkerOpts[i].getName(); diags.Report(diag::note_suggest_disabling_all_checkers); } } return checkerMgr; }
bool C2Builder::checkMainFunction(DiagnosticsEngine& Diags) { assert(mainComponent); Decl* mainDecl = 0; const ModuleList& mods = mainComponent->getModules(); for (unsigned m=0; m<mods.size(); m++) { const Module* M = mods[m]; Decl* decl = M->findSymbol("main"); if (decl) { if (mainDecl) { // TODO multiple main functions } else { mainDecl = decl; } } } if (recipe.type == Component::EXECUTABLE) { // bin: must have main if (options.testMode) return true; if (!mainDecl) { Diags.Report(diag::err_main_missing); return false; } } else { // lib: cannot have main if (mainDecl) { Diags.Report(mainDecl->getLocation(), diag::err_lib_has_main); return false; } } return true; }
static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts, const CodeGenOptions *CodeGenOpts, DiagnosticsEngine &Diags) { std::string ErrorInfo; bool OwnsStream = false; raw_ostream *OS = &llvm::errs(); if (DiagOpts->DiagnosticLogFile != "-") { // Create the output stream. llvm::raw_fd_ostream *FileOS( new llvm::raw_fd_ostream(DiagOpts->DiagnosticLogFile.c_str(), ErrorInfo, llvm::raw_fd_ostream::F_Append)); if (!ErrorInfo.empty()) { Diags.Report(diag::warn_fe_cc_log_diagnostics_failure) << DiagOpts->DumpBuildInformation << ErrorInfo; } else { FileOS->SetUnbuffered(); FileOS->SetUseAtomicWrites(true); OS = FileOS; OwnsStream = true; } } // Chain in the diagnostic client which will log the diagnostics. LogDiagnosticPrinter *Logger = new LogDiagnosticPrinter(*OS, DiagOpts, OwnsStream); if (CodeGenOpts) Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags); Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(), Logger)); }
bool FileRemapper::report(const Twine &err, DiagnosticsEngine &Diag) { SmallString<128> buf; unsigned ID = Diag.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Error, err.toStringRef(buf)); Diag.Report(ID); return true; }
bool CompilerInstance::InitializeSourceManager(StringRef InputFile, SrcMgr::CharacteristicKind Kind, DiagnosticsEngine &Diags, FileManager &FileMgr, SourceManager &SourceMgr, const FrontendOptions &Opts) { // Figure out where to get and map in the main file. if (InputFile != "-") { const FileEntry *File = FileMgr.getFile(InputFile); if (!File) { Diags.Report(diag::err_fe_error_reading) << InputFile; return false; } SourceMgr.createMainFileID(File, Kind); } else { OwningPtr<llvm::MemoryBuffer> SB; if (llvm::MemoryBuffer::getSTDIN(SB)) { // FIXME: Give ec.message() in this diag. Diags.Report(diag::err_fe_error_reading_stdin); return false; } const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(), SB->getBufferSize(), 0); SourceMgr.createMainFileID(File, Kind); SourceMgr.overrideFileContents(File, SB.take()); } assert(!SourceMgr.getMainFileID().isInvalid() && "Couldn't establish MainFileID!"); return true; }
// Initialize the remapping of files to alternative contents, e.g., // those specified through other files. static void InitializeFileRemapping(DiagnosticsEngine &Diags, SourceManager &SourceMgr, FileManager &FileMgr, const PreprocessorOptions &InitOpts) { // Remap files in the source manager (with buffers). for (PreprocessorOptions::const_remapped_file_buffer_iterator Remap = InitOpts.remapped_file_buffer_begin(), RemapEnd = InitOpts.remapped_file_buffer_end(); Remap != RemapEnd; ++Remap) { // Create the file entry for the file that we're mapping from. const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first, Remap->second->getBufferSize(), 0); if (!FromFile) { Diags.Report(diag::err_fe_remap_missing_from_file) << Remap->first; if (!InitOpts.RetainRemappedFileBuffers) delete Remap->second; continue; } // Override the contents of the "from" file with the contents of // the "to" file. SourceMgr.overrideFileContents(FromFile, Remap->second, InitOpts.RetainRemappedFileBuffers); } // Remap files in the source manager (with other files). for (PreprocessorOptions::const_remapped_file_iterator Remap = InitOpts.remapped_file_begin(), RemapEnd = InitOpts.remapped_file_end(); Remap != RemapEnd; ++Remap) { // Find the file that we're mapping to. const FileEntry *ToFile = FileMgr.getFile(Remap->second); if (!ToFile) { Diags.Report(diag::err_fe_remap_missing_to_file) << Remap->first << Remap->second; continue; } // Create the file entry for the file that we're mapping from. const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first, ToFile->getSize(), 0); if (!FromFile) { Diags.Report(diag::err_fe_remap_missing_from_file) << Remap->first; continue; } // Override the contents of the "from" file with the contents of // the "to" file. SourceMgr.overrideFileContents(FromFile, ToFile); } SourceMgr.setOverridenFilesKeepOriginalName( InitOpts.RemappedFilesKeepOriginalName); }
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, DiagnosticsEngine &Diags, FileManager &FileMgr, SourceManager &SourceMgr, const FrontendOptions &Opts) { SrcMgr::CharacteristicKind Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User; if (Input.isBuffer()) { SourceMgr.createMainFileIDForMemBuffer(Input.getBuffer(), Kind); assert(!SourceMgr.getMainFileID().isInvalid() && "Couldn't establish MainFileID!"); return true; } StringRef InputFile = Input.getFile(); // Figure out where to get and map in the main file. if (InputFile != "-") { const FileEntry *File = FileMgr.getFile(InputFile); if (!File) { Diags.Report(diag::err_fe_error_reading) << InputFile; return false; } // The natural SourceManager infrastructure can't currently handle named // pipes, but we would at least like to accept them for the main // file. Detect them here, read them with the more generic MemoryBuffer // function, and simply override their contents as we do for STDIN. if (File->isNamedPipe()) { OwningPtr<llvm::MemoryBuffer> MB; if (llvm::error_code ec = llvm::MemoryBuffer::getFile(InputFile, MB)) { Diags.Report(diag::err_cannot_open_file) << InputFile << ec.message(); return false; } // Create a new virtual file that will have the correct size. File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0); SourceMgr.overrideFileContents(File, MB.take()); } SourceMgr.createMainFileID(File, Kind); } else { OwningPtr<llvm::MemoryBuffer> SB; if (llvm::MemoryBuffer::getSTDIN(SB)) { // FIXME: Give ec.message() in this diag. Diags.Report(diag::err_fe_error_reading_stdin); return false; } const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(), SB->getBufferSize(), 0); SourceMgr.createMainFileID(File, Kind); SourceMgr.overrideFileContents(File, SB.take()); } assert(!SourceMgr.getMainFileID().isInvalid() && "Couldn't establish MainFileID!"); return true; }
VerifyDiagnosticConsumer::VerifyDiagnosticConsumer(DiagnosticsEngine &Diags) : Diags(Diags), PrimaryClient(Diags.getClient()), OwnsPrimaryClient(Diags.ownsClient()), Buffer(new TextDiagnosticBuffer()), SrcManager(0), Status(HasNoDirectives) { Diags.takeClient(); assert(Diags.hasSourceManager()); setSourceManager(Diags.getSourceManager()); }
FixItRewriter::FixItRewriter(DiagnosticsEngine &Diags, SourceManager &SourceMgr, const LangOptions &LangOpts, FixItOptions *FixItOpts) : Diags(Diags), Rewrite(SourceMgr, LangOpts), FixItOpts(FixItOpts), NumFailures(0), PrevDiagSilenced(false) { OwnsClient = Diags.ownsClient(); Client = Diags.takeClient(); Diags.setClient(this); }
void clang::EmitBackendOutput(DiagnosticsEngine &Diags, const HeaderSearchOptions &HeaderOpts, const CodeGenOptions &CGOpts, const clang::TargetOptions &TOpts, const LangOptions &LOpts, const llvm::DataLayout &TDesc, Module *M, BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS) { if (!CGOpts.ThinLTOIndexFile.empty()) { // If we are performing a ThinLTO importing compile, load the function index // into memory and pass it into runThinLTOBackend, which will run the // function importer and invoke LTO passes. Expected<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr = llvm::getModuleSummaryIndexForFile(CGOpts.ThinLTOIndexFile, /*IgnoreEmptyThinLTOIndexFile*/true); if (!IndexOrErr) { logAllUnhandledErrors(IndexOrErr.takeError(), errs(), "Error loading index file '" + CGOpts.ThinLTOIndexFile + "': "); return; } std::unique_ptr<ModuleSummaryIndex> CombinedIndex = std::move(*IndexOrErr); // A null CombinedIndex means we should skip ThinLTO compilation // (LLVM will optionally ignore empty index files, returning null instead // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; if (DoThinLTOBackend) { runThinLTOBackend(CombinedIndex.get(), M, HeaderOpts, CGOpts, TOpts, LOpts, std::move(OS), CGOpts.SampleProfileFile, Action); return; } } EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M); if (CGOpts.ExperimentalNewPassManager) AsmHelper.EmitAssemblyWithNewPassManager(Action, std::move(OS)); else AsmHelper.EmitAssembly(Action, std::move(OS)); // Verify clang's TargetInfo DataLayout against the LLVM TargetMachine's // DataLayout. if (AsmHelper.TM) { std::string DLDesc = M->getDataLayout().getStringRepresentation(); if (DLDesc != TDesc.getStringRepresentation()) { unsigned DiagID = Diags.getCustomDiagID( DiagnosticsEngine::Error, "backend data layout '%0' does not match " "expected target description '%1'"); Diags.Report(DiagID) << DLDesc << TDesc.getStringRepresentation(); } } }
// EmitUnknownDiagWarning - Emit a warning and typo hint for unknown warning opts static void EmitUnknownDiagWarning(DiagnosticsEngine &Diags, StringRef Prefix, StringRef Opt, bool isPositive) { StringRef Suggestion = DiagnosticIDs::getNearestWarningOption(Opt); if (!Suggestion.empty()) Diags.Report(isPositive? diag::warn_unknown_warning_option_suggest : diag::warn_unknown_negative_warning_option_suggest) << (Prefix.str() += Opt) << (Prefix.str() += Suggestion); else Diags.Report(isPositive? diag::warn_unknown_warning_option : diag::warn_unknown_negative_warning_option) << (Prefix.str() += Opt); }
bool yasm::CalcFloat(APFloat* lhs, Op::Op op, const APFloat& rhs, SourceLocation source, DiagnosticsEngine& diags) { APFloat::opStatus status; switch (op) { case Op::ADD: status = lhs->add(rhs, APFloat::rmNearestTiesToEven); break; case Op::SUB: status = lhs->subtract(rhs, APFloat::rmNearestTiesToEven); break; case Op::MUL: status = lhs->multiply(rhs, APFloat::rmNearestTiesToEven); break; case Op::DIV: case Op::SIGNDIV: status = lhs->divide(rhs, APFloat::rmNearestTiesToEven); break; case Op::MOD: case Op::SIGNMOD: status = lhs->mod(rhs, APFloat::rmNearestTiesToEven); break; default: status = APFloat::opInvalidOp; break; } if (status & APFloat::opInvalidOp) { diags.Report(source, diag::err_float_invalid_op); return false; } if (status & APFloat::opDivByZero) { diags.Report(source, diag::err_divide_by_zero); return false; } if (status & APFloat::opOverflow) diags.Report(source, diag::warn_float_overflow); else if (status & APFloat::opUnderflow) diags.Report(source, diag::warn_float_underflow); else if (status & APFloat::opInexact) diags.Report(source, diag::warn_float_inexact); return true; }
/// \brief Takes a list of diagnostics that have been generated but not matched /// by an expected-* directive and produces a diagnostic to the user from this. static unsigned PrintUnexpected(DiagnosticsEngine &Diags, const llvm::SourceMgr *SourceMgr, const_diag_iterator diag_begin, const_diag_iterator diag_end, DiagnosticsEngine::Level Kind) { if (diag_begin == diag_end) return 0; for (const_diag_iterator I = diag_begin, E = diag_end; I != E; ++I) { switch(Kind) { case DiagnosticsEngine::Error: Diags.ReportError(I->first,I->second); break; case DiagnosticsEngine::Warning: Diags.ReportWarning(I->first,I->second); break; case DiagnosticsEngine::Note: Diags.ReportNote(I->first,I->second); break; default: break; } } return std::distance(diag_begin, diag_end); }
/// Takes a list of diagnostics that have been generated but not matched /// by an expected-* directive and produces a diagnostic to the user from this. static unsigned PrintUnexpected(DiagnosticsEngine &Diags, SourceManager *SourceMgr, const_diag_iterator diag_begin, const_diag_iterator diag_end, const char *Kind) { if (diag_begin == diag_end) return 0; SmallString<256> Fmt; llvm::raw_svector_ostream OS(Fmt); for (const_diag_iterator I = diag_begin, E = diag_end; I != E; ++I) { if (I->first.isInvalid() || !SourceMgr) OS << "\n (frontend)"; else { OS << "\n "; if (const FileEntry *File = SourceMgr->getFileEntryForID( SourceMgr->getFileID(I->first))) OS << " File " << File->getName(); OS << " Line " << SourceMgr->getPresumedLineNumber(I->first); } OS << ": " << I->second; } Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit() << Kind << /*Unexpected=*/true << OS.str(); return std::distance(diag_begin, diag_end); }
/// Takes a list of diagnostics that were expected to have been generated /// but were not and produces a diagnostic to the user from this. static unsigned PrintExpected(DiagnosticsEngine &Diags, SourceManager &SourceMgr, std::vector<Directive *> &DL, const char *Kind) { if (DL.empty()) return 0; SmallString<256> Fmt; llvm::raw_svector_ostream OS(Fmt); for (const auto *D : DL) { if (D->DiagnosticLoc.isInvalid()) OS << "\n File *"; else OS << "\n File " << SourceMgr.getFilename(D->DiagnosticLoc); if (D->MatchAnyLine) OS << " Line *"; else OS << " Line " << SourceMgr.getPresumedLineNumber(D->DiagnosticLoc); if (D->DirectiveLoc != D->DiagnosticLoc) OS << " (directive at " << SourceMgr.getFilename(D->DirectiveLoc) << ':' << SourceMgr.getPresumedLineNumber(D->DirectiveLoc) << ')'; OS << ": " << D->Text; } Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit() << Kind << /*Unexpected=*/false << OS.str(); return DL.size(); }
/// CheckResults - This compares the expected results to those that /// were actually reported. It emits any discrepencies. Return "true" if there /// were problems. Return "false" otherwise. static unsigned CheckResults(DiagnosticsEngine &Diags, SourceManager &SourceMgr, const TextDiagnosticBuffer &Buffer, ExpectedData &ED) { // We want to capture the delta between what was expected and what was // seen. // // Expected \ Seen - set expected but not seen // Seen \ Expected - set seen but not expected unsigned NumProblems = 0; const DiagnosticLevelMask DiagMask = Diags.getDiagnosticOptions().getVerifyIgnoreUnexpected(); // See if there are error mismatches. NumProblems += CheckLists(Diags, SourceMgr, "error", ED.Errors, Buffer.err_begin(), Buffer.err_end(), bool(DiagnosticLevelMask::Error & DiagMask)); // See if there are warning mismatches. NumProblems += CheckLists(Diags, SourceMgr, "warning", ED.Warnings, Buffer.warn_begin(), Buffer.warn_end(), bool(DiagnosticLevelMask::Warning & DiagMask)); // See if there are remark mismatches. NumProblems += CheckLists(Diags, SourceMgr, "remark", ED.Remarks, Buffer.remark_begin(), Buffer.remark_end(), bool(DiagnosticLevelMask::Remark & DiagMask)); // See if there are note mismatches. NumProblems += CheckLists(Diags, SourceMgr, "note", ED.Notes, Buffer.note_begin(), Buffer.note_end(), bool(DiagnosticLevelMask::Note & DiagMask)); return NumProblems; }
// EmitUnknownDiagWarning - Emit a warning and typo hint for unknown warning // opts static void EmitUnknownDiagWarning(DiagnosticsEngine &Diags, diag::Flavor Flavor, StringRef Prefix, StringRef Opt) { StringRef Suggestion = DiagnosticIDs::getNearestOption(Flavor, Opt); Diags.Report(diag::warn_unknown_diag_option) << (Flavor == diag::Flavor::WarningOrError ? 0 : 1) << (Prefix.str() += Opt) << !Suggestion.empty() << (Prefix.str() += Suggestion); }
bool MipsTargetInfo::validateTarget(DiagnosticsEngine &Diags) const { // microMIPS64R6 backend was removed. if ((getTriple().getArch() == llvm::Triple::mips64 || getTriple().getArch() == llvm::Triple::mips64el) && IsMicromips && (ABI == "n32" || ABI == "n64")) { Diags.Report(diag::err_target_unsupported_cpu_for_micromips) << CPU; return false; } // FIXME: It's valid to use O32 on a 64-bit CPU but the backend can't handle // this yet. It's better to fail here than on the backend assertion. if (processorSupportsGPR64() && ABI == "o32") { Diags.Report(diag::err_target_unsupported_abi) << ABI << CPU; return false; } // 64-bit ABI's require 64-bit CPU's. if (!processorSupportsGPR64() && (ABI == "n32" || ABI == "n64")) { Diags.Report(diag::err_target_unsupported_abi) << ABI << CPU; return false; } // FIXME: It's valid to use O32 on a mips64/mips64el triple but the backend // can't handle this yet. It's better to fail here than on the // backend assertion. if ((getTriple().getArch() == llvm::Triple::mips64 || getTriple().getArch() == llvm::Triple::mips64el) && ABI == "o32") { Diags.Report(diag::err_target_unsupported_abi_for_triple) << ABI << getTriple().str(); return false; } // FIXME: It's valid to use N32/N64 on a mips/mipsel triple but the backend // can't handle this yet. It's better to fail here than on the // backend assertion. if ((getTriple().getArch() == llvm::Triple::mips || getTriple().getArch() == llvm::Triple::mipsel) && (ABI == "n32" || ABI == "n64")) { Diags.Report(diag::err_target_unsupported_abi_for_triple) << ABI << getTriple().str(); return false; } return true; }
/// \brief Return true with a diagnostic if the file that MSVC would have found /// fails to match the one that Clang would have found with MSVC header search /// disabled. static bool checkMSVCHeaderSearch(DiagnosticsEngine &Diags, const FileEntry *MSFE, const FileEntry *FE, SourceLocation IncludeLoc) { if (MSFE && FE != MSFE) { Diags.Report(IncludeLoc, diag::ext_pp_include_search_ms) << MSFE->getName(); return true; } return false; }
bool HtTpg::areAllSgConnected(DiagnosticsEngine &diag) { // fill in connections where possible bool bProgress; do { bProgress = false; for (size_t i = 0; i < m_sgNameList.size(); i += 1) { for (size_t j = 0; j < m_sgNameList.size(); j += 1) { if (getUrsDelta(i, j) != RS_DELTA_UNKNOWN) continue; for (size_t k = 0; k < m_sgNameList.size(); k += 1) { if (getUrsDelta(i, k) == RS_DELTA_UNKNOWN || getUrsDelta(k, j) == RS_DELTA_UNKNOWN) continue; int delta = getUrsDelta(i, k) + getUrsDelta(k, j); setUrsDelta(i, j, delta); setUrsDelta(j, i, -delta); bProgress = true; break; } } } } while (bProgress); // now check connectivity bool bFullyConnected = true; for (size_t i = 0; i < m_sgNameList.size(); i += 1) { for (size_t j = 0; j < i; j += 1) { if (m_pSgUrsMatrix[j * m_sgNameList.size() + i] == RS_DELTA_UNKNOWN) { bFullyConnected = false; char errorMsg[256]; sprintf(errorMsg, "subgroups of timing path group '%s' are not fully connected (%s and %s)", m_name.c_str(), m_sgNameList[j].c_str(), m_sgNameList[i].c_str()); unsigned DiagID = diag.getCustomDiagID(DiagnosticsEngine::Error, errorMsg); diag.Report(DiagID); } } } return bFullyConnected; }
static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts, DiagnosticsEngine &Diags, StringRef OutputFile) { std::string ErrorInfo; OwningPtr<llvm::raw_fd_ostream> OS; OS.reset(new llvm::raw_fd_ostream(OutputFile.str().c_str(), ErrorInfo, llvm::raw_fd_ostream::F_Binary)); if (!ErrorInfo.empty()) { Diags.Report(diag::warn_fe_serialized_diag_failure) << OutputFile << ErrorInfo; return; } DiagnosticConsumer *SerializedConsumer = clang::serialized_diags::create(OS.take(), DiagOpts); Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(), SerializedConsumer)); }
void clang::EmitBackendOutput(DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts, const clang::TargetOptions &TOpts, const LangOptions &LOpts, StringRef TDesc, Module *M, BackendAction Action, raw_pwrite_stream *OS) { EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, LOpts, M); AsmHelper.EmitAssembly(Action, OS); // If an optional clang TargetInfo description string was passed in, use it to // verify the LLVM TargetMachine's DataLayout. if (AsmHelper.TM && !TDesc.empty()) { std::string DLDesc = M->getDataLayout().getStringRepresentation(); if (DLDesc != TDesc) { unsigned DiagID = Diags.getCustomDiagID( DiagnosticsEngine::Error, "backend data layout '%0' does not match " "expected target description '%1'"); Diags.Report(DiagID) << DLDesc << TDesc; } } }
// Diagnostics static void SetUpBuildDumpLog(DiagnosticOptions *DiagOpts, unsigned argc, const char* const *argv, DiagnosticsEngine &Diags) { std::string ErrorInfo; OwningPtr<raw_ostream> OS( new llvm::raw_fd_ostream(DiagOpts->DumpBuildInformation.c_str(),ErrorInfo)); if (!ErrorInfo.empty()) { Diags.Report(diag::err_fe_unable_to_open_logfile) << DiagOpts->DumpBuildInformation << ErrorInfo; return; } (*OS) << "clang -cc1 command line arguments: "; for (unsigned i = 0; i != argc; ++i) (*OS) << argv[i] << ' '; (*OS) << '\n'; // Chain in a diagnostic client which will log the diagnostics. DiagnosticConsumer *Logger = new TextDiagnosticPrinter(*OS.take(), DiagOpts, /*OwnsOutputStream=*/true); Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(), Logger)); }
/// \brief Takes a list of diagnostics that were expected to have been generated /// but were not and produces a diagnostic to the user from this. static unsigned PrintExpected(DiagnosticsEngine &Diags, const llvm::SourceMgr &SourceMgr, DirectiveList &DL, DiagnosticsEngine::Level Kind) { if (DL.empty()) return 0; for (DirectiveList::iterator I = DL.begin(), E = DL.end(); I != E; ++I) { Directive &D = **I; Diags.ReportError(D.DirectiveLoc,llvm::Twine("Inconsistend verify directive: ")+D.Text); } return DL.size(); }
void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { for (const auto &I : All) { auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0")); switch (I.first) { default: llvm_unreachable( "Diagnostic not handled during diagnostic flushing!"); case DiagnosticsEngine::Note: Diag << Notes[I.second].second; break; case DiagnosticsEngine::Warning: Diag << Warnings[I.second].second; break; case DiagnosticsEngine::Remark: Diag << Remarks[I.second].second; break; case DiagnosticsEngine::Error: case DiagnosticsEngine::Fatal: Diag << Errors[I.second].second; break; } } }
void Directives::Impl::Dir::operator() (StringRef name, DirectiveInfo& info, DiagnosticsEngine& diags) { NameValues& namevals = info.getNameValues(); if ((m_flags & (ARG_REQUIRED|ID_REQUIRED)) && namevals.empty()) { diags.Report(info.getSource(), diag::err_directive_no_args); return; } if (!namevals.empty() && (m_flags & ID_REQUIRED) && !namevals.front().isId()) { diags.Report(info.getSource(), diag::err_value_id) << namevals.front().getValueRange(); return; } m_handler(info, diags); }
void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { // FIXME: Flush the diagnostics in order. for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0")) << it->second; for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, "%0")) << it->second; for (const_iterator it = remark_begin(), ie = remark_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Remark, "%0")) << it->second; for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0")) << it->second; }