From af95eafb34c20f980b65342cac0ee7cea534b161 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 23 Jan 2024 10:15:09 -0800 Subject: [PATCH] [CI] Using clang-17 for clang tidy & format (#35595) Clang-17 is now better at formatting. Clang-16 used to do some questionable formatting. Closes #35595 PiperOrigin-RevId: 600829055 --- .clang-tidy | 7 +++++++ src/core/lib/gprpp/time.h | 4 ++-- src/core/lib/iomgr/combiner.cc | 2 +- src/core/lib/json/json_writer.cc | 2 +- src/core/tsi/fake_transport_security.cc | 2 +- src/objective-c/tests/InteropTests/InteropTests.m | 2 +- .../tools/dockerfile/grpc_clang_format/Dockerfile.template | 2 +- .../tools/dockerfile/grpc_clang_tidy/Dockerfile.template | 2 +- templates/tools/dockerfile/test/sanity/Dockerfile.template | 7 ++----- test/core/util/osa_distance.cc | 2 +- tools/bazelify_tests/dockerimage_current_versions.bzl | 2 +- tools/dockerfile/grpc_clang_format/Dockerfile | 2 +- tools/dockerfile/grpc_clang_tidy/Dockerfile | 2 +- tools/dockerfile/test/sanity.current_version | 2 +- tools/dockerfile/test/sanity/Dockerfile | 7 ++----- 15 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 70f083cec64..32eed8a70e6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -32,6 +32,7 @@ # - bugprone-not-null-terminated-result # - bugprone-signed-char-misuse # - bugprone-sizeof-expression +# - bugprone-switch-missing-default-case # - bugprone-too-small-loop-variable # - bugprone-unchecked-optional-access # - clang-diagnostic-deprecated-declarations @@ -50,8 +51,10 @@ # - modernize-use-equals-default # - modernize-use-equals-delete # - modernize-use-using +# - performance-avoid-endl # - performance-no-automatic-move # - performance-no-int-to-ptr +# - performance-noexcept-swap # - performance-unnecessary-copy-initialization # - performance-unnecessary-value-param # - readability-else-after-return @@ -67,6 +70,7 @@ Checks: '-*, -bugprone-assignment-in-if-condition, -bugprone-branch-clone, -bugprone-easily-swappable-parameters, + -bugprone-empty-catch, -bugprone-exception-escape, -bugprone-implicit-widening-of-multiplication-result, -bugprone-infinite-loop, @@ -75,6 +79,7 @@ Checks: '-*, -bugprone-reserved-identifier, -bugprone-signed-char-misuse, -bugprone-sizeof-expression, + -bugprone-switch-missing-default-case, -bugprone-too-small-loop-variable, -bugprone-unchecked-optional-access, google-*, @@ -82,8 +87,10 @@ Checks: '-*, -google-runtime-int, -google-runtime-references, performance-*, + -performance-avoid-endl, -performance-no-automatic-move, -performance-no-int-to-ptr, + -performance-noexcept-swap, -performance-unnecessary-copy-initialization, -performance-unnecessary-value-param, clang-diagnostic-deprecated-declarations, diff --git a/src/core/lib/gprpp/time.h b/src/core/lib/gprpp/time.h index 32b1065e380..ac52a982af0 100644 --- a/src/core/lib/gprpp/time.h +++ b/src/core/lib/gprpp/time.h @@ -37,7 +37,7 @@ uint64_t now = grpc_core::Timestamp::FromTimespecRoundDown( \ gpr_now(GPR_CLOCK_MONOTONIC)) \ .milliseconds_after_process_epoch(); \ - if (prev == 0 || now - prev > (n)*1000) { \ + if (prev == 0 || now - prev > (n) * 1000) { \ prev = now; \ gpr_log(severity, format, __VA_ARGS__); \ } \ @@ -50,7 +50,7 @@ gpr_now(GPR_CLOCK_MONOTONIC)) \ .milliseconds_after_process_epoch(); \ uint64_t prev_tsamp = prev.exchange(now); \ - if (now - prev_tsamp > (n)*1000) { \ + if (now - prev_tsamp > (n) * 1000) { \ gpr_log(severity, format, __VA_ARGS__); \ } \ } while (0) diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 0d77bb579d4..d0e635ffd22 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -258,7 +258,7 @@ bool grpc_combiner_continue_exec_ctx() { // Define a macro to ease readability of the following switch statement. #define OLD_STATE_WAS(orphaned, elem_count) \ (((orphaned) ? 0 : STATE_UNORPHANED) | \ - ((elem_count)*STATE_ELEM_COUNT_LOW_BIT)) + ((elem_count) * STATE_ELEM_COUNT_LOW_BIT)) // Depending on what the previous state was, we need to perform different // actions. switch (old_state) { diff --git a/src/core/lib/json/json_writer.cc b/src/core/lib/json/json_writer.cc index ef07c5e3925..a69884ce0d9 100644 --- a/src/core/lib/json/json_writer.cc +++ b/src/core/lib/json/json_writer.cc @@ -138,7 +138,7 @@ void JsonWriter::EscapeUtf16(uint16_t utf16) { OutputChar(hex[(utf16 >> 12) & 0x0f]); OutputChar(hex[(utf16 >> 8) & 0x0f]); OutputChar(hex[(utf16 >> 4) & 0x0f]); - OutputChar(hex[(utf16)&0x0f]); + OutputChar(hex[(utf16) & 0x0f]); } void JsonWriter::EscapeString(const std::string& string) { diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index b1371dcfc75..d8e498e8181 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -121,7 +121,7 @@ static void store32_little_endian(uint32_t value, unsigned char* buf) { buf[3] = static_cast((value >> 24) & 0xFF); buf[2] = static_cast((value >> 16) & 0xFF); buf[1] = static_cast((value >> 8) & 0xFF); - buf[0] = static_cast((value)&0xFF); + buf[0] = static_cast((value) & 0xFF); } static uint32_t read_frame_size(const grpc_slice_buffer* sb) { diff --git a/src/objective-c/tests/InteropTests/InteropTests.m b/src/objective-c/tests/InteropTests/InteropTests.m index 3ce451fd1da..24122b9a30f 100644 --- a/src/objective-c/tests/InteropTests/InteropTests.m +++ b/src/objective-c/tests/InteropTests/InteropTests.m @@ -851,7 +851,7 @@ static dispatch_once_t initGlobalInterceptorFactory; [call setResponseDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL)]; [call start]; } - while (completedCallCount 0) { + while (completedCallCount < kNumRpcs && [waitUntil timeIntervalSinceNow] > 0) { [cv waitUntilDate:waitUntil]; } [cv unlock]; diff --git a/templates/tools/dockerfile/grpc_clang_format/Dockerfile.template b/templates/tools/dockerfile/grpc_clang_format/Dockerfile.template index 3ada7cedb14..2acff18204a 100644 --- a/templates/tools/dockerfile/grpc_clang_format/Dockerfile.template +++ b/templates/tools/dockerfile/grpc_clang_format/Dockerfile.template @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - FROM silkeh/clang:16-bullseye + FROM silkeh/clang:17-bullseye ADD clang_format_all_the_things.sh / diff --git a/templates/tools/dockerfile/grpc_clang_tidy/Dockerfile.template b/templates/tools/dockerfile/grpc_clang_tidy/Dockerfile.template index 814829d790d..a03ea3e894b 100644 --- a/templates/tools/dockerfile/grpc_clang_tidy/Dockerfile.template +++ b/templates/tools/dockerfile/grpc_clang_tidy/Dockerfile.template @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - FROM silkeh/clang:16-bullseye + FROM silkeh/clang:17-bullseye # Install prerequisites for the clang-tidy script RUN apt-get update && apt-get install -y python3 jq git && apt-get clean diff --git a/templates/tools/dockerfile/test/sanity/Dockerfile.template b/templates/tools/dockerfile/test/sanity/Dockerfile.template index 1ae00b5395b..c061cc2028e 100644 --- a/templates/tools/dockerfile/test/sanity/Dockerfile.template +++ b/templates/tools/dockerfile/test/sanity/Dockerfile.template @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - FROM silkeh/clang:16-bullseye + FROM silkeh/clang:17-bullseye <%include file="../../apt_get_basic.include"/> @@ -52,10 +52,7 @@ RUN python3 -m pip install --upgrade --ignore-installed PyYAML==5.4.1 --user # Install prerequisites for the clang-tidy script - RUN apt-get update && apt-get install -y jq git - - # Install prerequisites for the iwyu script - RUN apt-get update && apt-get install -y jq git cmake zlib1g-dev libtinfo-dev libclang-16-dev && apt-get clean + RUN apt-get update && apt-get install -y jq git && apt-get clean <%include file="../../bazel.include"/> <%include file="../../buildifier.include"/> diff --git a/test/core/util/osa_distance.cc b/test/core/util/osa_distance.cc index f323e705af9..1cf30d98867 100644 --- a/test/core/util/osa_distance.cc +++ b/test/core/util/osa_distance.cc @@ -31,7 +31,7 @@ size_t OsaDistance(absl::string_view s1, absl::string_view s2) { const auto height = s2.size() + 1; std::vector matrix(width * height, std::numeric_limits::max()); -#define MATRIX_CELL(x, y) matrix[(y)*width + (x)] +#define MATRIX_CELL(x, y) matrix[(y) * width + (x)] MATRIX_CELL(0, 0) = 0; for (size_t i = 1; i <= s1.size(); ++i) { diff --git a/tools/bazelify_tests/dockerimage_current_versions.bzl b/tools/bazelify_tests/dockerimage_current_versions.bzl index eeca8dd9c8d..a3824b0763f 100644 --- a/tools/bazelify_tests/dockerimage_current_versions.bzl +++ b/tools/bazelify_tests/dockerimage_current_versions.bzl @@ -111,5 +111,5 @@ DOCKERIMAGE_CURRENT_VERSIONS = { "tools/dockerfile/test/rbe_ubuntu2004.current_version": "docker://us-docker.pkg.dev/grpc-testing/testing-images-public/rbe_ubuntu2004@sha256:d3951aeadf43e3bee6adc5b86d26cdaf0b9d1b5baf790d7b2530d1c197adc9f8", "tools/dockerfile/test/ruby_debian11_arm64.current_version": "docker://us-docker.pkg.dev/grpc-testing/testing-images-public/ruby_debian11_arm64@sha256:7e77cf17e2e8657f4cc23ac9f93630bf13213fff961799e0f16dae17cd45cf6d", "tools/dockerfile/test/ruby_debian11_x64.current_version": "docker://us-docker.pkg.dev/grpc-testing/testing-images-public/ruby_debian11_x64@sha256:e4cb502caccf2db733268ce2ddc951fda8a9df2f7f53d6b74523c33d40c83006", - "tools/dockerfile/test/sanity.current_version": "docker://us-docker.pkg.dev/grpc-testing/testing-images-public/sanity@sha256:f1f5ca30491698f793cae75d5989cb53887d159800aef662cf7e6c3df6f86a88", + "tools/dockerfile/test/sanity.current_version": "docker://us-docker.pkg.dev/grpc-testing/testing-images-public/sanity@sha256:ca65b29302e8e381aabf9deb1952281f4e9963654e19c3d681148b5aa972c8a2", } diff --git a/tools/dockerfile/grpc_clang_format/Dockerfile b/tools/dockerfile/grpc_clang_format/Dockerfile index f3d675bab2f..ff99ca74274 100644 --- a/tools/dockerfile/grpc_clang_format/Dockerfile +++ b/tools/dockerfile/grpc_clang_format/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM silkeh/clang:16-bullseye +FROM silkeh/clang:17-bullseye ADD clang_format_all_the_things.sh / diff --git a/tools/dockerfile/grpc_clang_tidy/Dockerfile b/tools/dockerfile/grpc_clang_tidy/Dockerfile index 71125ada0d7..178d874b3bd 100644 --- a/tools/dockerfile/grpc_clang_tidy/Dockerfile +++ b/tools/dockerfile/grpc_clang_tidy/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM silkeh/clang:16-bullseye +FROM silkeh/clang:17-bullseye # Install prerequisites for the clang-tidy script RUN apt-get update && apt-get install -y python3 jq git && apt-get clean diff --git a/tools/dockerfile/test/sanity.current_version b/tools/dockerfile/test/sanity.current_version index 776c3d349be..2a2d514f070 100644 --- a/tools/dockerfile/test/sanity.current_version +++ b/tools/dockerfile/test/sanity.current_version @@ -1 +1 @@ -us-docker.pkg.dev/grpc-testing/testing-images-public/sanity:091d8e85bebb7b9f089178ae96435926cdc82fb8@sha256:f1f5ca30491698f793cae75d5989cb53887d159800aef662cf7e6c3df6f86a88 \ No newline at end of file +us-docker.pkg.dev/grpc-testing/testing-images-public/sanity:2d20232b40465f3487deef87274f4bfd7122b201@sha256:ca65b29302e8e381aabf9deb1952281f4e9963654e19c3d681148b5aa972c8a2 \ No newline at end of file diff --git a/tools/dockerfile/test/sanity/Dockerfile b/tools/dockerfile/test/sanity/Dockerfile index e45bdfc0026..b44b5582710 100644 --- a/tools/dockerfile/test/sanity/Dockerfile +++ b/tools/dockerfile/test/sanity/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM silkeh/clang:16-bullseye +FROM silkeh/clang:17-bullseye #================= # Basic C core dependencies @@ -102,10 +102,7 @@ RUN python3 -m pip install simplejson mako virtualenv==16.7.9 lxml six RUN python3 -m pip install --upgrade --ignore-installed PyYAML==5.4.1 --user # Install prerequisites for the clang-tidy script -RUN apt-get update && apt-get install -y jq git - -# Install prerequisites for the iwyu script -RUN apt-get update && apt-get install -y jq git cmake zlib1g-dev libtinfo-dev libclang-16-dev && apt-get clean +RUN apt-get update && apt-get install -y jq git && apt-get clean #======================== # Bazel installation