Skip to content

Commit 764ad73

Browse files
committed
auto/clang: Add a NXT_NONSTRING macro
This is a wrapper around __attribute__ ((__nonstring__)). Traditionally this was used to mark char array variables that intentionally lacked a terminating NUL byte, this would then cause warning to either be quelled or emitted for various memory/string functions. GCC 15 introduced a new warning, Wunterminated-string-initialization, which will always warn on things like static const char hex[16] = "0123456789ABCDEF"; However this is very much intentionally not NUL terminated. When the Wunterminated-string-initialization patch went in, the "nonstriong" attribute didn't quell this warning, however a patch has since gone in (prior to the GCC 15 release) to enable this attribute to quell this warning. In Unit we disabled this new warning with an eye to being able to re-enable it again, this patch is the first in a series to do just that. So the above example would become static const char hex[16] NXT_NONSTRING = "0123456789ABCDEF"; Link: <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=44c9403ed1833ae71a59e84f9e37af3182be0df5> Link: <https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=622968990beee7499e951590258363545b4a3b57> Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178#c21> Cc: Alejandro Colomar <[email protected]> Reviewed-by: Alejandro Colomar <[email protected]> Signed-off-by: Andrew Clayton <[email protected]>
1 parent d7afeb2 commit 764ad73

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

auto/clang

+14
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,17 @@ nxt_feature_test="static void f(void) __attribute__ ((__unused__));
194194
return 0;
195195
}"
196196
. auto/feature
197+
198+
199+
nxt_feature="GCC __attribute__ nonstring"
200+
nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_NONSTRING
201+
nxt_feature_run=
202+
nxt_feature_incs=
203+
nxt_feature_libs=
204+
nxt_feature_test="int main(void) {
205+
static const char str[3] __attribute__ ((__nonstring__)) =
206+
\"ABC\";
207+
208+
return !!str[0];
209+
}"
210+
. auto/feature

src/nxt_clang.h

+11
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@
131131
#endif
132132

133133

134+
#if (NXT_HAVE_GCC_ATTRIBUTE_NONSTRING)
135+
136+
#define NXT_NONSTRING __attribute__((__nonstring__))
137+
138+
#else
139+
140+
#define NXT_NONSTRING
141+
142+
#endif
143+
144+
134145
#if (NXT_HAVE_BUILTIN_POPCOUNT)
135146

136147
#define nxt_popcount __builtin_popcount

0 commit comments

Comments
 (0)