xref: /aosp_15_r20/external/clang/test/CodeGen/available-externally-suppress.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-apple-darwin10 %s | FileCheck %s
2*67e74705SXin Li // RUN: %clang_cc1 -O2 -fno-inline -emit-llvm -o - -triple x86_64-apple-darwin10 %s | FileCheck %s
3*67e74705SXin Li // RUN: %clang_cc1 -flto -O2 -fno-inline -emit-llvm -o - -triple x86_64-apple-darwin10 %s | FileCheck %s -check-prefix=LTO
4*67e74705SXin Li 
5*67e74705SXin Li // Ensure that we don't emit available_externally functions at -O0.
6*67e74705SXin Li // Also should not emit them at -O2, unless -flto is present in which case
7*67e74705SXin Li // we should preserve them for link-time inlining decisions.
8*67e74705SXin Li int x;
9*67e74705SXin Li 
f0(int y)10*67e74705SXin Li inline void f0(int y) { x = y; }
11*67e74705SXin Li 
12*67e74705SXin Li // CHECK-LABEL: define void @test()
13*67e74705SXin Li // CHECK: declare void @f0(i32)
14*67e74705SXin Li // LTO-LABEL: define void @test()
15*67e74705SXin Li // LTO: define available_externally void @f0
test()16*67e74705SXin Li void test() {
17*67e74705SXin Li   f0(17);
18*67e74705SXin Li }
19*67e74705SXin Li 
f1(int x)20*67e74705SXin Li inline int __attribute__((always_inline)) f1(int x) {
21*67e74705SXin Li   int blarg = 0;
22*67e74705SXin Li   for (int i = 0; i < x; ++i)
23*67e74705SXin Li     blarg = blarg + x * i;
24*67e74705SXin Li   return blarg;
25*67e74705SXin Li }
26*67e74705SXin Li 
27*67e74705SXin Li // CHECK: @test1
28*67e74705SXin Li // LTO: @test1
test1(int x)29*67e74705SXin Li int test1(int x) {
30*67e74705SXin Li   // CHECK: br i1
31*67e74705SXin Li   // CHECK-NOT: call {{.*}} @f1
32*67e74705SXin Li   // CHECK: ret i32
33*67e74705SXin Li   // LTO: br i1
34*67e74705SXin Li   // LTO-NOT: call {{.*}} @f1
35*67e74705SXin Li   // LTO: ret i32
36*67e74705SXin Li   return f1(x);
37*67e74705SXin Li }
38