| 1 |
// RUN: %clang_cc1 -emit-llvm -triple x86_64 %s -o - | FileCheck %s |
| 2 |
|
| 3 |
/// Set !retain regardless of the target. The backend will lower !retain to |
| 4 |
/// SHF_GNU_RETAIN on ELF and ignore the metadata for other binary formats. |
| 5 |
// CHECK: @c0 ={{.*}} constant i32 {{.*}} |
| 6 |
// CHECK: @foo.l0 = internal global i32 {{.*}} |
| 7 |
// CHECK: @g0 ={{.*}} global i32 {{.*}} |
| 8 |
// CHECK-NEXT: @g1 ={{.*}} global i32 {{.*}} |
| 9 |
// CHECK-NEXT: @g3 = internal global i32 {{.*}} |
| 10 |
// CHECK-NEXT: @g4 = internal global i32 0, section ".data.g"{{.*}} |
| 11 |
|
| 12 |
// CHECK: @llvm.used = appending global [8 x ptr] [ptr @c0, ptr @foo.l0, ptr @f0, ptr @f2, ptr @g0, ptr @g1, ptr @g3, ptr @g4], section "llvm.metadata" |
| 13 |
// CHECK: @llvm.compiler.used = appending global [3 x ptr] [ptr @f2, ptr @g3, ptr @g4], section "llvm.metadata" |
| 14 |
|
| 15 |
const int c0 __attribute__((retain)) = 42; |
| 16 |
|
| 17 |
void foo(void) { |
| 18 |
static int l0 __attribute__((retain)) = 2; |
| 19 |
} |
| 20 |
|
| 21 |
__attribute__((retain)) int g0; |
| 22 |
int g1 __attribute__((retain)); |
| 23 |
__attribute__((retain)) static int g2; |
| 24 |
__attribute__((used, retain)) static int g3; |
| 25 |
__attribute__((used, retain, section(".data.g"))) static int g4; |
| 26 |
|
| 27 |
void __attribute__((retain)) f0(void) {} |
| 28 |
static void __attribute__((retain)) f1(void) {} |
| 29 |
static void __attribute__((used, retain)) f2(void) {} |