xref: /llvm-project/clang/test/CodeGen/weak_constant.c (revision dd2362a8bab312dffc42bfcb30ad1340840ef581)
1 // RUN: %clang_cc1 -w -emit-llvm %s -O1 -o - | FileCheck %s
2 // This used to "check for bug compatibility with gcc".
3 // Now it checks that that the "weak" declaration makes the value
4 // fully interposable whereas a "selectany" one is handled as constant
5 // and propagated.
6 
7 // CHECK: @x = weak {{.*}}constant i32 123
8 const int x __attribute((weak)) = 123;
9 
10 // CHECK: @y = weak_odr {{.*}}constant i32 234
11 const int y __attribute((selectany)) = 234;
12 
f(void)13 int* f(void) {
14   return &x;
15 }
16 
g(void)17 int g(void) {
18   // CHECK: load i32, ptr @x
19   // CHECK-NOT: ret i32 123
20   return *f();
21 }
22 
k(void)23 int *k(void) {
24   return &y;
25 }
26 
l(void)27 int l(void) {
28   // CHECK-NOT: load i32, ptr @y
29   // CHECK: ret i32 234
30   return *k();
31 }
32