[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Driver / nvlink-wrapper.c
blob79f4a6641732f79eb21f5f3d3eea403a5f9bf8c1
1 // REQUIRES: x86-registered-target
2 // REQUIRES: nvptx-registered-target
4 #if defined(X)
5 extern int y;
6 int foo() { return y; }
8 int x = 0;
9 #elif defined(Y)
10 int y = 42;
11 #elif defined(Z)
12 int z = 42;
13 #elif defined(W)
14 int w = 42;
15 #elif defined(U)
16 extern int x;
17 extern int __attribute__((weak)) w;
19 int bar() {
20 return x + w;
22 #else
23 extern int y;
24 extern int x;
25 int baz() { return y + x; }
26 #endif
28 // Create various inputs to test basic linking and LTO capabilities. Creating a
29 // CUDA binary requires access to the `ptxas` executable, so we just use x64.
30 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -o %t.o
31 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DX -o %t-x.o
32 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DY -o %t-y.o
33 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DZ -o %t-z.o
34 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DW -o %t-w.o
35 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DU -o %t-u.o
36 // RUN: llvm-ar rcs %t-x.a %t-x.o
37 // RUN: llvm-ar rcs %t-y.a %t-y.o
38 // RUN: llvm-ar rcs %t-z.a %t-z.o
39 // RUN: llvm-ar rcs %t-w.a %t-w.o
40 // RUN: llvm-ar rcs %t-u.a %t-u.o
43 // Check that we forward any unrecognized argument to 'nvlink'.
45 // RUN: clang-nvlink-wrapper --dry-run -arch sm_52 %t-u.o -foo -o a.out 2>&1 \
46 // RUN: | FileCheck %s --check-prefix=ARGS
47 // ARGS: nvlink{{.*}} -arch sm_52 -foo -o a.out [[INPUT:.+]].cubin
50 // Check the symbol resolution for static archives. We expect to only link
51 // `libx.a` and `liby.a` because extern weak symbols do not extract and `libz.a`
52 // is not used at all.
54 // RUN: clang-nvlink-wrapper --dry-run %t-x.a %t-u.a %t-y.a %t-z.a %t-w.a %t.o \
55 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LINK
56 // LINK: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin
59 // Same as above but we use '--undefined' to forcibly extract 'libz.a'
61 // RUN: clang-nvlink-wrapper --dry-run %t-x.a %t-u.a %t-y.a %t-z.a %t-w.a %t.o \
62 // RUN: -u z -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LINK
63 // UNDEFINED: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin{{.*}}-z-{{.*}}.cubin
66 // Check that the LTO interface works and properly preserves symbols used in a
67 // regular object file.
69 // RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \
70 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LTO
71 // LTO: ptxas{{.*}} -m64 -c [[PTX:.+]].s -O3 -arch sm_52 -o [[CUBIN:.+]].cubin
72 // LTO: nvlink{{.*}} -arch sm_52 -o a.out [[CUBIN]].cubin {{.*}}-u-{{.*}}.cubin {{.*}}-y-{{.*}}.cubin
75 // Check that we don't forward some arguments.
77 // RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \
78 // RUN: -arch sm_52 --cuda-path/opt/cuda -o a.out 2>&1 | FileCheck %s --check-prefix=PATH
79 // PATH-NOT: --cuda-path=/opt/cuda
82 // Check that passes can be specified and debugged.
84 // RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \
85 // RUN: --lto-debug-pass-manager --lto-newpm-passes=forceattrs \
86 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=PASSES
87 // PASSES: Running pass: ForceFunctionAttrsPass
90 // Check that '-plugin` is ingored like in `ld.lld`
92 // RUN: clang-nvlink-wrapper --dry-run %t.o -plugin foo.so -arch sm_52 -o a.out \
93 // RUN: 2>&1 | FileCheck %s --check-prefix=PLUGIN
94 // PLUGIN-NOT: -plugin