Skip to content

Waf chibios sign compare - #34647

Draft
khancyr wants to merge 7 commits into
ArduPilot:masterfrom
khancyr:waf_chibios_sign_compare
Draft

khancyr wants to merge 7 commits into
ArduPilot:masterfrom
khancyr:waf_chibios_sign_compare

Conversation

@khancyr

@khancyr khancyr commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enable back the sign/unsign comparison on C++ code when compiling chibios board. This was inhibited by wrong flag handling

fixs the part of code that are reported with the current toolchain

Tested: with the real -Werror, these all build:
CubeOrange copter and rover;
MatekF405 plane;
MatekH743 copter;
MatekL431-Periph and f103-GPS (AP_Periph);
the CubeOrange bootloader;
the IO firmware.

not fly tested

Update :
Fixed the four sites, plus the calls they were hiding (fatal errors, and MIN/MAX instantiations reported once per file). Swept 28 targets with the warning non-fatal (CAN, network and ext-flash bootloaders, F1/F3/F4/L4/G4/H7/H7A3, 7 AP_Periph, all iomcu variants, 4 vehicles), which found three more sites (network.cpp:445, can.cpp:287, AP_Periph/proximity.cpp); all fixed.

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Description

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Global Size Summary (Total Flash delta in bytes)

Built from 1c9df2b rebased onto 1f1251a

Board Periph tracker blimp bootloader copter heli iofw plane rover sub
DrotekP3Pro _ _ _ 0 _ _ _ _ _ _
Durandal _ +20 +20 _ +20 +20 _ +20 +20 +20
Hitec-Airspeed * _ _ _ _ _ _ _ _ _
KakuteF7 _ * * _ * * _ * * *
MambaH743v4 _ +4 +4 _ +4 +4 _ +4 +4 +4
MatekF405-CAN _ _ _ 0 _ _ _ _ _ _
MatekF405 _ * * _ * * _ * * *
MatekH743-bdshot _ +20 +20 _ +20 +20 _ +20 +20 +20
Pixhawk1-1M _ * * _ * * _ * * *
disco _ * * _ * * _ * * *
f103-GPS * _ _ _ _ _ _ _ _ _

@AP-Review

AP-Review commented Oct 6, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-10-06)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head c13598cc91.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/34647/1.html#pr34647

Thanks for tightening this. With -Wno-sign-compare now C-only, a few C++ comparisons the PR does not fix still break builds at c13598c. I reproduced each with arm-none-eabi-gcc 10.2.1:

Since -Wfatal-errors stops each file at its first error, a wider sweep (CAN, network and ext-flash bootloaders, AP_Periph variants, iomcu variants) would be worth doing before turning this on. I only built the targets above.

On the persistent-params commit: MatekH7A3 and MatekH7A3-Wing do have bootloaders larger than their 8 KiB page 0, with persistence enabled. So the 'no board hits this' line in the commit message isn't right, and the fix does help them. The params write at Util.cpp:325-329 still has no space check when the bootloader itself is being updated. Using the same fit test there would close that path.

@khancyr
khancyr force-pushed the waf_chibios_sign_compare branch from c13598c to 27afd29 Compare October 7, 2026 17:28
@AP-Review

AP-Review commented Oct 7, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-10-07)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head 27afd29452.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/34647/2.html#pr34647

Thanks for the update. At 27afd29 the four build breaks from my last note are fixed, and the persistent-params write is now gated. The commit message also names the MatekH7A3 boards now.

Two more C++ comparisons still break builds now that -Wno-sign-compare is C-only (https://github.com/ArduPilot/ardupilot/pull/34647/files#diff-7d695263dc1bd6a88d12cd548aa30f977f387796b6b97d3c739cde0487071002R1241). Both are in driver code that only some boards compile. I reproduced them with arm-none-eabi-gcc 10.2.1:

  • libraries/AP_Radio/AP_Radio.cpp:260 MIN(strlen(tune_str), 92) fails in copter on skyviper-v2450 and skyviper-journey (both on the build server), and on skyviper-f412-rev1. On journey, libraries/AP_Radio/AP_Radio_bk2425.cpp:1118 and :1121 (dt > 50*d, dt > 120*d) fail as well.
  • libraries/AP_BattMonitor/AP_BattMonitor_TIBQ76952.cpp:677 MIN(AP_BATTMON_CELL_COUNT, ...) fails in AP_Periph on VM-L431-BMS, the only board that enables that driver.

size_t(92), uint32_t(50*d), uint32_t(120*d) and uint32_t(AP_BATTMON_CELL_COUNT) make all three build again; d is the positive packet interval, so behaviour is unchanged. These would go in their own AP_Radio and AP_BattMonitor commits, and the waf commit message would want a small update to match. I sampled boards rather than building the full list, so there may be others.

@khancyr
khancyr force-pushed the waf_chibios_sign_compare branch from 27afd29 to 1c9df2b Compare October 8, 2026 10:46
@AP-Review

AP-Review commented Oct 8, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-10-08)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head 1c9df2b4b0.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/34647/3.html#pr34647

