diff options
| author | Andrew Clayton <a.clayton@nginx.com> | 2025-03-18 04:50:24 +0000 |
|---|---|---|
| committer | Andrew Clayton <a.clayton@nginx.com> | 2025-03-19 17:53:00 +0000 |
| commit | 764ad73fc7e3cbbe48b259159340e063f7d7b082 (patch) | |
| tree | efdc3832c52c4abf53eb5b1286a21e4f2885a325 | |
| parent | d7afeb2b94f1cd72ed02403609e5484f9514e5eb (diff) | |
| download | unit-764ad73fc7e3cbbe48b259159340e063f7d7b082.tar.gz unit-764ad73fc7e3cbbe48b259159340e063f7d7b082.tar.bz2 | |
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 <alx@kernel.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
| -rw-r--r-- | auto/clang | 14 | ||||
| -rw-r--r-- | src/nxt_clang.h | 11 |
2 files changed, 25 insertions, 0 deletions
@@ -194,3 +194,17 @@ nxt_feature_test="static void f(void) __attribute__ ((__unused__)); return 0; }" . auto/feature + + +nxt_feature="GCC __attribute__ nonstring" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_NONSTRING +nxt_feature_run= +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main(void) { + static const char str[3] __attribute__ ((__nonstring__)) = + \"ABC\"; + + return !!str[0]; + }" +. auto/feature diff --git a/src/nxt_clang.h b/src/nxt_clang.h index 6803ffc8..872f1527 100644 --- a/src/nxt_clang.h +++ b/src/nxt_clang.h @@ -131,6 +131,17 @@ #endif +#if (NXT_HAVE_GCC_ATTRIBUTE_NONSTRING) + +#define NXT_NONSTRING __attribute__((__nonstring__)) + +#else + +#define NXT_NONSTRING + +#endif + + #if (NXT_HAVE_BUILTIN_POPCOUNT) #define nxt_popcount __builtin_popcount |
