1 // RUN: %clang_cc1 -triple x86_64-gnu-linux -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
2 // RUN: %clang_cc1 -triple aarch64-gnu-linux -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
3 // RUN: %clang_cc1 -triple x86_64-gnu-linux -x c++ -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
4 // RUN: %clang_cc1 -triple aarch64-gnu-linux -x c++ -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
6 // no-sanitize-memory-param-retval does NOT conflict with enable-noundef-analysis
7 // RUN: %clang_cc1 -triple x86_64-gnu-linux -x c++ -emit-llvm -fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
9 //************ Passing structs by value
10 // TODO: No structs may currently be marked noundef
12 namespace check_structs
{
16 Trivial
ret_trivial() { return {}; }
17 void pass_trivial(Trivial e
) {}
18 // CHECK-INTEL: [[DEF:define( dso_local)?]] i32 @{{.*}}ret_trivial
19 // CHECK-AARCH: [[DEF:define( dso_local)?]] i32 @{{.*}}ret_trivial
20 // CHECK-INTEL: [[DEF]] void @{{.*}}pass_trivial{{.*}}(i32 %
21 // CHECK-AARCH: [[DEF]] void @{{.*}}pass_trivial{{.*}}(i64 %
25 NoCopy(NoCopy
&) = delete;
27 NoCopy
ret_nocopy() { return {}; }
28 void pass_nocopy(NoCopy e
) {}
29 // CHECK: [[DEF]] void @{{.*}}ret_nocopy{{.*}}(ptr dead_on_unwind noalias writable sret({{[^)]+}}) align 4 %
30 // CHECK: [[DEF]] void @{{.*}}pass_nocopy{{.*}}(ptr noundef %
35 Huge
ret_huge() { return {}; }
36 void pass_huge(Huge h
) {}
37 // CHECK: [[DEF]] void @{{.*}}ret_huge{{.*}}(ptr dead_on_unwind noalias writable sret({{[^)]+}}) align 4 %
38 // CHECK: [[DEF]] void @{{.*}}pass_huge{{.*}}(ptr noundef
39 } // namespace check_structs
41 //************ Passing unions by value
42 // No unions may be marked noundef
44 namespace check_unions
{
48 Trivial
ret_trivial() { return {}; }
49 void pass_trivial(Trivial e
) {}
50 // CHECK-INTEL: [[DEF]] i32 @{{.*}}ret_trivial
51 // CHECK-AARCH: [[DEF]] i32 @{{.*}}ret_trivial
52 // CHECK-INTEL: [[DEF]] void @{{.*}}pass_trivial{{.*}}(i32 %
53 // CHECK-AARCH: [[DEF]] void @{{.*}}pass_trivial{{.*}}(i64 %
57 NoCopy(NoCopy
&) = delete;
59 NoCopy
ret_nocopy() { return {}; }
60 void pass_nocopy(NoCopy e
) {}
61 // CHECK: [[DEF]] void @{{.*}}ret_nocopy{{.*}}(ptr dead_on_unwind noalias writable sret({{[^)]+}}) align 4 %
62 // CHECK: [[DEF]] void @{{.*}}pass_nocopy{{.*}}(ptr noundef %
63 } // namespace check_unions
65 //************ Passing `this` pointers
66 // `this` pointer must always be defined
68 namespace check_this
{
88 // CHECK: define linkonce_odr void @{{.*}}Object{{.*}}(ptr noundef nonnull align 4 dereferenceable(1) %
89 // CHECK: define linkonce_odr noundef i32 @{{.*}}Object{{.*}}getData{{.*}}(ptr noundef nonnull align 4 dereferenceable(1) %
90 // CHECK: define linkonce_odr noundef ptr @{{.*}}Object{{.*}}getThis{{.*}}(ptr noundef nonnull align 4 dereferenceable(1) %
91 } // namespace check_this
93 //************ Passing vector types
95 namespace check_vecs
{
96 typedef int __attribute__((vector_size(12))) i32x3
;
100 void pass_vec(i32x3 v
) {
103 // CHECK: [[DEF]] noundef <3 x i32> @{{.*}}ret_vec{{.*}}()
104 // CHECK-INTEL: [[DEF]] void @{{.*}}pass_vec{{.*}}(<3 x i32> noundef %
105 // CHECK-AARCH: [[DEF]] void @{{.*}}pass_vec{{.*}}(<4 x i32> %
106 } // namespace check_vecs
108 //************ Passing exotic types
109 // Function/Array pointers, Function member / Data member pointers, nullptr_t, ExtInt types
111 namespace check_exotic
{
116 typedef int Object::*mdptr
;
117 typedef int (Object::*mfptr
)();
118 typedef decltype(nullptr) nullptr_t
;
119 typedef int (*arrptr
)[32];
120 typedef int (*fnptr
)(int);
122 arrptr
ret_arrptr() {
134 nullptr_t
ret_npt() {
137 void pass_npt(nullptr_t t
) {
139 _BitInt(3) ret_BitInt() {
142 void pass_BitInt(_BitInt(3) e
) {
144 void pass_large_BitInt(_BitInt(127) e
) {
147 // Pointers to arrays/functions are always noundef
148 // CHECK: [[DEF]] noundef ptr @{{.*}}ret_arrptr{{.*}}()
149 // CHECK: [[DEF]] noundef ptr @{{.*}}ret_fnptr{{.*}}()
151 // Pointers to members are never noundef
152 // CHECK: [[DEF]] i64 @{{.*}}ret_mdptr{{.*}}()
153 // CHECK-INTEL: [[DEF]] { i64, i64 } @{{.*}}ret_mfptr{{.*}}()
154 // CHECK-AARCH: [[DEF]] [2 x i64] @{{.*}}ret_mfptr{{.*}}()
156 // nullptr_t is never noundef
157 // CHECK: [[DEF]] ptr @{{.*}}ret_npt{{.*}}()
158 // CHECK: [[DEF]] void @{{.*}}pass_npt{{.*}}(ptr %
160 // CHECK-INTEL: [[DEF]] noundef signext i3 @{{.*}}ret_BitInt{{.*}}()
161 // CHECK-AARCH: [[DEF]] noundef i3 @{{.*}}ret_BitInt{{.*}}()
162 // CHECK-INTEL: [[DEF]] void @{{.*}}pass_BitInt{{.*}}(i3 noundef signext %
163 // CHECK-AARCH: [[DEF]] void @{{.*}}pass_BitInt{{.*}}(i3 noundef %
164 // CHECK-INTEL: [[DEF]] void @{{.*}}pass_large_BitInt{{.*}}(i64 noundef %{{.*}}, i64 noundef %
165 // CHECK-AARCH: [[DEF]] void @{{.*}}pass_large_BitInt{{.*}}(i127 noundef %
166 } // namespace check_exotic