xref: /llvm-project/clang/test/Sema/attr-retain.c (revision e765e0bc8ed06ebb186a9905227273517f0b7240)
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -Wunused-function
2 
3 /// We allow 'retain' on non-ELF targets because 'retain' is often used together
4 /// with 'used'. 'used' has GC root semantics on macOS and Windows. We want
5 /// users to just write retain,used and don't need to dispatch on binary formats.
6 
7 extern char test1[] __attribute__((retain));       // expected-warning {{'retain' attribute ignored on a non-definition declaration}}
8 extern const char test2[] __attribute__((retain)); // expected-warning {{'retain' attribute ignored on a non-definition declaration}}
9 const char test3[] __attribute__((retain)) = "";
10 
11 struct __attribute__((retain)) s { // expected-warning {{'retain' attribute only applies to variables with non-local storage, functions, and Objective-C methods}}
12 };
13 
foo(void)14 void foo(void) {
15   static int a __attribute__((retain));
16   int b __attribute__((retain)); // expected-warning {{'retain' attribute only applies to variables with non-local storage, functions, and Objective-C methods}}
17   (void)a;
18   (void)b;
19 }
20 
f0(void)21 __attribute__((retain,used)) static void f0(void) {}
f1(void)22 __attribute__((retain)) static void f1(void) {} // expected-warning {{unused function 'f1'}}
f2(void)23 __attribute__((retain)) void f2(void) {}
24 
25 /// Test attribute merging.
26 int tentative;
27 int tentative __attribute__((retain));
28 extern int tentative;
29 int tentative = 0;
30