[style] upgrade clang-format and clang-tidy from 14 to 16 (#11682)

This commit is contained in:
Li Cao
2025-07-11 09:19:26 +08:00
committed by GitHub
parent a9c2001bf1
commit 6c6e99ee7c
24 changed files with 90 additions and 87 deletions
+3
View File
@@ -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).*(?<!third_party.*repo)'
+1 -1
View File
@@ -63,7 +63,7 @@ jobs:
- name: Bootstrap
run: |
sudo apt-get update
sudo apt-get --no-install-recommends install -y clang-format-14 clang-tidy-14 shellcheck iwyu
sudo apt-get --no-install-recommends install -y clang-format-16 clang-tidy-16 shellcheck iwyu
python3 -m pip install yapf==0.31.0
sudo snap install shfmt
npm install prettier@2.0.4
+1 -1
View File
@@ -109,7 +109,7 @@ This will open up a text editor where you can specify which commits to squash.
#### Coding Conventions and Style
OpenThread uses and enforces the [OpenThread Coding Conventions and Style](STYLE_GUIDE.md) on all code, except for code located in [third_party](third_party). Use `script/make-pretty` and `script/make-pretty check` to automatically reformat code and check for code-style compliance, respectively. OpenThread currently requires [clang-format v14.0.0](https://releases.llvm.org/download.html#14.0.0) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python.
OpenThread uses and enforces the [OpenThread Coding Conventions and Style](STYLE_GUIDE.md) on all code, except for code located in [third_party](third_party). Use `script/make-pretty` and `script/make-pretty check` to automatically reformat code and check for code-style compliance, respectively. OpenThread currently requires [clang-format v16.0.0](https://releases.llvm.org/download.html#16.0.0) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python.
As part of the cleanup process, you should also run `script/make-pretty check` to ensure that your code passes the baseline code style checks.
+1 -1
View File
@@ -116,7 +116,7 @@
- OpenThread uses `script/make-pretty` to reformat code and enforce code format and style. `script/make-pretty check` build target is included in OpenThread's continuous integration and must pass before a pull request is merged.
- `script/make-pretty` requires [clang-format v14.0.0](https://releases.llvm.org/download.html#14.0.0) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python.
- `script/make-pretty` requires [clang-format v16.0.0](https://releases.llvm.org/download.html#16.0.0) for C/C++ and [yapf v0.31.0](https://github.com/google/yapf) for Python.
### File Names
+2 -2
View File
@@ -216,8 +216,8 @@ void platformUartProcess(void)
ssize_t rval;
const int error_flags = POLLERR | POLLNVAL | POLLHUP;
struct pollfd pollfd[] = {
{s_in_fd, POLLIN | error_flags, 0},
{s_out_fd, POLLOUT | error_flags, 0},
{s_in_fd, POLLIN | error_flags, 0},
{s_out_fd, POLLOUT | error_flags, 0},
};
errno = 0;
+9 -9
View File
@@ -38,7 +38,7 @@ install_packages_pretty_format()
echo 'Installing pretty tools useful for code contributions...'
# add clang-format and clang-tidy for pretty
sudo apt-get --no-install-recommends install -y clang-format-14 clang-tidy-14 || echo 'WARNING: could not install clang-format-14 and clang-tidy-14, which is useful if you plan to contribute C/C++ code to the OpenThread project.'
sudo apt-get --no-install-recommends install -y clang-format-16 clang-tidy-16 || echo 'WARNING: could not install clang-format-16 and clang-tidy-16, which is useful if you plan to contribute C/C++ code to the OpenThread project.'
# add yapf for pretty
python3 -m pip install yapf==0.31.0 || echo 'WARNING: could not install yapf, which is useful if you plan to contribute python code to the OpenThread project.'
@@ -113,14 +113,14 @@ install_packages_brew()
echo 'Installing pretty tools useful for code contributions...'
# add clang-format for pretty
CLANG_FORMAT_VERSION="clang-format version 14"
command -v clang-format-14 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || {
brew install llvm@14
sudo ln -s "$(brew --prefix llvm@14)/bin/clang-format" /usr/local/bin/clang-format-14
sudo ln -s "$(brew --prefix llvm@14)/bin/clang-tidy" /usr/local/bin/clang-tidy-14
sudo ln -s "$(brew --prefix llvm@14)/bin/clang-apply-replacements" /usr/local/bin/clang-apply-replacements-14
sudo ln -s "$(brew --prefix llvm@14)/bin/run-clang-tidy" /usr/local/bin/run-clang-tidy-14
} || echo 'WARNING: could not install llvm@14, which is useful if you plan to contribute C/C++ code to the OpenThread project.'
CLANG_FORMAT_VERSION="clang-format version 16"
command -v clang-format-16 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || {
brew install llvm@16
sudo ln -s "$(brew --prefix llvm@16)/bin/clang-format" /usr/local/bin/clang-format-16
sudo ln -s "$(brew --prefix llvm@16)/bin/clang-tidy" /usr/local/bin/clang-tidy-16
sudo ln -s "$(brew --prefix llvm@16)/bin/clang-apply-replacements" /usr/local/bin/clang-apply-replacements-16
sudo ln -s "$(brew --prefix llvm@16)/bin/run-clang-tidy" /usr/local/bin/run-clang-tidy-16
} || echo 'WARNING: could not install llvm@16, which is useful if you plan to contribute C/C++ code to the OpenThread project.'
# add yapf for pretty
python3 -m pip install yapf || echo 'Failed to install python code formatter yapf. Install it manually if you need.'
+5 -5
View File
@@ -27,7 +27,7 @@
# POSSIBILITY OF SUCH DAMAGE.
#
CLANG_FORMAT_VERSION="clang-format version 14.0"
CLANG_FORMAT_VERSION="clang-format version 16.0"
die()
{
@@ -39,18 +39,18 @@ die()
# expand_aliases shell option is set using shopt.
shopt -s expand_aliases
if command -v clang-format-14 >/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
+16 -16
View File
@@ -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
+1 -1
View File
@@ -1034,7 +1034,7 @@ template <> otError Interpreter::Process<Cmd("nat64")>(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,
+6 -6
View File
@@ -1854,22 +1854,22 @@ private:
// Template specializations and declarations
template <>
inline RoutingManager::RxRaTracker::Entry<RoutingManager::OnLinkPrefix>
&RoutingManager::RxRaTracker::SharedEntry::GetEntry(void)
inline RoutingManager::RxRaTracker::Entry<RoutingManager::OnLinkPrefix> &RoutingManager::RxRaTracker::SharedEntry::
GetEntry(void)
{
return mOnLinkEntry;
}
template <>
inline RoutingManager::RxRaTracker::Entry<RoutingManager::RoutePrefix>
&RoutingManager::RxRaTracker::SharedEntry::GetEntry(void)
inline RoutingManager::RxRaTracker::Entry<RoutingManager::RoutePrefix> &RoutingManager::RxRaTracker::SharedEntry::
GetEntry(void)
{
return mRouteEntry;
}
template <>
inline RoutingManager::RxRaTracker::Entry<RoutingManager::RdnssAddress>
&RoutingManager::RxRaTracker::SharedEntry::GetEntry(void)
inline RoutingManager::RxRaTracker::Entry<RoutingManager::RdnssAddress> &RoutingManager::RxRaTracker::SharedEntry::
GetEntry(void)
{
return mRdnssAddrEntry;
}
+1 -1
View File
@@ -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
}
+8 -8
View File
@@ -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<SecureTransport *>(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);
+2 -2
View File
@@ -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 || \
+1 -1
View File
@@ -601,7 +601,7 @@ void KeyManager::GetPskc(Pskc &aPskc) const
aPskc.Clear();
}
#else
aPskc = mPskc;
aPskc = mPskc;
#endif
}
+1 -1
View File
@@ -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(); }
+1 -1
View File
@@ -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.
+4 -4
View File
@@ -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);
+2 -2
View File
@@ -304,12 +304,12 @@ otError HdlcInterface::WaitForFrame(uint64_t aTimeoutUs)
break;
}
#else // OPENTHREAD_POSIX_VIRTUAL_TIME
timeout.tv_sec = static_cast<time_t>(aTimeoutUs / OT_US_PER_S);
timeout.tv_sec = static_cast<time_t>(aTimeoutUs / OT_US_PER_S);
timeout.tv_usec = static_cast<suseconds_t>(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);
@@ -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.
+3 -3
View File
@@ -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};
+12 -12
View File
@@ -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);
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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));
+3 -3
View File
@@ -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));