From c0c9d1dbf92f862555fd0339f6c70c09680cbd6d Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Tue, 9 Jun 2020 23:30:55 -0700 Subject: [PATCH] Copybara import of the project: -- fd2e99fa87c34f2fb1a20052c030ad7a4139b4e1 by Christian Blichmann : Support LLVM >= 7.0.1 in Clang based header generator This change glosses over small API changes introduced since LLVM/Clang 7.0.1, which ships with Debian Stable "Buster". Ubuntu 18.04 LTS "Bionic" also shipped this (and subsequently updated to version 9). Hence, compiling the generator should now work on all reasonable Debian based distributions. COPYBARA_INTEGRATE_REVIEW=https://github.com/google/sandboxed-api/pull/44 from cblichmann:20200609-llvm-version-compat fd2e99fa87c34f2fb1a20052c030ad7a4139b4e1 PiperOrigin-RevId: 315637014 Change-Id: I6585041d8bebade15e44c057b1a69287bbc0e733 --- sandboxed_api/tools/clang_generator/CMakeLists.txt | 5 ++++- sandboxed_api/tools/clang_generator/generator.h | 7 +++++++ sandboxed_api/tools/clang_generator/types.cc | 14 +++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sandboxed_api/tools/clang_generator/CMakeLists.txt b/sandboxed_api/tools/clang_generator/CMakeLists.txt index f0e59a2..0f38c15 100644 --- a/sandboxed_api/tools/clang_generator/CMakeLists.txt +++ b/sandboxed_api/tools/clang_generator/CMakeLists.txt @@ -12,9 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Minimum supported: LLVM 9 +# Minimum supported: LLVM 7.0.1 find_package(LLVM REQUIRED) find_package(Clang REQUIRED) +if(LLVM_VERSION VERSION_LESS "7.0.1") + message(FATAL_ERROR "SAPI header generator needs LLVM 7.0.1 or newer") +endif() add_library(sapi_generator diagnostics.cc diff --git a/sandboxed_api/tools/clang_generator/generator.h b/sandboxed_api/tools/clang_generator/generator.h index dc1636b..24e2658 100644 --- a/sandboxed_api/tools/clang_generator/generator.h +++ b/sandboxed_api/tools/clang_generator/generator.h @@ -18,6 +18,7 @@ #include #include "absl/container/flat_hash_set.h" +#include "absl/memory/memory.h" #include "absl/status/status.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/RecursiveASTVisitor.h" @@ -111,9 +112,15 @@ class GeneratorFactory : public clang::tooling::FrontendActionFactory { : options_(std::move(options)) {} private: +#if LLVM_VERSION_MAJOR >= 10 + std::unique_ptr create() override { + return absl::make_unique(&options_); + } +#else clang::FrontendAction* create() override { return new GeneratorAction(&options_); } +#endif GeneratorOptions options_; }; diff --git a/sandboxed_api/tools/clang_generator/types.cc b/sandboxed_api/tools/clang_generator/types.cc index 67044ae..4d91499 100644 --- a/sandboxed_api/tools/clang_generator/types.cc +++ b/sandboxed_api/tools/clang_generator/types.cc @@ -17,6 +17,18 @@ #include "absl/strings/str_cat.h" namespace sapi { +namespace { + +bool IsFunctionReferenceType(clang::QualType qual) { +#if LLVM_VERSION_MAJOR >= 9 + return qual->isFunctionReferenceType(); +#else + const auto* ref = qual->getAs(); + return ref && ref->getPointeeType()->isFunctionType(); +#endif +} + +} // namespace void GatherRelatedTypes(clang::QualType qual, QualTypeSet* types) { if (const auto* typedef_type = qual->getAs()) { @@ -25,7 +37,7 @@ void GatherRelatedTypes(clang::QualType qual, QualTypeSet* types) { return; } - if (qual->isFunctionPointerType() || qual->isFunctionReferenceType() || + if (qual->isFunctionPointerType() || IsFunctionReferenceType(qual) || qual->isMemberFunctionPointerType()) { if (const auto* function_type = qual->getPointeeOrArrayElementType() ->getAs()) {