Thanks for the update. At 1c9df2b the AP_Radio and TIBQ76952 casts are in their own commits, and the waf commit message names the SkyViper boards and VM-L431-BMS. skyviper-journey copter and VM-L431-BMS AP_Periph now build here with the C++-only -Werror=sign-compare (https://github.com/ArduPilot/ardupilot/pull/34647/files#diff-7d695263dc1bd6a88d12cd548aa30f977f387796b6b97d3c739cde0487071002R1240). Reverting the casts makes them fail again. The other reviewers also saw skyviper-v2450 and skyviper-f412-rev1 build. Commits 1-5 are unchanged from the last review. Nothing outstanding from my side.

The one red check is 'test sub' (MotorThrustHoverParameterIgnore and TestLogDownloadLogRestart). It passed on this PR's two previous heads and on master at the base, and none of the code changed here is compiled into SITL Sub. It looks unrelated, but I haven't re-run it, so a re-run would be needed before merge.

The full board matrix wasn't built. The sample was 23 targets across F1/F4/F7/G4/L4/H7, vehicle, AP_Periph, bootloader and iofirmware builds, plus the 106 passing CI checks.


for (int32_t i = 0; i <= count+1; ) {
if (i < count) {
for (int32_t i = 0; i <= int32_t(count)+1; ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can i go negative here? That would be a bit of a concern considering we're indexing with it down further.

Debug("Flash OK\n");
#if HAL_ENABLE_SAVE_PERSISTENT_PARAMS
if (persistent_params.get_length()) {
if (store_persistent_params && persistent_params.get_length()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a drive-by bugfix unrelated to "Waf chibios sign compare". That would make this patch the headline!

Comment thread libraries/AP_Radio/AP_Radio_bk2425.cpp Outdated
int32_t d = synctm.sync_time_us; // Time between packets, e.g. 5100 us
uint32_t dt = when - synctm.rx_time_us;
if (dt > 50*d) { // We have lost sync (missed 50 packets) so slow down the channel hopping until we resync
if (dt > uint32_t(50*d)) { // We have lost sync (missed 50 packets) so slow down the channel hopping until we resync

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't d's type be corrected?

uint8_t *tdest = (uint8_t *)dest;
uint8_t *tsrc = (uint8_t *)src;
for (int i=0; i<n; i++) {
for (size_t i=0; i<n; i++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (size_t i=0; i<n; i++) {
for (auto i=0; i<n; i++) {

khancyr and others added 7 commits November 20, 2026 10:24
Compare values of the same signedness, ready for -Werror=sign-compare
on ChibiOS. No change in behaviour: the lseek result is still compared
with the offset, the priority and sleep ticks get the same values, and
the bdshot decode index, which never goes negative, is now unsigned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compare values of the same signedness, ready for -Werror=sign-compare
on ChibiOS. No change in behaviour: arg and n are checked to be
positive before they are compared, the name and value ends are after
their starts, and the CAN timeouts only gain unsigned constants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compare the SBUS interval with an unsigned minimum, ready for
-Werror=sign-compare on ChibiOS. No change in behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compare the update interval with an unsigned limit, ready for
-Werror=sign-compare on ChibiOS. proximity_max_rate is checked to be
positive first, so there is no change in behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compare values of the same signedness, ready for -Werror=sign-compare
on ChibiOS. The packet interval d is set from the unsigned
sync_time_us, so make it uint32_t, which is how it was already
compared, and the tune length limit only changes type: no change in
behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compare the cell count limits with the same signedness, ready for
-Werror=sign-compare on ChibiOS. No change in behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ChibiOS flags have -Wno-sign-compare and -Wno-attributes, and are
copied into CXXFLAGS after the -Werror= flags every board gets, so
neither check has ever applied to ChibiOS C++ code. Keep them for C
only, which leaves C as it was, so C++ gets the same checks as on the
other boards.

The previous commits fix the comparisons this finds. Checked with the
warnings made non-fatal on vehicle, AP_Periph, bootloader and IO
firmware builds: CAN, network and external flash bootloaders, F1, F3,
F4, L4, G4, H7 and H7A3 boards, every iomcu variant, the SkyViper
boards and VM-L431-BMS, and CubeOrange copter, plane and rover with
every build option enabled. No attributes warning was found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@khancyr
khancyr force-pushed the waf_chibios_sign_compare branch from 1c9df2b to 3b877cc Compare November 20, 2026 15:13
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head 3b877cc524.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/34647/4.html#pr34647

This looks good to me at 3b877cc (rebased from 1c9df2b, which I last reviewed). Peter's points are addressed in the code: bk2425's d is now uint32_t, the bdshot index is uint32_t and can't go negative (it runs 0,3,2,5,4,...), and the persistent-params fix has been dropped because it is already on master as 80b96dc.

Notes

  • Tools/AP_Bootloader/support.cpp:399 keeping size_t i is right. Peter's suggested for (auto i=0; i<n; i++) makes i an int, which fails under the new C++ -Werror=sign-compare. A one-line reply on that thread would close it.
  • CI (still open): the earlier red 'test sub' was on the old head. At 3b877cc, 77 of 80 checks are still queued, so it needs to go green before merge.
  • Build coverage (still open): I sampled 11 targets (bootloaders, iofirmware, AP_Periph, SkyViper, CubeOrange, MatekH743), not the full board matrix. The ChibiOS CI jobs will cover the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants