From b6ca3b5c40d6c290ae62d5dcbeff531e3a5cc219 Mon Sep 17 00:00:00 2001 From: mcbarton <150042563+mcbarton@users.noreply.github.com> Date: Wed, 8 May 2024 07:36:44 +0100 Subject: [PATCH] Fix clang tidy + remove warnings when building (#272) --- .github/workflows/clang-format.yml | 2 +- .github/workflows/clang-tidy-review.yml | 18 ++++++++++++------ lib/Interpreter/Compatibility.h | 5 +++++ lib/Interpreter/CppInterOp.cpp | 6 +++--- lib/Interpreter/DynamicLibraryManager.cpp | 2 +- lib/Interpreter/Paths.cpp | 2 +- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 9ca84320f..ed3889200 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -23,7 +23,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: 3.10 + python-version: "3.11" - name: Install clang-format run: | diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml index 713382b23..ecbe34e19 100644 --- a/.github/workflows/clang-tidy-review.yml +++ b/.github/workflows/clang-tidy-review.yml @@ -17,21 +17,27 @@ jobs: - name: Checkout PR branch uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + - name: Install LLVM and Clang - uses: KyleMayes/install-llvm-action@v2 + uses: KyleMayes/install-llvm-action@v2.0.2 with: - version: "18.1.3" + version: "16.0.0" + - name: install lit + run: pip install lit + - name: Run clang-tidy uses: ZedThree/clang-tidy-review@v0.18.0 id: review with: build_dir: build - apt_packages: libxml2,libxml2-dev,libtinfo-dev,zlib1g-dev,libzstd-dev + apt_packages: cmake,libxml2,libxml2-dev,libtinfo-dev,zlib1g-dev,libzstd-dev split_workflow: true cmake_command: > - pip install cmake lit && - cmake --version && cmake . -B build -DCMAKE_BUILD_TYPE="Release" -DUSE_CLING=OFF -DUSE_REPL=ON @@ -40,4 +46,4 @@ jobs: -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - name: Upload artifacts - uses: ZedThree/clang-tidy-review/upload@v0.18.0 \ No newline at end of file + uses: ZedThree/clang-tidy-review/upload@v0.18.0 diff --git a/lib/Interpreter/Compatibility.h b/lib/Interpreter/Compatibility.h index 75f92dd05..9291d67ba 100644 --- a/lib/Interpreter/Compatibility.h +++ b/lib/Interpreter/Compatibility.h @@ -10,6 +10,11 @@ #include "clang/Basic/Version.h" #include "clang/Config/config.h" +#if LLVM_VERSION_MAJOR < 18 +#define starts_with startswith +#define ends_with endswith +#endif + #if CLANG_VERSION_MAJOR >= 18 #include "clang/Interpreter/CodeCompletion.h" #endif diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index f66d8b510..7ae53d6c1 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -316,9 +316,9 @@ namespace Cpp { // Add quick checks for the std smart prts to cover most of the cases. std::string typeString = GetTypeAsString(type); llvm::StringRef tsRef(typeString); - if (tsRef.startswith("std::unique_ptr") || - tsRef.startswith("std::shared_ptr") || - tsRef.startswith("std::weak_ptr")) + if (tsRef.starts_with("std::unique_ptr") || + tsRef.starts_with("std::shared_ptr") || + tsRef.starts_with("std::weak_ptr")) return true; return isSmartPointer(RT); } diff --git a/lib/Interpreter/DynamicLibraryManager.cpp b/lib/Interpreter/DynamicLibraryManager.cpp index d2cf5a172..bfa156edf 100644 --- a/lib/Interpreter/DynamicLibraryManager.cpp +++ b/lib/Interpreter/DynamicLibraryManager.cpp @@ -323,7 +323,7 @@ namespace Cpp { foundName = lookupLibMaybeAddExt(libStem, RPath, RunPath, libLoader); if (foundName.empty()) { StringRef libStemName = llvm::sys::path::filename(libStem); - if (!libStemName.startswith("lib")) { + if (!libStemName.starts_with("lib")) { // try with "lib" prefix: foundName = lookupLibMaybeAddExt( libStem.str().insert(libStem.size()-libStemName.size(), "lib"), diff --git a/lib/Interpreter/Paths.cpp b/lib/Interpreter/Paths.cpp index 1a5abbd27..4e7c1f622 100644 --- a/lib/Interpreter/Paths.cpp +++ b/lib/Interpreter/Paths.cpp @@ -413,7 +413,7 @@ bool SplitPaths(llvm::StringRef PathStr, } // Trim trailing sep in case of A:B:C:D: - if (!PathStr.empty() && PathStr.endswith(Delim)) + if (!PathStr.empty() && PathStr.ends_with(Delim)) PathStr = PathStr.substr(0, PathStr.size()-Delim.size()); if (!PathStr.empty()) {