Skip to content

Commit f557872

Browse files
silabs-PiyushYsuveshpratapa
authored andcommitted
Fix LLVM compilation issues
- Fix Clang -Wshorten-64-to-32 in mac_frame.cpp and cli_ping.cpp - Move strict warning flags from global GN toolchain to private openthread_private_flags config on OT-owned targets only - Use private configs for tcplp/mbedtls warning overrides - Fix known mbedtls compilation error when -Wundef is set: Mbed-TLS/mbedtls#10207
1 parent 318b4b0 commit f557872

14 files changed

Lines changed: 40 additions & 28 deletions

File tree

BUILD.gn

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727

2828
import("etc/gn/openthread.gni")
2929

30+
# Strict warnings for OpenThread sources only. Use private `configs =` on OT
31+
# targets, not `public_configs` on shared deps, so embedders (e.g. Matter with
32+
# Clang) keep their own warning defaults; a late -W* can undo flags such as
33+
# -Wno-unused-parameter on dependent translation units.
34+
config("openthread_private_flags") {
35+
cflags = [
36+
"-Werror",
37+
"-Wall",
38+
"-Wextra",
39+
"-Wundef",
40+
"-Wformat-nonliteral",
41+
]
42+
}
43+
3044
config("openthread_config") {
3145
defines = []
3246
if (openthread_config_file != "") {

etc/gn/toolchain/BUILD.gn

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,16 @@
2626
#
2727

2828
toolchain("toolchain") {
29-
diagnostic_cflags = [
30-
"-Werror",
31-
"-Wall",
32-
"-Wextra",
33-
"-Wundef",
34-
"-Wformat-nonliteral",
35-
]
3629
if (use_clang) {
3730
cc = "clang"
3831
cxx = "clang++"
3932
} else {
4033
cc = "gcc"
4134
cxx = "g++"
4235
}
43-
cflags = string_join(" ", diagnostic_cflags)
36+
# Warning/diagnostic flags come from GN target configs ({{cflags}}), not from
37+
# a global toolchain preset, so nothing is prepended here.
38+
cflags = ""
4439

4540
tool("cc") {
4641
depfile = "{{output}}.d"

examples/apps/cli/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#
2727

2828
static_library("cli_uart") {
29+
configs = [ "../../../:openthread_private_flags" ]
2930
sources = [ "cli_uart.cpp" ]
3031
include_dirs = [ "../../platforms" ]
3132
deps = [

examples/platforms/utils/mac_frame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ otError otMacFrameProcessTxSfd(otRadioFrame *aFrame, uint64_t aRadioTime, otRadi
413413
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
414414
if (aRadioContext->mCslPresent) // CSL IE should be filled for every transmit attempt
415415
{
416-
otMacFrameSetCslIe(aFrame, aRadioContext->mCslPeriod, ComputeCslPhase(aRadioTime, aRadioContext));
416+
otMacFrameSetCslIe(aFrame, aRadioContext->mCslPeriod,
417+
ComputeCslPhase(static_cast<uint32_t>(aRadioTime), aRadioContext));
417418
}
418419
#endif
419420
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE

src/cli/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static_library("cli_config") {
8282
}
8383

8484
static_library("libopenthread-cli-ftd") {
85+
configs = [ "../..:openthread_private_flags" ]
8586
sources = openthread_cli_sources
8687
public_deps = [
8788
":cli_config",
@@ -91,6 +92,7 @@ static_library("libopenthread-cli-ftd") {
9192
}
9293

9394
static_library("libopenthread-cli-mtd") {
95+
configs = [ "../..:openthread_private_flags" ]
9496
sources = openthread_cli_sources
9597
public_deps = [
9698
":cli_config",

src/cli/cli_ping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ void PingSender::HandlePingStatistics(const otPingSenderStatistics *aStatistics)
233233

234234
if (aStatistics->mReceivedCount != 0)
235235
{
236-
uint32_t avgRoundTripTime =
237-
1000 * static_cast<uint64_t>(aStatistics->mTotalRoundTripTime) / aStatistics->mReceivedCount;
236+
uint32_t avgRoundTripTime = static_cast<uint32_t>(
237+
1000 * static_cast<uint64_t>(aStatistics->mTotalRoundTripTime) / aStatistics->mReceivedCount);
238238

239239
OutputFormat(" Round-trip min/avg/max = %u/%u.%03u/%u ms.", aStatistics->mMinRoundTripTime,
240240
static_cast<uint16_t>(avgRoundTripTime / 1000), static_cast<uint16_t>(avgRoundTripTime % 1000),

src/core/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ group("libopenthread_platform") {
954954
}
955955

956956
static_library("libopenthread-ftd") {
957+
configs = [ "../..:openthread_private_flags" ]
957958
sources = openthread_core_sources
958959
if (openthread_enable_core_config_args && openthread_config_tcp_enable) {
959960
deps = [ "../../third_party/tcplp" ]
@@ -963,6 +964,7 @@ static_library("libopenthread-ftd") {
963964
}
964965

965966
static_library("libopenthread-mtd") {
967+
configs = [ "../..:openthread_private_flags" ]
966968
sources = openthread_core_sources
967969
if (openthread_enable_core_config_args && openthread_config_tcp_enable) {
968970
deps = [ "../../third_party/tcplp" ]
@@ -972,6 +974,7 @@ static_library("libopenthread-mtd") {
972974
}
973975

974976
static_library("libopenthread-radio") {
977+
configs = [ "../..:openthread_private_flags" ]
975978
sources = openthread_radio_sources
976979
public_deps = [ ":libopenthread_platform" ]
977980
public_configs = [ "../..:openthread_radio_config" ]

src/lib/hdlc/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#
2727

2828
static_library("libopenthread-hdlc") {
29+
configs = [ "../../../:openthread_private_flags" ]
2930
sources = [
3031
"hdlc.cpp",
3132
"hdlc.hpp",

src/lib/platform/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ config("platform_config") {
3737
}
3838

3939
static_library("libopenthread-platform") {
40+
configs = [ "../../..:openthread_private_flags" ]
4041
sources = platform_sources
4142
public_deps = [ "../../core:libopenthread_core_headers" ]
4243
public_configs = [ ":platform_config" ]

src/lib/spinel/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ source_set("spinel-api") {
7373
}
7474

7575
static_library("libopenthread-spinel-ncp") {
76+
configs = [ "../../..:openthread_private_flags" ]
7677
sources = spinel_sources
7778
public_deps = [
7879
":spinel-api",
@@ -86,6 +87,7 @@ static_library("libopenthread-spinel-ncp") {
8687
}
8788

8889
static_library("libopenthread-radio-spinel") {
90+
configs = [ "../../..:openthread_private_flags" ]
8991
sources = spinel_sources
9092
public_deps = [
9193
":spinel-api",
@@ -105,6 +107,7 @@ static_library("libopenthread-radio-spinel") {
105107
}
106108

107109
static_library("libopenthread-spinel-rcp") {
110+
configs = [ "../../..:openthread_private_flags" ]
108111
sources = spinel_sources
109112
public_deps = [
110113
":spinel-api",

0 commit comments

Comments
 (0)