summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Partin <tristan@partin.io>2024-07-11 10:11:27 -0500
committerDylan Baker <dylan@pnwbakers.com>2025-11-18 08:22:34 -0800
commitccbc91c23393ad9754e1019c4ce5853cf5c8a8e3 (patch)
tree27543d9a13b1dd22531d18845b3e1f4ba762a35a
parentbf45777a1d979465abea3cd1ade8ff227eacdf9a (diff)
downloadmeson-ccbc91c23393ad9754e1019c4ce5853cf5c8a8e3.tar.gz
Add support for the `counted_by` attribute
This is a new attribute released in GCC 15 and clang 18. It isn't supported in C++ compilers at the moment.
-rw-r--r--docs/markdown/Reference-tables.md3
-rw-r--r--docs/markdown/snippets/add_counted_by_attribute.md4
-rw-r--r--mesonbuild/compilers/c_function_attributes.py7
-rw-r--r--test cases/common/197 function attributes/meson.build29
4 files changed, 37 insertions, 6 deletions
diff --git a/docs/markdown/Reference-tables.md b/docs/markdown/Reference-tables.md
index 9ac24a43c..4a3bf288b 100644
--- a/docs/markdown/Reference-tables.md
+++ b/docs/markdown/Reference-tables.md
@@ -297,6 +297,7 @@ which are supported by GCC, Clang, and other compilers.
| const |
| constructor |
| constructor_priority |
+| counted_by⁸ |
| deprecated |
| destructor |
| error |
@@ -352,6 +353,8 @@ which are supported by GCC, Clang, and other compilers.
⁷ *New in 1.5.0*
+⁸ *New in 1.10.0*
+
### MSVC __declspec
These values are supported using the MSVC style `__declspec` annotation,
diff --git a/docs/markdown/snippets/add_counted_by_attribute.md b/docs/markdown/snippets/add_counted_by_attribute.md
new file mode 100644
index 000000000..aa80b6dad
--- /dev/null
+++ b/docs/markdown/snippets/add_counted_by_attribute.md
@@ -0,0 +1,4 @@
+## Support for the `counted_by` attribute
+
+`compiler.has_function_attribute()` now supports for the new `counted_by`
+attribute.
diff --git a/mesonbuild/compilers/c_function_attributes.py b/mesonbuild/compilers/c_function_attributes.py
index 4c8aa7054..e425dbfa2 100644
--- a/mesonbuild/compilers/c_function_attributes.py
+++ b/mesonbuild/compilers/c_function_attributes.py
@@ -30,6 +30,13 @@ C_FUNC_ATTRIBUTES = {
'int foo(void) __attribute__((constructor));',
'constructor_priority':
'int foo( void ) __attribute__((__constructor__(65535/2)));',
+ 'counted_by':
+ '''
+ struct foo {
+ unsigned int count;
+ char bar[] __attribute__((counted_by(count)));
+ };
+ ''',
'deprecated':
'int foo(void) __attribute__((deprecated("")));',
'destructor':
diff --git a/test cases/common/197 function attributes/meson.build b/test cases/common/197 function attributes/meson.build
index db7e3af32..a2dc5b76f 100644
--- a/test cases/common/197 function attributes/meson.build
+++ b/test cases/common/197 function attributes/meson.build
@@ -117,7 +117,16 @@ if ['gcc', 'intel'].contains(c.get_id())
endif
endif
+if c.get_id() == 'clang'
+ if c.version().version_compare('>= 18.0.0')
+ attributes += 'counted_by'
+ endif
+endif
+
if c.get_id() == 'gcc'
+ if c.version().version_compare('>= 15.1')
+ attributes += 'counted_by'
+ endif
if c.version().version_compare('>= 14.1')
attributes += 'null_terminated_string_arg'
endif
@@ -128,19 +137,27 @@ if get_option('mode') == 'single'
x = c.has_function_attribute(a)
expected_result = expected.get(a, expected_default)
assert(x == expected_result, '@0@: @1@'.format(c.get_id(), a))
- x = cpp.has_function_attribute(a)
- assert(x == expected_result, '@0@: @1@'.format(cpp.get_id(), a))
+ # counted_by is not currently supported by GCC or clang on C++
+ if a != 'counted_by'
+ x = cpp.has_function_attribute(a)
+ assert(x == expected_result, '@0@: @1@'.format(cpp.get_id(), a))
+ endif
endforeach
else
- multi_expected = []
+ multi_expected_c = []
+ multi_expected_cpp = []
foreach a : attributes
if expected.get(a, expected_default)
- multi_expected += a
+ multi_expected_c += a
+ # counted_by is not currently supported by GCC or clang on C++
+ if a != 'counted_by'
+ multi_expected_cpp += a
+ endif
endif
endforeach
multi_check = c.get_supported_function_attributes(attributes)
- assert(multi_check == multi_expected, 'get_supported_function_arguments works (C)')
+ assert(multi_check == multi_expected_c, 'get_supported_function_arguments works (C)')
multi_check = cpp.get_supported_function_attributes(attributes)
- assert(multi_check == multi_expected, 'get_supported_function_arguments works (C++)')
+ assert(multi_check == multi_expected_cpp, 'get_supported_function_arguments works (C++)')
endif