2022-04-07 18:03:55 +08:00
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-gnu-linux -x c++ -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
|
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -triple aarch64-gnu-linux -x c++ -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
|
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
|
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -triple aarch64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
|
2022-01-14 18:12:57 +08:00
|
|
|
|
|
|
|
// no-sanitize-memory-param-retval does NOT conflict with enable-noundef-analysis
|
2022-04-07 18:03:55 +08:00
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
|
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
|
2021-02-11 10:34:01 +08:00
|
|
|
|
|
|
|
//************ Passing structs by value
|
|
|
|
// TODO: No structs may currently be marked noundef
|
|
|
|
|
|
|
|
namespace check_structs {
|
|
|
|
struct Trivial {
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
Trivial ret_trivial() { return {}; }
|
|
|
|
void pass_trivial(Trivial e) {}
|
|
|
|
// CHECK-INTEL: [[DEFINE:define( dso_local)?]] i32 @{{.*}}ret_trivial
|
2021-04-13 21:28:32 +08:00
|
|
|
// CHECK-AARCH: [[DEFINE:define( dso_local)?]] i32 @{{.*}}ret_trivial
|
2021-02-11 10:34:01 +08:00
|
|
|
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i32 %
|
|
|
|
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i64 %
|
|
|
|
|
|
|
|
struct NoCopy {
|
|
|
|
int a;
|
|
|
|
NoCopy(NoCopy &) = delete;
|
|
|
|
};
|
|
|
|
NoCopy ret_nocopy() { return {}; }
|
|
|
|
void pass_nocopy(NoCopy e) {}
|
|
|
|
// CHECK: [[DEFINE]] void @{{.*}}ret_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noalias sret({{[^)]+}}) align 4 %
|
|
|
|
// CHECK: [[DEFINE]] void @{{.*}}pass_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noundef %
|
|
|
|
|
|
|
|
struct Huge {
|
|
|
|
int a[1024];
|
|
|
|
};
|
|
|
|
Huge ret_huge() { return {}; }
|
|
|
|
void pass_huge(Huge h) {}
|
|
|
|
// CHECK: [[DEFINE]] void @{{.*}}ret_huge{{.*}}(%"struct.check_structs::Huge"* noalias sret({{[^)]+}}) align 4 %
|
|
|
|
// CHECK: [[DEFINE]] void @{{.*}}pass_huge{{.*}}(%"struct.check_structs::Huge"* noundef
|
|
|
|
} // namespace check_structs
|
|
|
|
|
|
|
|
//************ Passing unions by value
|
|
|
|
// No unions may be marked noundef
|
|
|
|
|
|
|
|
namespace check_unions {
|
|
|
|
union Trivial {
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
Trivial ret_trivial() { return {}; }
|
|
|
|
void pass_trivial(Trivial e) {}
|
|
|
|
// CHECK-INTEL: [[DEFINE]] i32 @{{.*}}ret_trivial
|
2021-04-13 21:28:32 +08:00
|
|
|
// CHECK-AARCH: [[DEFINE]] i32 @{{.*}}ret_trivial
|
2021-02-11 10:34:01 +08:00
|
|
|
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i32 %
|
|
|
|
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i64 %
|
|
|
|
|
|
|
|
union NoCopy {
|
|
|
|
int a;
|
|
|
|
NoCopy(NoCopy &) = delete;
|
|
|
|
};
|
|
|
|
NoCopy ret_nocopy() { return {}; }
|
|
|
|
void pass_nocopy(NoCopy e) {}
|
|
|
|
// CHECK: [[DEFINE]] void @{{.*}}ret_nocopy{{.*}}(%"union.check_unions::NoCopy"* noalias sret({{[^)]+}}) align 4 %
|
|
|
|
// CHECK: [[DEFINE]] void @{{.*}}pass_nocopy{{.*}}(%"union.check_unions::NoCopy"* noundef %
|
|
|
|
} // namespace check_unions
|
|
|
|
|
|
|
|
//************ Passing `this` pointers
|
|
|
|
// `this` pointer must always be defined
|
|
|
|
|
|
|
|
namespace check_this {
|
|
|
|
struct Object {
|
|
|
|
int data[];
|
|
|
|
|
|
|
|
Object() {
|
|
|
|
this->data[0] = 0;
|
|
|
|
}
|
|
|
|
int getData() {
|
|
|
|
return this->data[0];
|
|
|
|
}
|
|
|
|
Object *getThis() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void use_object() {
|
|
|
|
Object obj;
|
|
|
|
obj.getData();
|
|
|
|
obj.getThis();
|
|
|
|
}
|
2022-01-20 21:45:19 +08:00
|
|
|
// CHECK: define linkonce_odr void @{{.*}}Object{{.*}}(%"struct.check_this::Object"* noundef nonnull align 4 dereferenceable(1) %
|
|
|
|
// CHECK: define linkonce_odr noundef i32 @{{.*}}Object{{.*}}getData{{.*}}(%"struct.check_this::Object"* noundef nonnull align 4 dereferenceable(1) %
|
|
|
|
// CHECK: define linkonce_odr noundef %"struct.check_this::Object"* @{{.*}}Object{{.*}}getThis{{.*}}(%"struct.check_this::Object"* noundef nonnull align 4 dereferenceable(1) %
|
2021-02-11 10:34:01 +08:00
|
|
|
} // namespace check_this
|
|
|
|
|
|
|
|
//************ Passing vector types
|
|
|
|
|
|
|
|
namespace check_vecs {
|
|
|
|
typedef int __attribute__((vector_size(12))) i32x3;
|
|
|
|
i32x3 ret_vec() {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
void pass_vec(i32x3 v) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: [[DEFINE]] noundef <3 x i32> @{{.*}}ret_vec{{.*}}()
|
|
|
|
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_vec{{.*}}(<3 x i32> noundef %
|
|
|
|
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_vec{{.*}}(<4 x i32> %
|
|
|
|
} // namespace check_vecs
|
|
|
|
|
|
|
|
//************ Passing exotic types
|
|
|
|
// Function/Array pointers, Function member / Data member pointers, nullptr_t, ExtInt types
|
|
|
|
|
|
|
|
namespace check_exotic {
|
|
|
|
struct Object {
|
|
|
|
int mfunc();
|
|
|
|
int mdata;
|
|
|
|
};
|
|
|
|
typedef int Object::*mdptr;
|
|
|
|
typedef int (Object::*mfptr)();
|
|
|
|
typedef decltype(nullptr) nullptr_t;
|
|
|
|
typedef int (*arrptr)[32];
|
|
|
|
typedef int (*fnptr)(int);
|
|
|
|
|
|
|
|
arrptr ret_arrptr() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
fnptr ret_fnptr() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mdptr ret_mdptr() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mfptr ret_mfptr() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nullptr_t ret_npt() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
void pass_npt(nullptr_t t) {
|
|
|
|
}
|
2021-12-07 01:46:54 +08:00
|
|
|
_BitInt(3) ret_BitInt() {
|
2021-02-11 10:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-07 01:46:54 +08:00
|
|
|
void pass_BitInt(_BitInt(3) e) {
|
2021-02-11 10:34:01 +08:00
|
|
|
}
|
2021-12-07 01:46:54 +08:00
|
|
|
void pass_large_BitInt(_BitInt(127) e) {
|
2021-02-11 10:34:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pointers to arrays/functions are always noundef
|
|
|
|
// CHECK: [[DEFINE]] noundef [32 x i32]* @{{.*}}ret_arrptr{{.*}}()
|
|
|
|
// CHECK: [[DEFINE]] noundef i32 (i32)* @{{.*}}ret_fnptr{{.*}}()
|
|
|
|
|
|
|
|
// Pointers to members are never noundef
|
|
|
|
// CHECK: [[DEFINE]] i64 @{{.*}}ret_mdptr{{.*}}()
|
|
|
|
// CHECK-INTEL: [[DEFINE]] { i64, i64 } @{{.*}}ret_mfptr{{.*}}()
|
|
|
|
// CHECK-AARCH: [[DEFINE]] [2 x i64] @{{.*}}ret_mfptr{{.*}}()
|
|
|
|
|
|
|
|
// nullptr_t is never noundef
|
|
|
|
// CHECK: [[DEFINE]] i8* @{{.*}}ret_npt{{.*}}()
|
|
|
|
// CHECK: [[DEFINE]] void @{{.*}}pass_npt{{.*}}(i8* %
|
|
|
|
|
|
|
|
// TODO: for now, ExtInt is only noundef if it is sign/zero-extended
|
2021-12-07 01:46:54 +08:00
|
|
|
// CHECK-INTEL: [[DEFINE]] noundef signext i3 @{{.*}}ret_BitInt{{.*}}()
|
|
|
|
// CHECK-AARCH: [[DEFINE]] i3 @{{.*}}ret_BitInt{{.*}}()
|
|
|
|
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_BitInt{{.*}}(i3 noundef signext %
|
|
|
|
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_BitInt{{.*}}(i3 %
|
|
|
|
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_large_BitInt{{.*}}(i64 %{{.*}}, i64 %
|
|
|
|
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_large_BitInt{{.*}}(i127 %
|
2022-01-20 21:45:19 +08:00
|
|
|
} // namespace check_exotic
|