Fix build-SITL-Mac VLA-folding-constant error in log.c#11679
Open
sensei-hacker wants to merge 2 commits into
Open
Fix build-SITL-Mac VLA-folding-constant error in log.c#11679sensei-hacker wants to merge 2 commits into
sensei-hacker wants to merge 2 commits into
Conversation
_logBufferHex() sized a stack buffer using two `const size_t` locals (charsPerByte, maxBytes). In C, const-qualified objects are not integer constant expressions, so the array size expression was technically a variable-length array; recent AppleClang treats reliance on its extension that folds such expressions back to a constant as an error under -Werror -Wgnu-folding-constant, breaking build-SITL-Mac. Replace the const locals with a local enum, whose members are genuine integer constant expressions in C. The buffer size and behavior are unchanged (13 + 5*8 + 1 = 54 bytes either way).
Contributor
PR Summary by QodoFix AppleClang VLA folding-constant build error in _logBufferHex()
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Contributor
STATIC_ASSERT expands to a typedef of a char array sized by the condition, a common compile-time-assertion trick. This call site's condition compared GPS_DEGREES_DIVIDER (already 10000000L) against the floating-point literal 1e7. Per C11 6.6p6, integer constant expressions may not contain floating constants, so despite being trivially foldable, AppleClang's -Wgnu-folding-constant -Werror rejects it. Replace 1e7 with 10000000L to match GPS_DEGREES_DIVIDER's own literal form, making the condition a pure integer constant expression. No change to the assertion's truth value or any runtime behavior.
|
Test firmware build ready — commit Download firmware for PR #11679 238 targets built. Find your board's
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
build-SITL-MacCI failure onmaintenance-10.x: AppleClang errors onsrc/main/common/log.c:210under-Werror -Wgnu-folding-constant.Root Cause
_logBufferHex()sizes a stack buffer with:In C (unlike C++), a
const-qualified object is not an integer constant expression. So this array size is technically a variable-length array. Compilers have long tolerated this via a GNU extension that folds it back to a fixed size when the value happens to be known — but a newer AppleClang on the macOS CI runner now warns (and-Werrorpromotes to error) when code relies on that extension.Fix
Replace the two
const size_tlocals with a localenum:Enum constants are genuine integer constant expressions in C (C11 6.6p6), so the buffer size expression is now a real compile-time constant on every compiler — not just one that happens to fold it. This removes the VLA classification at the root rather than suppressing the warning.
No behavior change: buffer size is
13 + 5*8 + 1 = 54bytes both before and after.Testing
log.c.const size_tlocals vs.enumconstants differ in constant-expression classification per the C standard (C11 6.6p6 explicitly lists enumeration constants as valid ICE operands, and excludes const-qualified objects).build-SITL-MacCI leg on this PR will provide the authoritative confirmation against the actual AppleClang toolchain that originally reported the error.Code Review
Reviewed with inav-code-review agent — no critical or important issues found. Approved.
Fixes the build-SITL-Mac failure reported against maintenance-10.x (see PR #11678 CI for original occurrence).