1 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
3 // CHECK: @used_before_default_def = weak_odr ifunc void (), ptr @used_before_default_def.resolver
4 // CHECK: @used_after_default_def = weak_odr ifunc void (), ptr @used_after_default_def.resolver
5 // CHECK-NOT: @used_before_default_decl = weak_odr ifunc void (), ptr @used_before_default_decl.resolver
6 // CHECK-NOT: @used_after_default_decl = weak_odr ifunc void (), ptr @used_after_default_decl.resolver
7 // CHECK-NOT: @used_no_default = weak_odr ifunc void (), ptr @used_no_default.resolver
8 // CHECK-NOT: @not_used_no_default = weak_odr ifunc void (), ptr @not_used_no_default.resolver
9 // CHECK: @not_used_with_default = weak_odr ifunc void (), ptr @not_used_with_default.resolver
12 // Test that an ifunc is generated and used when the default
13 // version is defined after the first use of the function.
15 __attribute__((target_version("aes"))) void used_before_default_def(void) {}
16 // CHECK-LABEL: define dso_local void @used_before_default_def._Maes(
18 void call_before_def(void) { used_before_default_def(); }
19 // CHECK-LABEL: define dso_local void @call_before_def(
20 // CHECK: call void @used_before_default_def()
22 __attribute__((target_version("default"))) void used_before_default_def(void) {}
23 // CHECK-LABEL: define dso_local void @used_before_default_def.default(
25 // CHECK-NOT: declare void @used_before_default_def(
28 // Test that an ifunc is generated and used when the default
29 // version is defined before the first use of the function.
31 __attribute__((target_version("aes"))) void used_after_default_def(void) {}
32 // CHECK-LABEL: define dso_local void @used_after_default_def._Maes(
34 __attribute__((target_version("default"))) void used_after_default_def(void) {}
35 // CHECK-LABEL: define dso_local void @used_after_default_def.default(
37 void call_after_def(void) { used_after_default_def(); }
38 // CHECK-LABEL: define dso_local void @call_after_def(
39 // CHECK: call void @used_after_default_def()
41 // CHECK-NOT: declare void @used_after_default_def(
44 // Test that an unmagled declaration is generated and used when the
45 // default version is declared after the first use of the function.
47 __attribute__((target_version("aes"))) void used_before_default_decl(void) {}
48 // CHECK-LABEL: define dso_local void @used_before_default_decl._Maes(
50 void call_before_decl(void) { used_before_default_decl(); }
51 // CHECK-LABEL: define dso_local void @call_before_decl(
52 // CHECK: call void @used_before_default_decl()
54 __attribute__((target_version("default"))) void used_before_default_decl(void);
55 // CHECK: declare void @used_before_default_decl()
58 // Test that an unmagled declaration is generated and used when the
59 // default version is declared before the first use of the function.
61 __attribute__((target_version("aes"))) void used_after_default_decl(void) {}
62 // CHECK-LABEL: define dso_local void @used_after_default_decl._Maes(
64 __attribute__((target_version("default"))) void used_after_default_decl(void);
65 // CHECK: declare void @used_after_default_decl()
67 void call_after_decl(void) { used_after_default_decl(); }
68 // CHECK-LABEL: define dso_local void @call_after_decl(
69 // CHECK: call void @used_after_default_decl()
72 // Test that an unmagled declaration is generated and used when
73 // the default version is not present.
75 __attribute__((target_version("aes"))) void used_no_default(void) {}
76 // CHECK-LABEL: define dso_local void @used_no_default._Maes(
78 void call_no_default(void) { used_no_default(); }
79 // CHECK-LABEL: define dso_local void @call_no_default(
80 // CHECK: call void @used_no_default()
82 // CHECK: declare void @used_no_default()
85 // Test that neither an ifunc nor a declaration is generated if the default
86 // definition is missing since the versioned function is not used.
88 __attribute__((target_version("aes"))) void not_used_no_default(void) {}
89 // CHECK-LABEL: define dso_local void @not_used_no_default._Maes(
91 // CHECK-NOT: declare void @not_used_no_default(
94 // Test that an ifunc is generated if the default version is defined but not used.
96 __attribute__((target_version("aes"))) void not_used_with_default(void) {}
97 // CHECK-LABEL: define dso_local void @not_used_with_default._Maes(
99 __attribute__((target_version("default"))) void not_used_with_default(void) {}
100 // CHECK-LABEL: define dso_local void @not_used_with_default.default(
102 // CHECK-NOT: declare void @not_used_with_default(
105 // CHECK: define weak_odr ptr @used_before_default_def.resolver()
106 // CHECK: define weak_odr ptr @used_after_default_def.resolver()
107 // CHECK-NOT: define weak_odr ptr @used_before_default_decl.resolver(
108 // CHECK-NOT: define weak_odr ptr @used_after_default_decl.resolver(
109 // CHECK-NOT: define weak_odr ptr @used_no_default.resolver(
110 // CHECK-NOT: define weak_odr ptr @not_used_no_default.resolver(
111 // CHECK: define weak_odr ptr @not_used_with_default.resolver()