From 5fb0dafcafbb34a503b301f807fb5c8a6efe326a Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 12 Dec 2019 20:25:05 -0800 Subject: clang-plugin: Support LLVM 9.0 The main difference here is that evalCall checkers have changed to take a CallEvent& parameter rather than a CallExpr* parameter. For version 9 we convert the CallEvent& into a CallExpr* as soon as we receive it. This may need to be refactored in the future, as CallEvent is the more modern API and covers syntax that CallExpr doesn't cover, but that is a large refactor better left for when it becomes necessary or when LLVM 9 becomes the minimum version. --- clang-plugin/gerror-checker.cpp | 12 +++++++++++- clang-plugin/gerror-checker.h | 9 ++++++++- configure.ac | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/clang-plugin/gerror-checker.cpp b/clang-plugin/gerror-checker.cpp index 8301a44..df9f5c7 100644 --- a/clang-plugin/gerror-checker.cpp +++ b/clang-plugin/gerror-checker.cpp @@ -505,9 +505,19 @@ GErrorChecker::checkPreCall (const CallEvent &call, /* Dispatch call-evaluation events to the different per-function handlers. * Return true iff the call was evaluated. */ bool -GErrorChecker::evalCall (const CallExpr *call, +GErrorChecker::evalCall ( +#ifdef HAVE_LLVM_9_0 + const CallEvent &call_event, +#else + const CallExpr *call, +#endif CheckerContext &context) const { +#ifdef HAVE_LLVM_9_0 + const CallExpr *call = llvm::dyn_cast(call_event.getOriginExpr()); + if (!call) + return false; +#endif const FunctionDecl *func_decl = context.getCalleeDecl (call); if (func_decl == NULL || diff --git a/clang-plugin/gerror-checker.h b/clang-plugin/gerror-checker.h index 5fdff0e..1d7ce80 100644 --- a/clang-plugin/gerror-checker.h +++ b/clang-plugin/gerror-checker.h @@ -23,6 +23,8 @@ #ifndef TARTAN_GERROR_CHECKER_H #define TARTAN_GERROR_CHECKER_H +#include "config.h" + #include #include #include @@ -159,7 +161,12 @@ private: public: void checkPreCall (const CallEvent &call, CheckerContext &context) const; - bool evalCall (const CallExpr *call, + bool evalCall ( +#ifdef HAVE_LLVM_9_0 + const CallEvent &call_event, +#else + const CallExpr *call, +#endif CheckerContext &context) const; void checkBind (SVal loc, SVal val, const Stmt *stmt, CheckerContext &context) const; diff --git a/configure.ac b/configure.ac index 89ef86a..ab6e12b 100644 --- a/configure.ac +++ b/configure.ac @@ -91,6 +91,9 @@ AC_DEFINE_UNQUOTED([LLVM_CONFIG_VERSION],"$llvm_version", AS_IF([test "$major" -ge 8],[ AC_DEFINE([HAVE_LLVM_8_0], [1], [Whether LLVM ≥ 8.0 is available]) ]) +AS_IF([test "$major" -ge 9],[ + AC_DEFINE([HAVE_LLVM_9_0], [1], [Whether LLVM ≥ 9.0 is available]) +]) # Clang dependency (e.g. the clang-devel package on Fedora) AC_LANG_PUSH([C++]) -- cgit v1.2.3