MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkClang

Method checkClang

lib/cppcheck.cpp:669–786  ·  view source on GitHub ↗

TODO: clear error list before returning

Source from the content-addressed store, hash-verified

667
668// TODO: clear error list before returning
669unsigned int CppCheck::checkClang(const FileWithDetails &file)
670{
671 // TODO: clear exitcode
672
673 if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
674 mUnusedFunctionsCheck.reset(new CheckUnusedFunctions());
675
676 if (!mSettings.quiet)
677 mErrorLogger.reportOut(std::string("Checking ") + file.spath() + " ...", Color::FgGreen);
678
679 // TODO: get language from FileWithDetails object
680 std::string clangStderr;
681 if (!mSettings.buildDir.empty())
682 clangStderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, file.spath(), "", file.fsFileId()) + ".clang-stderr";
683
684 std::string exe = mSettings.clangExecutable;
685#ifdef _WIN32
686 // append .exe if it is not a path
687 if (Path::fromNativeSeparators(mSettings.clangExecutable).find('/') == std::string::npos) {
688 exe += ".exe";
689 }
690#endif
691
692 const std::string args2 = "-fsyntax-only -Xclang -ast-dump -fno-color-diagnostics " +
693 getClangFlags(mSettings, file.lang()) +
694 file.spath();
695 const std::string redirect2 = clangStderr.empty() ? "2>&1" : ("2> " + clangStderr);
696 if (mSettings.verbose && !mSettings.quiet) {
697 mErrorLogger.reportOut(exe + " " + args2, Color::Reset);
698 }
699
700 if (!mExecuteCommand) {
701 std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no command callback provided)" << std::endl;
702 return 0; // TODO: report as failure?
703 }
704
705 std::string output2;
706 const int exitcode = mExecuteCommand(exe,split(args2),redirect2,output2);
707 if (mSettings.debugClangOutput) {
708 std::cout << output2 << std::endl;
709 }
710 // TODO: this might also fail if compiler errors are encountered - we should report them properly
711 if (exitcode != EXIT_SUCCESS) {
712 // TODO: report as proper error
713 std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (exitcode: " << exitcode << " / output: " << output2 << ")" << std::endl;
714 return 0; // TODO: report as failure?
715 }
716
717 if (output2.find("TranslationUnitDecl") == std::string::npos) {
718 // TODO: report as proper error
719 std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no TranslationUnitDecl in output)" << std::endl;
720 return 0; // TODO: report as failure?
721 }
722
723 const auto reportError = [this](const ErrorMessage& errorMessage) {
724 mErrorLogger.reportErr(errorMessage);
725 };
726

Callers

nothing calls this directly

Calls 15

getClangFlagsFunction · 0.85
splitFunction · 0.85
reportClangErrorsFunction · 0.85
setValuesFunction · 0.85
createDumpFileFunction · 0.85
fsFileIdMethod · 0.80
langMethod · 0.80
appendFileIfNewMethod · 0.80
printDebugOutputMethod · 0.80
getfileMethod · 0.80
frontMethod · 0.80
exitcodeMethod · 0.80

Tested by

no test coverage detected