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