[cfe-commits] r137813 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
Jordy Rose
jediknil at belkadan.com
Tue Aug 16 21:56:03 PDT 2011
Author: jrose
Date: Tue Aug 16 23:56:03 2011
New Revision: 137813
URL: http://llvm.org/viewvc/llvm-project?rev=137813&view=rev
Log:
[analyzer] Add a warning for an incompatible plugin version.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=137813&r1=137812&r2=137813&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Tue Aug 16 23:56:03 2011
@@ -293,4 +293,8 @@
def warn_unkwown_analyzer_checker : Warning<
"no analyzer checkers are associated with '%0'">;
+def warn_incompatible_analyzer_plugin_api : Warning<
+ "checker plugin '%0' is not compatible with this version of the analyzer">;
+def note_incompatible_analyzer_plugin_api : Note<
+ "current API version is '%0', but plugin was compiled with version '%1'">;
}
Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=137813&r1=137812&r2=137813&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Tue Aug 16 23:56:03 2011
@@ -21,6 +21,7 @@
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallVector.h"
@@ -32,15 +33,19 @@
namespace {
class ClangCheckerRegistry : public CheckerRegistry {
typedef void (*RegisterCheckersFn)(CheckerRegistry &);
-public:
- ClangCheckerRegistry(ArrayRef<std::string> plugins);
static bool isCompatibleAPIVersion(const char *versionString);
+ static void warnIncompatible(Diagnostic *diags, StringRef pluginPath,
+ const char *pluginAPIVersion);
+
+public:
+ ClangCheckerRegistry(ArrayRef<std::string> plugins, Diagnostic *diags = 0);
};
} // end anonymous namespace
-ClangCheckerRegistry::ClangCheckerRegistry(ArrayRef<std::string> plugins) {
+ClangCheckerRegistry::ClangCheckerRegistry(ArrayRef<std::string> plugins,
+ Diagnostic *diags) {
registerBuiltinCheckers(*this);
for (ArrayRef<std::string>::iterator i = plugins.begin(), e = plugins.end();
@@ -51,8 +56,10 @@
// See if it's compatible with this build of clang.
const char *pluginAPIVersion =
(const char *) lib.getAddressOfSymbol("clang_analyzerAPIVersionString");
- if (!isCompatibleAPIVersion(pluginAPIVersion))
+ if (!isCompatibleAPIVersion(pluginAPIVersion)) {
+ warnIncompatible(diags, *i, pluginAPIVersion);
continue;
+ }
// Register its checkers.
RegisterCheckersFn registerPluginCheckers =
@@ -73,10 +80,24 @@
if (strcmp(versionString, CLANG_ANALYZER_API_VERSION_STRING) == 0)
return true;
- // FIXME: Should we emit a diagnostic if the version doesn't match?
return false;
}
+void ClangCheckerRegistry::warnIncompatible(Diagnostic *diags,
+ StringRef pluginPath,
+ const char *pluginAPIVersion) {
+ if (!diags)
+ return;
+ if (!pluginAPIVersion)
+ return;
+
+ diags->Report(diag::warn_incompatible_analyzer_plugin_api)
+ << llvm::sys::path::filename(pluginPath);
+ diags->Report(diag::note_incompatible_analyzer_plugin_api)
+ << CLANG_ANALYZER_API_VERSION_STRING
+ << pluginAPIVersion;
+}
+
CheckerManager *ento::createCheckerManager(const AnalyzerOptions &opts,
const LangOptions &langOpts,
@@ -90,7 +111,8 @@
checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
}
- ClangCheckerRegistry(plugins).initializeManager(*checkerMgr, checkerOpts);
+ ClangCheckerRegistry allCheckers(plugins, &diags);
+ allCheckers.initializeManager(*checkerMgr, checkerOpts);
checkerMgr->finishedCheckerRegistration();
for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) {
More information about the cfe-commits
mailing list