Skip to content

Commit

Permalink
Add support for the counted_by attribute
Browse files Browse the repository at this point in the history
This is a new attribute being developed.
  • Loading branch information
tristan957 committed Jul 16, 2024
1 parent a51d5f3 commit 3dc652b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/markdown/Reference-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ which are supported by GCC, Clang, and other compilers.
| const |
| constructor |
| constructor_priority |
| counted_by |
| deprecated |
| destructor |
| error |
Expand Down Expand Up @@ -338,6 +339,8 @@ which are supported by GCC, Clang, and other compilers.

*New in 1.5.0*

*New in 1.6.0*

### MSVC __declspec

These values are supported using the MSVC style `__declspec` annotation,
Expand Down
4 changes: 4 additions & 0 deletions docs/markdown/snippets/add_counted_by_attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Support for the `counted_by` attribute

`compiler.has_function_attribute()` has grown support for the new `counted_by`
attribute.
7 changes: 7 additions & 0 deletions mesonbuild/compilers/c_function_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
'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':
Expand Down
9 changes: 9 additions & 0 deletions test cases/common/197 function attributes/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3dc652b

Please sign in to comment.