From 6c6e99ee7ca1a581e28bf1c32791eb2f35043d2b Mon Sep 17 00:00:00 2001 From: Li Cao Date: Fri, 11 Jul 2025 09:19:26 +0800 Subject: [PATCH] [style] upgrade clang-format and clang-tidy from 14 to 16 (#11682) --- .clang-tidy | 3 ++ .github/workflows/build.yml | 2 +- CONTRIBUTING.md | 2 +- STYLE_GUIDE.md | 2 +- examples/platforms/simulation/uart.c | 4 +-- script/bootstrap | 18 +++++------ script/clang-format | 10 +++--- script/clang-tidy | 32 +++++++++---------- src/cli/cli.cpp | 2 +- src/core/border_router/routing_manager.hpp | 12 +++---- src/core/coap/coap.cpp | 2 +- src/core/meshcop/secure_transport.cpp | 16 +++++----- src/core/radio/radio.hpp | 4 +-- src/core/thread/key_manager.cpp | 2 +- src/lib/spinel/radio_spinel.cpp | 2 +- src/lib/spinel/radio_spinel.hpp | 2 +- src/posix/platform/daemon.cpp | 8 ++--- src/posix/platform/hdlc_interface.cpp | 4 +-- .../include/openthread/openthread-system.h | 6 ++-- tests/unit/test_child.cpp | 6 ++-- tests/unit/test_link_quality.cpp | 24 +++++++------- tests/unit/test_spinel_prop_codec.cpp | 2 +- tests/unit/test_srp_adv_proxy.cpp | 6 ++-- tests/unit/test_srp_server.cpp | 6 ++-- 24 files changed, 90 insertions(+), 87 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 224827af6..bf6dfdce6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,5 +20,8 @@ Checks: > readability-redundant-member-init, readability-simplify-boolean-expr, readability-static-accessed-through-instance +CheckOptions: + - key: readability-simplify-boolean-expr.SimplifyDeMorgan + value: false WarningsAsErrors: '*' HeaderFilterRegex: '(examples|include|src).*(?/dev/null; then - alias clang-format=clang-format-14 +if command -v clang-format-16 >/dev/null; then + alias clang-format=clang-format-16 elif command -v clang-format >/dev/null; then case "$(clang-format --version)" in *"$CLANG_FORMAT_VERSION"*) ;; *) - die "$(clang-format --version); clang-format 14.0 required" + die "$(clang-format --version); clang-format 16.0 required" ;; esac else - die "clang-format 14.0 required" + die "clang-format 16.0 required" fi clang-format "$@" || die diff --git a/script/clang-tidy b/script/clang-tidy index c46080926..c6dd087fe 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -27,8 +27,8 @@ # POSSIBILITY OF SUCH DAMAGE. # -CLANG_TIDY_VERSION="LLVM version 14.0" -CLANG_APPLY_REPLACEMENTS_VERSION="clang-apply-replacements version 14.0" +CLANG_TIDY_VERSION="LLVM version 16.0" +CLANG_APPLY_REPLACEMENTS_VERSION="clang-apply-replacements version 16.0" die() { @@ -36,9 +36,9 @@ die() exit 1 } -# Search for clang-tidy-14 -if command -v clang-tidy-14 >/dev/null; then - clang_tidy=$(command -v clang-tidy-14) +# Search for clang-tidy-16 +if command -v clang-tidy-16 >/dev/null; then + clang_tidy=$(command -v clang-tidy-16) elif command -v clang-tidy >/dev/null; then clang_tidy=$(command -v clang-tidy) case "$($clang_tidy --version)" in @@ -49,12 +49,12 @@ elif command -v clang-tidy >/dev/null; then ;; esac else - die "clang-tidy 14.0 required" + die "clang-tidy 16.0 required" fi -# Search for clang-apply-replacements-14 -if command -v clang-apply-replacements-14 >/dev/null; then - clang_apply_replacements=$(command -v clang-apply-replacements-14) +# Search for clang-apply-replacements-16 +if command -v clang-apply-replacements-16 >/dev/null; then + clang_apply_replacements=$(command -v clang-apply-replacements-16) elif command -v clang-apply-replacements >/dev/null; then clang_apply_replacements=$(command -v clang-apply-replacements) case "$($clang_apply_replacements --version)" in @@ -65,20 +65,20 @@ elif command -v clang-apply-replacements >/dev/null; then ;; esac else - die "clang-apply-replacements 14.0 required" + die "clang-apply-replacements 16.0 required" fi -# Search for run-clang-tidy-14.py -if command -v run-clang-tidy-14.py >/dev/null; then - run_clang_tidy=$(command -v run-clang-tidy-14.py) -elif command -v run-clang-tidy-14 >/dev/null; then - run_clang_tidy=$(command -v run-clang-tidy-14) +# Search for run-clang-tidy-16.py +if command -v run-clang-tidy-16.py >/dev/null; then + run_clang_tidy=$(command -v run-clang-tidy-16.py) +elif command -v run-clang-tidy-16 >/dev/null; then + run_clang_tidy=$(command -v run-clang-tidy-16) elif command -v run-clang-tidy.py >/dev/null; then run_clang_tidy=$(command -v run-clang-tidy.py) elif command -v run-clang-tidy >/dev/null; then run_clang_tidy=$(command -v run-clang-tidy) else - die "run-clang-tidy.py 14.0 required" + die "run-clang-tidy.py 16.0 required" fi $run_clang_tidy -clang-tidy-binary "$clang_tidy" -clang-apply-replacements-binary "$clang_apply_replacements" "$@" || die diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index fc93c62b1..59a89a259 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -1034,7 +1034,7 @@ template <> otError Interpreter::Process(Arg aArgs[]) }; static const uint8_t kNat64CounterTableHeaderColumns[] = {15, 25, 25}; static const char *const kNat64CounterTableSubHeader[] = { - "Protocol", "Pkts", "Bytes", "Pkts", "Bytes", + "Protocol", "Pkts", "Bytes", "Pkts", "Bytes", }; static const uint8_t kNat64CounterTableSubHeaderColumns[] = { 15, 10, 14, 10, 14, diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index b1bd749b9..d1c6038c0 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -1854,22 +1854,22 @@ private: // Template specializations and declarations template <> -inline RoutingManager::RxRaTracker::Entry - &RoutingManager::RxRaTracker::SharedEntry::GetEntry(void) +inline RoutingManager::RxRaTracker::Entry &RoutingManager::RxRaTracker::SharedEntry:: + GetEntry(void) { return mOnLinkEntry; } template <> -inline RoutingManager::RxRaTracker::Entry - &RoutingManager::RxRaTracker::SharedEntry::GetEntry(void) +inline RoutingManager::RxRaTracker::Entry &RoutingManager::RxRaTracker::SharedEntry:: + GetEntry(void) { return mRouteEntry; } template <> -inline RoutingManager::RxRaTracker::Entry - &RoutingManager::RxRaTracker::SharedEntry::GetEntry(void) +inline RoutingManager::RxRaTracker::Entry &RoutingManager::RxRaTracker::SharedEntry:: + GetEntry(void) { return mRdnssAddrEntry; } diff --git a/src/core/coap/coap.cpp b/src/core/coap/coap.cpp index 15ca62098..778863d70 100644 --- a/src/core/coap/coap.cpp +++ b/src/core/coap/coap.cpp @@ -1247,7 +1247,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo } #else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE { - FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone); + FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone); } #endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE } diff --git a/src/core/meshcop/secure_transport.cpp b/src/core/meshcop/secure_transport.cpp index 13e61fe32..5581c929f 100644 --- a/src/core/meshcop/secure_transport.cpp +++ b/src/core/meshcop/secure_transport.cpp @@ -946,12 +946,12 @@ exit: #else -int SecureTransport::HandleMbedtlsExportKeys(void *aContext, +int SecureTransport::HandleMbedtlsExportKeys(void *aContext, const unsigned char *aMasterSecret, const unsigned char *aKeyBlock, - size_t aMacLength, - size_t aKeyLength, - size_t aIvLength) + size_t aMacLength, + size_t aKeyLength, + size_t aIvLength) { return static_cast(aContext)->HandleMbedtlsExportKeys(aMasterSecret, aKeyBlock, aMacLength, aKeyLength, aIvLength); @@ -959,14 +959,14 @@ int SecureTransport::HandleMbedtlsExportKeys(void *aContext, int SecureTransport::HandleMbedtlsExportKeys(const unsigned char *aMasterSecret, const unsigned char *aKeyBlock, - size_t aMacLength, - size_t aKeyLength, - size_t aIvLength) + size_t aMacLength, + size_t aKeyLength, + size_t aIvLength) { OT_UNUSED_VARIABLE(aMasterSecret); Crypto::Sha256::Hash kek; - Crypto::Sha256 sha256; + Crypto::Sha256 sha256; VerifyOrExit(mCipherSuite == kEcjpakeWithAes128Ccm8); diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index e09b4f024..4785946bf 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -1106,14 +1106,14 @@ inline Error Radio::ReceiveAt(uint8_t, uint32_t, uint32_t) { return kErrorNone; #endif #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE -inline void Radio::UpdateCslSampleTime(uint32_t) {} +inline void Radio::UpdateCslSampleTime(uint32_t) {} inline Error Radio::EnableCsl(uint32_t, Mac::ShortAddress aShortAddr, const Mac::ExtAddress &) { return kErrorNotImplemented; } -inline Error Radio::ResetCsl(void) { return kErrorNotImplemented; } +inline Error Radio::ResetCsl(void) { return kErrorNotImplemented; } #endif #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE || \ diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index c2a49f8e1..6502b883f 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -601,7 +601,7 @@ void KeyManager::GetPskc(Pskc &aPskc) const aPskc.Clear(); } #else - aPskc = mPskc; + aPskc = mPskc; #endif } diff --git a/src/lib/spinel/radio_spinel.cpp b/src/lib/spinel/radio_spinel.cpp index e19123a43..285409bf2 100644 --- a/src/lib/spinel/radio_spinel.cpp +++ b/src/lib/spinel/radio_spinel.cpp @@ -1966,7 +1966,7 @@ exit: LogIfFail("Error calculating RCP time offset: %s", error); } -uint64_t RadioSpinel::GetNow(void) { return (mIsTimeSynced) ? (otPlatTimeGet() + mRadioTimeOffset) : UINT64_MAX; } +uint64_t RadioSpinel::GetNow(void) const { return (mIsTimeSynced) ? (otPlatTimeGet() + mRadioTimeOffset) : UINT64_MAX; } uint32_t RadioSpinel::GetBusSpeed(void) const { return GetSpinelDriver().GetSpinelInterface()->GetBusSpeed(); } diff --git a/src/lib/spinel/radio_spinel.hpp b/src/lib/spinel/radio_spinel.hpp index ca6dd8782..f1f36c877 100644 --- a/src/lib/spinel/radio_spinel.hpp +++ b/src/lib/spinel/radio_spinel.hpp @@ -824,7 +824,7 @@ public: * * @returns The current estimated RCP time in microseconds. */ - uint64_t GetNow(void); + uint64_t GetNow(void) const; /** * Returns the bus speed between the host and the radio. diff --git a/src/posix/platform/daemon.cpp b/src/posix/platform/daemon.cpp index 62420ca3d..c42f7cdcb 100644 --- a/src/posix/platform/daemon.cpp +++ b/src/posix/platform/daemon.cpp @@ -197,7 +197,7 @@ void Daemon::createListenSocketOrDie(void) void Daemon::createListenSocketOrDie(void) { struct sockaddr_un sockname; - int ret; + int ret; class AllowAllGuard { @@ -205,7 +205,7 @@ void Daemon::createListenSocketOrDie(void) AllowAllGuard(void) { const char *allowAll = getenv("OT_DAEMON_ALLOW_ALL"); - mAllowAll = (allowAll != nullptr && strcmp("1", allowAll) == 0); + mAllowAll = (allowAll != nullptr && strcmp("1", allowAll) == 0); if (mAllowAll) { @@ -221,8 +221,8 @@ void Daemon::createListenSocketOrDie(void) } private: - bool mAllowAll = false; - mode_t mMode = 0; + bool mAllowAll = false; + mode_t mMode = 0; }; mListenSocket = SocketWithCloseExec(AF_UNIX, SOCK_STREAM, 0, kSocketNonBlock); diff --git a/src/posix/platform/hdlc_interface.cpp b/src/posix/platform/hdlc_interface.cpp index 8bf4043e9..afe0842ef 100644 --- a/src/posix/platform/hdlc_interface.cpp +++ b/src/posix/platform/hdlc_interface.cpp @@ -304,12 +304,12 @@ otError HdlcInterface::WaitForFrame(uint64_t aTimeoutUs) break; } #else // OPENTHREAD_POSIX_VIRTUAL_TIME - timeout.tv_sec = static_cast(aTimeoutUs / OT_US_PER_S); + timeout.tv_sec = static_cast(aTimeoutUs / OT_US_PER_S); timeout.tv_usec = static_cast(aTimeoutUs % OT_US_PER_S); fd_set read_fds; fd_set error_fds; - int rval; + int rval; FD_ZERO(&read_fds); FD_ZERO(&error_fds); diff --git a/src/posix/platform/include/openthread/openthread-system.h b/src/posix/platform/include/openthread/openthread-system.h index 168d5f6c2..fd175a45d 100644 --- a/src/posix/platform/include/openthread/openthread-system.h +++ b/src/posix/platform/include/openthread/openthread-system.h @@ -58,9 +58,9 @@ extern "C" { */ enum { - OT_PLATFORM_CONFIG_SPI_DEFAULT_MODE = 0, ///< Default SPI Mode: CPOL=0, CPHA=0. - OT_PLATFORM_CONFIG_SPI_DEFAULT_SPEED_HZ = 1000000, ///< Default SPI speed in hertz. - OT_PLATFORM_CONFIG_SPI_DEFAULT_CS_DELAY_US = 20, ///< Default delay after SPI C̅S̅ assertion, in µsec. + OT_PLATFORM_CONFIG_SPI_DEFAULT_MODE = 0, ///< Default SPI Mode: CPOL=0, CPHA=0. + OT_PLATFORM_CONFIG_SPI_DEFAULT_SPEED_HZ = 1000000, ///< Default SPI speed in hertz. + OT_PLATFORM_CONFIG_SPI_DEFAULT_CS_DELAY_US = 20, ///< Default delay after SPI C̅S̅ assertion, in µsec. OT_PLATFORM_CONFIG_SPI_DEFAULT_RESET_DELAY_MS = 0, ///< Default delay after R̅E̅S̅E̅T̅ assertion, in milliseconds. OT_PLATFORM_CONFIG_SPI_DEFAULT_ALIGN_ALLOWANCE = 16, ///< Default maximum number of 0xFF bytes to clip from start of MISO frame. diff --git a/tests/unit/test_child.cpp b/tests/unit/test_child.cpp index d7263cf30..a7a0874db 100644 --- a/tests/unit/test_child.cpp +++ b/tests/unit/test_child.cpp @@ -105,9 +105,9 @@ void TestChildIp6Address(void) Ip6::Address addresses[kMaxChildIp6Addresses]; uint8_t numAddresses; const char *ip6Addresses[] = { - "fd00:1234::1234", - "ff6b:e251:52fb:0:12e6:b94c:1c28:c56a", - "fd00:1234::204c:3d7c:98f6:9a1b", + "fd00:1234::1234", + "ff6b:e251:52fb:0:12e6:b94c:1c28:c56a", + "fd00:1234::204c:3d7c:98f6:9a1b", }; const uint8_t meshLocalIidArray[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; diff --git a/tests/unit/test_link_quality.cpp b/tests/unit/test_link_quality.cpp index 36bbf7118..71132d047 100644 --- a/tests/unit/test_link_quality.cpp +++ b/tests/unit/test_link_quality.cpp @@ -333,30 +333,30 @@ void TestLinkQualityCalculations(void) { const int8_t rssList1[] = {-81, -80, -79, -78, -76, -80, -77, -75, -77, -76, -77, -74}; const RssTestData rssData1 = { - rssList1, // mRssList - sizeof(rssList1), // mRssListSize - 3 // mExpectedLinkQuality + rssList1, // mRssList + sizeof(rssList1), // mRssListSize + 3 // mExpectedLinkQuality }; const int8_t rssList2[] = {-90, -80, -85}; const RssTestData rssData2 = { - rssList2, // mRssList - sizeof(rssList2), // mRssListSize - 2 // mExpectedLinkQuality + rssList2, // mRssList + sizeof(rssList2), // mRssListSize + 2 // mExpectedLinkQuality }; const int8_t rssList3[] = {-95, -96, -98, -99, -100, -100, -98, -99, -100, -100, -100, -100, -100}; const RssTestData rssData3 = { - rssList3, // mRssList - sizeof(rssList3), // mRssListSize - 0 // mExpectedLinkQuality + rssList3, // mRssList + sizeof(rssList3), // mRssListSize + 0 // mExpectedLinkQuality }; const int8_t rssList4[] = {-75, -100, -100, -100, -100, -100, -95, -92, -93, -94, -93, -93}; const RssTestData rssData4 = { - rssList4, // mRssList - sizeof(rssList4), // mRssListSize - 1 // mExpectedLinkQuality + rssList4, // mRssList + sizeof(rssList4), // mRssListSize + 1 // mExpectedLinkQuality }; TestLinkQualityData(rssData1); diff --git a/tests/unit/test_spinel_prop_codec.cpp b/tests/unit/test_spinel_prop_codec.cpp index 85bbba5df..68a17f1a6 100644 --- a/tests/unit/test_spinel_prop_codec.cpp +++ b/tests/unit/test_spinel_prop_codec.cpp @@ -58,7 +58,7 @@ void TestDnssd(void) otPlatDnssdHost dnssdHostEncode; otPlatDnssdHost dnssdHostDecode; otIp6Address dnssdHostAddrs[] = { - {0xfd, 0x2a, 0xc3, 0x0c, 0x87, 0xd3, 0x00, 0x01, 0xed, 0x1c, 0x0c, 0x91, 0xcc, 0xb6, 0x57, 0x8b}, + {0xfd, 0x2a, 0xc3, 0x0c, 0x87, 0xd3, 0x00, 0x01, 0xed, 0x1c, 0x0c, 0x91, 0xcc, 0xb6, 0x57, 0x8b}, }; otPlatDnssdRequestId requestId; const uint8_t *callbackData; diff --git a/tests/unit/test_srp_adv_proxy.cpp b/tests/unit/test_srp_adv_proxy.cpp index cbd03cfe5..49d65e507 100644 --- a/tests/unit/test_srp_adv_proxy.cpp +++ b/tests/unit/test_srp_adv_proxy.cpp @@ -611,9 +611,9 @@ void PrepareService1(Srp::Client::Service &aService) static const char kTxtKey3[] = "D"; static const uint8_t kTxtValue3[] = {0}; static const otDnsTxtEntry kTxtEntries[] = { - {kTxtKey1, kTxtValue1, sizeof(kTxtValue1)}, - {kTxtKey2, kTxtValue2, sizeof(kTxtValue2)}, - {kTxtKey3, kTxtValue3, sizeof(kTxtValue3)}, + {kTxtKey1, kTxtValue1, sizeof(kTxtValue1)}, + {kTxtKey2, kTxtValue2, sizeof(kTxtValue2)}, + {kTxtKey3, kTxtValue3, sizeof(kTxtValue3)}, }; memset(&aService, 0, sizeof(aService)); diff --git a/tests/unit/test_srp_server.cpp b/tests/unit/test_srp_server.cpp index 2c5f50943..a9a2e916c 100644 --- a/tests/unit/test_srp_server.cpp +++ b/tests/unit/test_srp_server.cpp @@ -309,9 +309,9 @@ void PrepareService1(Srp::Client::Service &aService) static const char kTxtKey3[] = "D"; static const uint8_t kTxtValue3[] = {0}; static const otDnsTxtEntry kTxtEntries[] = { - {kTxtKey1, kTxtValue1, sizeof(kTxtValue1)}, - {kTxtKey2, kTxtValue2, sizeof(kTxtValue2)}, - {kTxtKey3, kTxtValue3, sizeof(kTxtValue3)}, + {kTxtKey1, kTxtValue1, sizeof(kTxtValue1)}, + {kTxtKey2, kTxtValue2, sizeof(kTxtValue2)}, + {kTxtKey3, kTxtValue3, sizeof(kTxtValue3)}, }; memset(&aService, 0, sizeof(aService));