Masked the SMP remap core maps to silence a false -O2 array bounds error - #728
Merged
Merged
Conversation
…TX_THREAD_SMP_CORE_MASK, so the computed core index is provably within the schedule list and GCC no longer reports a false array bounds error at -O2 The remap solution search derives a core number from the lowest set bit of the supplied core maps and uses it to index _tx_thread_smp_schedule_list and the local remap list, both of which have TX_THREAD_SMP_MAX_CORES entries. Every map reaching the function is already restricted to the cores that are present, because tx_thread_smp_cores_allowed is masked with TX_THREAD_SMP_CORE_MASK in tx_thread_create and tx_thread_smp_core_exclude. The compiler cannot see that invariant, however, so when the function is inlined into _tx_thread_system_suspend at -O2 GCC assumes the bit number can be as high as 31 and reports an out of bounds array subscript, which fails the build under -Werror. Masking the three incoming maps with TX_THREAD_SMP_CORE_MASK makes the invariant explicit. The masks are semantic no-ops, so scheduling behaviour is unchanged. The first core queue entry is now initialized as well, since the narrowed value range lets the compiler consider an empty queue on entry. Fixes eclipse-threadx#469 Assisted-by: Copilot (Opus 5) <noreply@github.com>
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.
Fixes #469
_tx_thread_smp_remap_solution_findindexes_tx_thread_smp_schedule_listwiththe lowest set bit of the core maps it is given. Every caller already masks
those maps with
TX_THREAD_SMP_CORE_MASK, but the compiler cannot see it, sowhen the function is inlined into
_tx_thread_system_suspendat-O2GCCassumes a bit number as high as 31 and reports an out-of-bounds subscript.
-Werrorturns that into a build failure.Masked the three incoming maps at the top of the function, in both the inline
version in
common_smp/inc/tx_thread.hand the twin intx_thread_smp_utilities.c. The masks are semantic no-ops, so scheduling isunchanged, but the range is now visible to the optimizer. The first core queue
entry is also initialized, because the narrowed range lets GCC consider an empty
queue and warn about that instead.
Reproduced on the Cortex-A9 SMP port with arm-none-eabi-gcc 13.2.1, and clean
afterwards across -O2, -O3 and -Os and 2, 4 and 8 core configurations. SMP suite
116/116.