Skip to content

include/assert: stringify assert expressions at the first macro level - #21764

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Fix-Point:fix-assert-stringify
Nov 13, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Fix-Point:fix-assert-stringify

Conversation

@Fix-Point

@Fix-Point Fix-Point commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Related to: #21491
This PR fixes assert-expression stringification so macro-heavy assert conditions no longer bloat .rodata. DEBUGASSERT() expanded its argument before stringification (the DEBUGASSERT(f) -> _ASSERT(f) -> #f chain macro-replaces f at the first boundary), so #f captured the expanded token sequence; with __INT128_DEFINED, FLS() expands to both FLS64() and FLS128() (a full ternary tree each), and a single DEBUGASSERT(nodesize >= MM_MIN_CHUNK) in mm/mm_heap/mm.h reached 67,165 bytes — the +49 KB .rodata reported on qemu-intel64 with CONFIG_DEBUG_ASSERTIONS_EXPRESSION.

The fix stringifies at the first macro level: _ASSERT()/_VERIFY() take the expression string as a 4th parameter, and DEBUGASSERT()/DEBUGVERIFY()/ASSERT()/VERIFY()/assert() pass #f themselves. The one in-tree caller outside assert.h — ostest's wdtest_assert() in nuttx-apps — is updated by a companion PR (Depends-On link there).

Impact

  • User: none — the assertion condition is evaluated exactly as before; only the diagnostic string changes (it now shows the source text, e.g. nodesize >= MM_MIN_CHUNK, which is the form the source uses).
  • Build: no config or build-system change.
  • Compatibility: _ASSERT(f,file,line)/_VERIFY(f,file,line) gain a 4th parameter; all in-tree callers are updated here and in the companion apps PR.
  • Security: no change.

Testing

  • Host: qemu-intel64 (x86_64, gcc 13), CONFIG_DEBUG_ASSERTIONS=y + CONFIG_DEBUG_ASSERTIONS_EXPRESSION=y.
  • Build: make links clean (LD: nuttx).
  • .rodata: strings -n 1000 nuttx finds no large string (was a 67,165-byte one); the assert strings read nodesize >= MM_MIN_CHUNK / nodesize >= MM_SIZEOF_ALLOCNODE (literal source text); the largest string in the image is 223 bytes (a GCC command line).

Depends-on: apache/nuttx-apps#4033

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Nov 12, 2026
@Fix-Point
Fix-Point force-pushed the fix-assert-stringify branch 2 times, most recently from 0832e9b to 0eb893c Compare November 12, 2026 08:05
The chain DEBUGASSERT(f) -> _ASSERT(f) -> #f macro-replaces f before the
#f stringification (the DEBUGASSERT replacement list has no # or ##), so
the assert strings held the expanded token sequences.  With
__INT128_DEFINED, FLS() expands to both FLS64() and FLS128() (a full
ternary tree each), so one DEBUGASSERT(nodesize >= MM_MIN_CHUNK) in
mm/mm_heap/mm.h reached 67,165 bytes -- the +49 KB .rodata on
qemu-intel64 with CONFIG_DEBUG_ASSERTIONS_EXPRESSION.

Stringify at the first macro level instead: _ASSERT()/_VERIFY() take the
expression string as a parameter, and the five assert entry points
(DEBUGASSERT/DEBUGVERIFY/ASSERT/VERIFY/assert) pass #f themselves.  The
strings now hold the source text, and the largest string in the
qemu-intel64 image drops from 67,165 to 223 bytes.

_ASSERT()/_VERIFY() gain a 4th parameter; the one in-tree caller outside
assert.h (ostest's wdtest_assert() in nuttx-apps) is updated by a
companion PR.

Verified on qemu-intel64 with CONFIG_DEBUG_ASSERTIONS_EXPRESSION: the
image links clean, strings -n 1000 finds no large string, and the assert
strings read "nodesize >= MM_MIN_CHUNK".

Assisted-By: mimo-v2.6-pro
Signed-off-by: ouyangxiangzhen <[email protected]>
@Fix-Point
Fix-Point force-pushed the fix-assert-stringify branch from 0eb893c to f840f27 Compare November 12, 2026 09:22
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

qemu-intel64

  • Data: .rodata -18,720 B (-14.8%, 108,185 B)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx/actions/runs/43190960417

@xiaoxiang781216
xiaoxiang781216 merged commit 562db43 into apache:master Nov 13, 2026
47 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants