| 1 | // RUN: %clang_cc1 -triple x86_64-pc-win32 -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=COFF %s |
| 2 | // COFF-DAG: @bar = external dso_local global i32 |
| 3 | // COFF-DAG: @weak_bar = extern_weak dso_local global i32 |
| 4 | // COFF-DAG: declare dso_local void @foo() |
| 5 | // COFF-DAG: @baz = dso_local global i32 42 |
| 6 | // COFF-DAG: define dso_local i32* @zed() |
| 7 | // COFF-DAG: @thread_var = external dso_local thread_local global i32 |
| 8 | // COFF-DAG: @local_thread_var = dso_local thread_local global i32 42 |
| 9 | // COFF-DAG: @import_var = external dllimport global i32 |
| 10 | // COFF-DAG: declare dllimport void @import_func() |
| 11 | |
| 12 | // RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=MINGW %s |
| 13 | // MINGW-DAG: @bar = external global i32 |
| 14 | // MINGW-DAG: @weak_bar = extern_weak global i32 |
| 15 | // MINGW-DAG: declare dso_local void @foo() |
| 16 | // MINGW-DAG: @baz = dso_local global i32 42 |
| 17 | // MINGW-DAG: define dso_local i32* @zed() |
| 18 | // MINGW-DAG: @thread_var = external dso_local thread_local global i32 |
| 19 | // MINGW-DAG: @local_thread_var = dso_local thread_local global i32 42 |
| 20 | // MINGW-DAG: @import_var = external dllimport global i32 |
| 21 | // MINGW-DAG: declare dllimport void @import_func() |
| 22 | |
| 23 | // RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm -mrelocation-model static %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=STATIC %s |
| 24 | // STATIC-DAG: @bar = external dso_local global i32 |
| 25 | // STATIC-DAG: @weak_bar = extern_weak dso_local global i32 |
| 26 | // STATIC-DAG: declare dso_local void @foo() |
| 27 | // STATIC-DAG: @baz = dso_local global i32 42 |
| 28 | // STATIC-DAG: define dso_local i32* @zed() |
| 29 | // STATIC-DAG: @thread_var = external thread_local global i32 |
| 30 | // STATIC-DAG: @local_thread_var = dso_local thread_local global i32 42 |
| 31 | // STATIC-DAG: @import_var = external dso_local global i32 |
| 32 | // STATIC-DAG: declare dso_local void @import_func() |
| 33 | |
| 34 | // RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm -pic-is-pie -mpie-copy-relocations %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=PIE-COPY %s |
| 35 | // PIE-COPY-DAG: @bar = external dso_local global i32 |
| 36 | // PIE-COPY-DAG: @weak_bar = extern_weak global i32 |
| 37 | // PIE-COPY-DAG: declare void @foo() |
| 38 | // PIE-COPY-DAG: @baz = dso_local global i32 42 |
| 39 | // PIE-COPY-DAG: define dso_local i32* @zed() |
| 40 | // PIE-COPY-DAG: @thread_var = external thread_local global i32 |
| 41 | // PIE-COPY-DAG: @local_thread_var = dso_local thread_local global i32 42 |
| 42 | // PIE-COPY-DAG: @import_var = external dso_local global i32 |
| 43 | // PIE-COPY-DAG: declare void @import_func() |
| 44 | |
| 45 | // RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm -pic-is-pie %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=PIE %s |
| 46 | // PIE-DAG: @bar = external global i32 |
| 47 | // PIE-DAG: @weak_bar = extern_weak global i32 |
| 48 | // PIE-DAG: declare void @foo() |
| 49 | // PIE-DAG: @baz = dso_local global i32 42 |
| 50 | // PIE-DAG: define dso_local i32* @zed() |
| 51 | // PIE-DAG: @thread_var = external thread_local global i32 |
| 52 | // PIE-DAG: @local_thread_var = dso_local thread_local global i32 42 |
| 53 | // PIE-DAG: @import_var = external global i32 |
| 54 | // PIE-DAG: declare void @import_func() |
| 55 | |
| 56 | // RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm -mrelocation-model static -fno-plt %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=NOPLT %s |
| 57 | // NOPLT-DAG: @bar = external dso_local global i32 |
| 58 | // NOPLT-DAG: @weak_bar = extern_weak dso_local global i32 |
| 59 | // NOPLT-DAG: declare void @foo() |
| 60 | // NOPLT-DAG: @baz = dso_local global i32 42 |
| 61 | // NOPLT-DAG: define dso_local i32* @zed() |
| 62 | // NOPLT-DAG: @thread_var = external thread_local global i32 |
| 63 | // NOPLT-DAG: @local_thread_var = dso_local thread_local global i32 42 |
| 64 | // NOPLT-DAG: @import_var = external dso_local global i32 |
| 65 | // NOPLT-DAG: declare void @import_func() |
| 66 | |
| 67 | // RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm -fno-plt -pic-is-pie -mpie-copy-relocations %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=PIE-COPY-NOPLT %s |
| 68 | // PIE-COPY-NOPLT-DAG: @bar = external dso_local global i32 |
| 69 | // PIE-COPY-NOPLT-DAG: @weak_bar = extern_weak global i32 |
| 70 | // PIE-COPY-NOPLT-DAG: declare void @foo() |
| 71 | // PIE-COPY-NOPLT-DAG: @baz = dso_local global i32 42 |
| 72 | // PIE-COPY-NOPLT-DAG: define dso_local i32* @zed() |
| 73 | // PIE-COPY-NOPLT-DAG: @thread_var = external thread_local global i32 |
| 74 | // PIE-COPY-NOPLT-DAG: @local_thread_var = dso_local thread_local global i32 42 |
| 75 | // PIE-COPY-NOPLT-DAG: @import_var = external dso_local global i32 |
| 76 | // PIE-COPY-NOPLT-DAG: declare void @import_func() |
| 77 | |
| 78 | // RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm -pic-is-pie -fno-plt %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=PIE-NO-PLT %s |
| 79 | // RUN: %clang_cc1 -triple powerpc64le-pc-linux -emit-llvm -mrelocation-model static %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=PIE-NO-PLT %s |
| 80 | // PIE-NO-PLT-DAG: @bar = external global i32 |
| 81 | // PIE-NO-PLT-DAG: @weak_bar = extern_weak global i32 |
| 82 | // PIE-NO-PLT-DAG: declare void @foo() |
| 83 | // PIE-NO-PLT-DAG: @baz = dso_local global i32 42 |
| 84 | // PIE-NO-PLT-DAG: define dso_local i32* @zed() |
| 85 | // PIE-NO-PLT-DAG: @thread_var = external thread_local global i32 |
| 86 | // PIE-NO-PLT-DAG: @local_thread_var = dso_local thread_local global i32 42 |
| 87 | // PIE-NO-PLT-DAG: @import_var = external global i32 |
| 88 | // PIE-NO-PLT-DAG: declare void @import_func() |
| 89 | |
| 90 | // RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix=SHARED %s |
| 91 | // SHARED-DAG: @bar = external global i32 |
| 92 | // SHARED-DAG: @weak_bar = extern_weak global i32 |
| 93 | // SHARED-DAG: declare void @foo() |
| 94 | // SHARED-DAG: @baz = global i32 42 |
| 95 | // SHARED-DAG: define i32* @zed() |
| 96 | // SHARED-DAG: @thread_var = external thread_local global i32 |
| 97 | // SHARED-DAG: @local_thread_var = thread_local global i32 42 |
| 98 | // PIE-NO-PLT-DAG: @import_var = external global i32 |
| 99 | // PIE-NO-PLT-DAG: declare void @import_func() |
| 100 | |
| 101 | __attribute__((dllimport)) extern int import_var; |
| 102 | __attribute__((dllimport)) void import_func(void); |
| 103 | |
| 104 | int *use_import() { |
| 105 | import_func(); |
| 106 | return &import_var; |
| 107 | } |
| 108 | |
| 109 | extern int bar; |
| 110 | __attribute__((weak)) extern int weak_bar; |
| 111 | void foo(void); |
| 112 | |
| 113 | int baz = 42; |
| 114 | int *zed() { |
| 115 | foo(); |
| 116 | return baz ? &weak_bar : &bar; |
| 117 | } |
| 118 | |
| 119 | extern __thread int thread_var; |
| 120 | __thread int local_thread_var = 42; |
| 121 | int *get_thread_var(int a) { |
| 122 | return a ? &thread_var : &local_thread_var; |
| 123 | } |
| 124 | |