1 // RUN: %clang_cc1 -no-opaque-pointers -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 i8*] [i8* bitcast (i32* @c0 to i8*), i8* bitcast (i32* @foo.l0 to i8*), i8* bitcast (void ()* @f0 to i8*), i8* bitcast (void ()* @f2 to i8*), i8* bitcast (i32* @g0 to i8*), i8* bitcast (i32* @g1 to i8*), i8* bitcast (i32* @g3 to i8*), i8* bitcast (i32* @g4 to i8*)], section "llvm.metadata"
13 // CHECK:      @llvm.compiler.used = appending global [3 x i8*] [i8* bitcast (void ()* @f2 to i8*), i8* bitcast (i32* @g3 to i8*), i8* bitcast (i32* @g4 to i8*)], 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) {}
30