From 78fa850ddce624e71a5c6a3eced174a1f17a6cb8 Mon Sep 17 00:00:00 2001 From: Binrui Dong Date: Fri, 2 Feb 2024 19:50:50 +0800 Subject: [PATCH] Make clang-tidy plugin compatible with LLVM 17 --- tools/clang-tidy-plugin/CMakeLists.txt | 1 + tools/clang-tidy-plugin/LargeStackObjectCheck.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt index 59b1829a78cf8..c39e57a5f3b46 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt @@ -54,6 +54,7 @@ if (CATA_CLANG_TIDY_EXECUTABLE) else () set(CataAnalyzerName CataAnalyzerPlugin) add_library(${CataAnalyzerName} MODULE ${CataAnalyzerSrc}) + target_link_libraries(${CataAnalyzerName} PRIVATE clangTidy) endif () target_include_directories(${CataAnalyzerName} SYSTEM PRIVATE diff --git a/tools/clang-tidy-plugin/LargeStackObjectCheck.cpp b/tools/clang-tidy-plugin/LargeStackObjectCheck.cpp index ccd7d754d9e0d..9cfdfa9e41cc3 100644 --- a/tools/clang-tidy-plugin/LargeStackObjectCheck.cpp +++ b/tools/clang-tidy-plugin/LargeStackObjectCheck.cpp @@ -58,7 +58,11 @@ static void CheckDecl( LargeStackObjectCheck &Check, const MatchFinder::MatchRes return; } +#if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR >= 17 + if( std::optional VarSize = Result.Context->getTypeSizeInCharsIfKnown( T ) ) { +#else if( Optional VarSize = Result.Context->getTypeSizeInCharsIfKnown( T ) ) { +#endif int VarSize_KiB = *VarSize / CharUnits::fromQuantity( 1024 ); if( VarSize_KiB >= 100 ) {