|
| 1 | +// RUN: %clang_cc1 -triple aarch64-pc-windows-msvc -emit-llvm -o - %s | FileCheck %s |
| 2 | +// RUN: %clang_cc1 -triple aarch64-pc-windows-msvc -O2 -emit-llvm -o - %s | FileCheck %s |
| 3 | +// RUN: %clang_cc1 -triple aarch64-pc-windows-msvc -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN |
| 4 | +// RUN: %clang_cc1 -triple aarch64-pc-windows-msvc -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN |
| 5 | + |
| 6 | +int foo(int) __attribute__ ((ifunc("foo_ifunc"))); |
| 7 | + |
| 8 | +static int f1(int i) { |
| 9 | + return i + 1; |
| 10 | +} |
| 11 | + |
| 12 | +static int f2(int i) { |
| 13 | + return i + 2; |
| 14 | +} |
| 15 | + |
| 16 | +typedef int (*foo_t)(int); |
| 17 | + |
| 18 | +volatile int global; |
| 19 | + |
| 20 | +static foo_t foo_ifunc(void) { |
| 21 | + return global ? f1 : f2; |
| 22 | +} |
| 23 | + |
| 24 | +int bar(void) { |
| 25 | + return foo(1); |
| 26 | +} |
| 27 | + |
| 28 | +extern void goo(void); |
| 29 | + |
| 30 | +void bar2(void) { |
| 31 | + goo(); |
| 32 | +} |
| 33 | + |
| 34 | +extern void goo(void) __attribute__ ((ifunc("goo_ifunc"))); |
| 35 | + |
| 36 | +void* goo_ifunc(void) { |
| 37 | + return 0; |
| 38 | +} |
| 39 | + |
| 40 | +/// The ifunc is emitted after its resolver. |
| 41 | +void *hoo_ifunc(void) { return 0; } |
| 42 | +extern void hoo(int) __attribute__ ((ifunc("hoo_ifunc"))); |
| 43 | + |
| 44 | +/// ifunc on Windows is lowered to global pointers and an indirect call. |
| 45 | +// CHECK: @global = dso_local global i32 0, align 4 |
| 46 | +// CHECK: {{.*}} = internal{{.*}}global{{.*}}poison, align 8 |
| 47 | +/// Register the constructor for initialisation. |
| 48 | +// CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 10, ptr @{{.*}}, ptr null }] |
| 49 | + |
| 50 | +// CHECK-LABEL: @bar() |
| 51 | +// CHECK %0 = load ptr, ptr @0, align 8 |
| 52 | +// CHECK %call = call i32 %0(i32 noundef 1) |
| 53 | + |
| 54 | +// CHECK-LABEL: @bar2() |
| 55 | +// CHECK %0 = load ptr, ptr getelementptr inbounds ([3 x ptr], ptr @0, i32 0, i32 1), align 8 |
| 56 | +// CHECK call void %0() |
| 57 | + |
| 58 | +// CHECK: define internal void @{{.*}}() |
| 59 | + |
| 60 | +// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @goo_ifunc() {{(local_unnamed_addr )?}} |
| 61 | + |
| 62 | +// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() {{(local_unnamed_addr )?}} |
| 63 | + |
| 64 | +// SAN: define internal {{(fastcc )?}}{{(noundef )?}}nonnull ptr @foo_ifunc() {{(unnamed_addr )?}} |
| 65 | + |
0 commit comments