[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Driver / lto.c
blobb1d729a1ece70b99ce0393d20b0e84217e8f3f23
1 // -flto causes a switch to llvm-bc object files.
2 // RUN: %clang -ccc-print-phases -c %s -flto 2> %t
3 // RUN: FileCheck -check-prefix=CHECK-COMPILE-ACTIONS < %t %s
4 //
5 // CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir
6 // CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc
8 // RUN: %clang -ccc-print-phases %s -flto 2> %t
9 // RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s
11 // CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}lto.c", c
12 // CHECK-COMPILELINK-ACTIONS: 1: preprocessor, {0}, cpp-output
13 // CHECK-COMPILELINK-ACTIONS: 2: compiler, {1}, ir
14 // CHECK-COMPILELINK-ACTIONS: 3: backend, {2}, lto-bc
15 // CHECK-COMPILELINK-ACTIONS: 4: linker, {3}, image
17 // llvm-bc and llvm-ll outputs need to match regular suffixes
18 // (unfortunately).
19 // RUN: %clang %s -flto -save-temps -### 2> %t
20 // RUN: FileCheck -check-prefix=CHECK-COMPILELINK-SUFFIXES < %t %s
22 // CHECK-COMPILELINK-SUFFIXES: "-o" "{{.*}}lto.i" "-x" "c" "{{.*}}lto.c"
23 // CHECK-COMPILELINK-SUFFIXES: "-o" "{{.*}}lto.bc" {{.*}}"{{.*}}lto.i"
24 // CHECK-COMPILELINK-SUFFIXES: "-o" "{{.*}}lto.o" {{.*}}"{{.*}}lto.bc"
25 // CHECK-COMPILELINK-SUFFIXES: "{{.*}}a.{{(out|exe)}}" {{.*}}"{{.*}}lto.o"
27 // RUN: %clang %s -flto -S -### 2> %t
28 // RUN: FileCheck -check-prefix=CHECK-COMPILE-SUFFIXES < %t %s
30 // CHECK-COMPILE-SUFFIXES: "-o" "{{.*}}lto.s" "-x" "c" "{{.*}}lto.c"
32 // RUN: not %clang %s -emit-llvm 2>&1 | FileCheck --check-prefix=LLVM-LINK %s
33 // LLVM-LINK: -emit-llvm cannot be used when linking
35 /// With ld.bfd or gold, link against LLVMgold.
36 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
37 // RUN: -fuse-ld=bfd -flto=thin -### 2>&1 | FileCheck --check-prefix=LLVMGOLD %s
38 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
39 // RUN: -fuse-ld=gold -flto=full -### 2>&1 | FileCheck --check-prefix=LLVMGOLD %s
40 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
41 // RUN: -fuse-ld=gold -fno-lto -flto -### 2>&1 | FileCheck --check-prefix=LLVMGOLD %s
42 // LLVMGOLD: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
44 /// lld does not need LLVMgold.
45 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
46 // RUN: -fuse-ld=lld -flto -### 2>&1 | FileCheck --check-prefix=NO-LLVMGOLD %s
47 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
48 // RUN: -fuse-ld=gold -flto -fno-lto -### 2>&1 | FileCheck --check-prefix=NO-LLVMGOLD %s
49 // NO-LLVMGOLD-NOT: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
51 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
52 // RUN: -fuse-ld=lld -flto -O -### 2>&1 | FileCheck --check-prefix=O1 %s
53 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
54 // RUN: -fuse-ld=lld -flto -O1 -### 2>&1 | FileCheck --check-prefix=O1 %s
55 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
56 // RUN: -fuse-ld=lld -flto -Og -### 2>&1 | FileCheck --check-prefix=O1 %s
57 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
58 // RUN: -fuse-ld=lld -flto -O2 -### 2>&1 | FileCheck --check-prefix=O2 %s
59 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
60 // RUN: -fuse-ld=lld -flto -Os -### 2>&1 | FileCheck --check-prefix=O2 %s
61 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
62 // RUN: -fuse-ld=lld -flto -Oz -### 2>&1 | FileCheck --check-prefix=O2 %s
63 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
64 // RUN: -fuse-ld=lld -flto -O3 -### 2>&1 | FileCheck --check-prefix=O3 %s
65 // RUN: %clang -target x86_64-unknown-linux-gnu --sysroot %S/Inputs/basic_cross_linux_tree %s \
66 // RUN: -fuse-ld=lld -flto -Ofast -### 2>&1 | FileCheck --check-prefix=O3 %s
68 // O1: -plugin-opt=O1
69 // O2: -plugin-opt=O2
70 // O3: -plugin-opt=O3
72 // -flto passes along an explicit debugger tuning argument.
73 // RUN: %clang -target x86_64-unknown-linux -### %s -flto -glldb 2> %t
74 // RUN: FileCheck -check-prefix=CHECK-TUNING-LLDB < %t %s
75 // RUN: %clang -target x86_64-unknown-linux -### %s -flto -g 2> %t
76 // RUN: FileCheck -check-prefix=CHECK-NO-TUNING < %t %s
78 // CHECK-TUNING-LLDB: "-plugin-opt=-debugger-tune=lldb"
79 // CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune
81 // -flto=auto and -flto=jobserver pass along -flto=full
82 // RUN: %clang -target x86_64-unknown-linux -### %s -flto=auto 2>&1 | FileCheck --check-prefix=FLTO-AUTO %s
83 // RUN: %clang -target x86_64-unknown-linux -### %s -flto=jobserver 2>&1 | FileCheck --check-prefix=FLTO-JOBSERVER %s
85 // FLTO-AUTO: -flto=full
86 // FLTO-JOBSERVER: -flto=full
89 // Pass the last -flto argument.
90 // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -flto 2>&1 | \
91 // RUN: FileCheck --check-prefix=FLTO-FULL %s
92 // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -flto=full \
93 // RUN: 2>&1 | FileCheck --check-prefix=FLTO-FULL %s
94 // RUN: %clang -target x86_64-unknown-linux -### %s -flto=full -flto=thin \
95 // RUN: 2>&1 | FileCheck --check-prefix=FLTO-THIN %s
96 // RUN: %clang -target x86_64-unknown-linux -### %s -flto -flto=thin 2>&1 | \
97 // RUN: FileCheck --check-prefix=FLTO-THIN %s
99 // FLTO-FULL-NOT: -flto=thin
100 // FLTO-FULL: -flto=full
101 // FLTO-FULL-NOT: -flto=thin
103 // FLTO-THIN-NOT: -flto=full
104 // FLTO-THIN-NOT: "-flto"
105 // FLTO-THIN: -flto=thin
106 // FLTO-THIN-NOT: "-flto"
107 // FLTO-THIN-NOT: -flto=full