gcc_attribute_func.c revision 1.6
1/*	$NetBSD: gcc_attribute_func.c,v 1.6 2025/05/16 16:49:43 rillig Exp $	*/
2# 3 "gcc_attribute_func.c"
3
4/*
5 * Tests for the GCC __attribute__ for functions.
6 *
7 * https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
8 */
9
10/* lint1-extra-flags: -X 351 */
11
12void deprecated_function(void)
13    __attribute__((__noreturn__))
14    __attribute__((__aligned__(8), __cold__))
15    __attribute__((__deprecated__("do not use while driving")));
16
17__attribute__((__cold__))
18void attribute_as_prefix(void);
19
20void __attribute__((__cold__)) attribute_after_type_spec(void);
21void *__attribute__((__cold__)) attribute_before_name(void);
22/*TODO: do not allow __attribute__ after function name */
23void *attribute_after_name __attribute__((__cold__))(void);
24void *attribute_after_parameters(void) __attribute__((__cold__));
25
26static void __attribute__((used))
27used_function(void)
28{
29}
30
31/* expect+2: warning: static function 'unused_function' unused [236] */
32static void
33unused_function(void)
34{
35}
36
37void
38/* expect+1: warning: parameter 'arr' unused in function 'param_attrs' [231] */
39param_attrs(int arr[3] __attribute__(()) __attribute__((__deprecated__)))
40{
41}
42
43void asm_function(void)
44    __asm__("asm_function_name")
45    __attribute__(()) __attribute__((__deprecated__));
46void renamed_function(void)
47    __symbolrename(renamed_function);
48