| 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 |
|
| 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 |
|
| 21 |
__attribute__((retain,used)) static void f0(void) {} |
| 22 |
__attribute__((retain)) static void f1(void) {} // expected-warning {{unused function 'f1'}} |
| 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; |