Commit effcb5d8
effcb5d8ea89Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 5 files · ~5 modified
Description
refactor: rewrite immortal-string idiom to (&lit[1]) form
The runtime header and codegen output have used ("\xff" "literal" + 1) to mark a string literal as immortal — the 0xff prefix tells the GC scanner this is a static literal rather than a heap-allocated string, and the +1 advances the returned pointer past the marker byte. Apple clang emits -Wstring-plus-int on this idiom because, syntactically, it looks like adding an int to a char array.
Switch to (&("\xff" "literal")[1]) which clang accepts as ordinary array indexing. The pointer value is identical to the old form, so generated code is byte-equivalent at runtime.
Sites updated:
- lib/sp_runtime.h: SPL macro, sp_str_sub_range, sp_str_sub_range_len, sp_file_read.
- spinel_codegen.rb: c_string_literal emission template, plus the three "("\xff" + 1)" empty-string-literal sites.
The previous fix (commit 95d5c5e) silenced this by passing -Wno-string-plus-int unconditionally. With the idiom rewritten the flag is no longer needed, so revert it from Makefile, spinel, and spinel.bat.
Bootstrap converges (gen2.c == gen3.c). Linux gcc: 77 tests pass, 55 benches pass. Verified that clang -Werror -Wstring-plus-int compiles the generated C cleanly without -Wno-string-plus-int.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- effcb5d8ea89
- Parent
- 3aba184ef222
MakefilemodifiedView file
# make clean Remove built binariesCC ?= cc# -Wno-string-plus-int silences clang's warning on the immortal-string# idiom ("\xff" "literal" + 1). gcc doesn't have this warning but accepts# the flag silently, so it is safe to apply unconditionally.CFLAGS = -O2 -Wno-all -Wno-string-plus-intCFLAGS = -O2 -Wno-all# Per-function sections allow the linker to strip unused bigint/regexp# functions from the final binary (supported since GCC 2.7 / binutils 2.17).SEC_FLAGS = -ffunction-sections -fdata-sectionslib/sp_runtime.hmodifiedView file
Loading diff…
spinelmodifiedView file
Loading diff…
spinel.batmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…