This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e411a17d7f33c3cd5b5fcab402aa6c449716e4fa Author: ouyangxiangzhen <[email protected]> AuthorDate: Tue Nov 10 14:07:30 2026 +0800 compiler: define is_constexpr() per compiler capability is_constexpr() was (0) everywhere except the GNU section, so any constant-folding dispatch built on it silently lost its compile-time path on non-GNU toolchains, and a shared fallback would claim support no one verified. Give each compiler section only the definition that is proven on a real toolchain or documented by the compiler vendor: - GCC/Clang: __builtin_constant_p(). - SDCC: keep (0). The classic sizeof(void) trick was verified to give correct values on SDCC 4.0.0 (z80 at all scopes; mcs51 at expression, array and file-scope static-init scope), but on mcs51 it cannot be used inside enum constant initializers ("error 174: enumeration constant not an integer"), each mcs51 expansion warns 88/127 (generic-pointer casts), and its payoff on 8/16-bit targets is unproven. A plain (0) keeps every constant-expression scope working and div_const() falls back to plain division. - TASKING: __builtin_constant_p(), listed as a compiler intrinsic in the TASKING VX-toolset for TriCore User Guide (MA160-800, v6.4r1), "Intrinsic Functions" - "Miscellaneous Intrinsic Functions": "int __builtin_constant_p( type exp ); During compilation, constant propagation returns 1 if exp is a constant expression. Otherwise, it returns 0. Note that type can be int, long, long long, double or long double." https://www.tasking.com/documentation/tricore/ctc/reference/clang_intrinsics_misc.html - IAR: __builtin_constant_p(), listed under "Supported GCC built-in functions", IAR Embedded Workbench for Arm 10.10.x: https://docs.iar.com/ewarm/10.1x/en/iar-c-c---development/intrinsic-functions/supported-gcc-built-in-functions.html That page documents a deviation from GCC: the result does not depend on the optimization level and may be 0 for expressions the compiler later constant-folds, which is the safe direction for this macro (a 0 answer just takes the plain-arithmetic path). - Zilog/MSVC/generic: keep (0). The trick was rejected at parse level by z88dk sccz80 and no real MSVC compiler was obtainable. Neither TASKING nor IAR was available locally, so those two entries rest on the vendor documentation cited above rather than on a local toolchain run. Cross-compiler probe evidence for the SDCC entry (gcc -m64/-m32 and clang run output; SDCC z80/mcs51 asm constants; literal/enum/global/local/volatile at expression scope; the nested ternary with a function-call dead branch in static initializers) is recorded in .review-tmp/is-constexpr-verify.md. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <[email protected]> --- include/nuttx/compiler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 14325b23f1f..11e5647eceb 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -1152,7 +1152,7 @@ # define const_function # define predict_true(x) (x) # define predict_false(x) (x) -# define is_constexpr(x) (0) +# define is_constexpr(x) __builtin_constant_p(x) # define compiler_assume(x) # define locate_code(n) # define aligned_data(n) @@ -1426,7 +1426,7 @@ # define const_function # define predict_true(x) (x) # define predict_false(x) (x) -# define is_constexpr(x) (0) +# define is_constexpr(x) __builtin_constant_p(x) # define compiler_assume(x) # define aligned_data(n) __attribute__((aligned(n))) # define locate_code(n) __attribute__((section(n)))
