diff options
author | Tristan Partin <tristan@partin.io> | 2024-05-07 14:51:40 -0500 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2024-05-07 15:33:32 -0700 |
commit | 8cb16b2d6a97514bf17aa8ca2f6bf098cfc5bcbf (patch) | |
tree | eafe5a76fe3908c389ce27d4650af49ff794e795 | |
parent | 23eb7ba700cd6c53d5491cc4f99c532629efa1e2 (diff) | |
download | meson-8cb16b2d6a97514bf17aa8ca2f6bf098cfc5bcbf.zip meson-8cb16b2d6a97514bf17aa8ca2f6bf098cfc5bcbf.tar.gz meson-8cb16b2d6a97514bf17aa8ca2f6bf098cfc5bcbf.tar.bz2 |
Add support for GCC's null_terminated_string_arg function attribute
This is new as of 14.1.
-rw-r--r-- | docs/markdown/Reference-tables.md | 99 | ||||
-rw-r--r-- | docs/markdown/snippets/null_terminated_string_arg.md | 13 | ||||
-rw-r--r-- | mesonbuild/compilers/c_function_attributes.py | 2 | ||||
-rw-r--r-- | test cases/common/197 function attributes/meson.build | 6 |
4 files changed, 72 insertions, 48 deletions
diff --git a/docs/markdown/Reference-tables.md b/docs/markdown/Reference-tables.md index d30d22a..2357ff4 100644 --- a/docs/markdown/Reference-tables.md +++ b/docs/markdown/Reference-tables.md @@ -272,54 +272,55 @@ These values are supported using the GCC style `__attribute__` annotations, which are supported by GCC, Clang, and other compilers. -| Name | -|--------------------------| -| alias | -| aligned | -| alloc_size | -| always_inline | -| artificial | -| cold | -| const | -| constructor | -| constructor_priority | -| deprecated | -| destructor | -| error | -| externally_visible | -| fallthrough | -| flatten | -| format | -| format_arg | -| force_align_arg_pointerÂł | -| gnu_inline | -| hot | -| ifunc | -| malloc | -| noclone | -| noinline | -| nonnull | -| noreturn | -| nothrow | -| optimize | -| packed | -| pure | -| retain⎠| -| returns_nonnull | -| sectionâ” | -| sentinelâ” | -| unused | -| used | -| vector_sizeⶠ| -| visibility* | -| visibility:defaultâ | -| visibility:hiddenâ | -| visibility:internalâ | -| visibility:protectedâ | -| warning | -| warn_unused_result | -| weak | -| weakref | +| Name | +|-----------------------------| +| alias | +| aligned | +| alloc_size | +| always_inline | +| artificial | +| cold | +| const | +| constructor | +| constructor_priority | +| deprecated | +| destructor | +| error | +| externally_visible | +| fallthrough | +| flatten | +| format | +| format_arg | +| force_align_arg_pointerÂł | +| gnu_inline | +| hot | +| ifunc | +| malloc | +| noclone | +| noinline | +| nonnull | +| noreturn | +| nothrow | +| null_terminated_string_argâ· | +| optimize | +| packed | +| pure | +| retain⎠| +| returns_nonnull | +| sectionâ” | +| sentinelâ” | +| unused | +| used | +| vector_sizeⶠ| +| visibility* | +| visibility:defaultâ | +| visibility:hiddenâ | +| visibility:internalâ | +| visibility:protectedâ | +| warning | +| warn_unused_result | +| weak | +| weakref | \* *Changed in 0.52.0* the "visibility" target no longer includes "protected", which is not present in Apple's clang. @@ -335,6 +336,8 @@ which are supported by GCC, Clang, and other compilers. ⶠ*New in 1.1.0* +â· *New in 1.5.0* + ### MSVC __declspec These values are supported using the MSVC style `__declspec` annotation, diff --git a/docs/markdown/snippets/null_terminated_string_arg.md b/docs/markdown/snippets/null_terminated_string_arg.md new file mode 100644 index 0000000..2ba1755 --- /dev/null +++ b/docs/markdown/snippets/null_terminated_string_arg.md @@ -0,0 +1,13 @@ +## Added support for GCC's `null_terminated_string_arg` function attribute + +You can now check if a compiler support the `null_terminated_string_arg` +function attribute via the `has_function_attribute()` method on the +[[@compiler]] object. + +```meson +cc = meson.get_compiler('c') + +if cc.has_function_attribute('null_terminated_string_arg') + # We have it... +endif +``` diff --git a/mesonbuild/compilers/c_function_attributes.py b/mesonbuild/compilers/c_function_attributes.py index eec872b..a7258a1 100644 --- a/mesonbuild/compilers/c_function_attributes.py +++ b/mesonbuild/compilers/c_function_attributes.py @@ -80,6 +80,8 @@ C_FUNC_ATTRIBUTES = { 'int foo(void) __attribute__((noreturn));', 'nothrow': 'int foo(void) __attribute__((nothrow));', + 'null_terminated_string_arg': + 'int foo(const char * p) __attribute__((null_terminated_string_arg(1)));', 'optimize': '__attribute__((optimize(3))) int foo(void) { return 0; }', 'packed': diff --git a/test cases/common/197 function attributes/meson.build b/test cases/common/197 function attributes/meson.build index 530db93..db7e3af 100644 --- a/test cases/common/197 function attributes/meson.build +++ b/test cases/common/197 function attributes/meson.build @@ -117,6 +117,12 @@ if ['gcc', 'intel'].contains(c.get_id()) endif endif +if c.get_id() == 'gcc' + if c.version().version_compare('>= 14.1') + attributes += 'null_terminated_string_arg' + endif +endif + if get_option('mode') == 'single' foreach a : attributes x = c.has_function_attribute(a) |