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()) {