diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGen/builtin-assume-aligned.c | 44 | ||||
-rw-r--r-- | clang/test/CodeGen/builtin-assume.c | 22 | ||||
-rw-r--r-- | clang/test/Sema/builtin-assume-aligned.c | 43 | ||||
-rw-r--r-- | clang/test/Sema/builtin-assume.c | 9 | ||||
-rw-r--r-- | clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp | 22 |
5 files changed, 137 insertions, 3 deletions
diff --git a/clang/test/CodeGen/builtin-assume-aligned.c b/clang/test/CodeGen/builtin-assume-aligned.c new file mode 100644 index 00000000000..bcae8c7f145 --- /dev/null +++ b/clang/test/CodeGen/builtin-assume-aligned.c @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: @test1 +int test1(int *a) { +// CHECK: %ptrint = ptrtoint +// CHECK: %maskedptr = and i64 %ptrint, 31 +// CHECK: %maskcond = icmp eq i64 %maskedptr, 0 +// CHECK: call void @llvm.assume(i1 %maskcond) + a = __builtin_assume_aligned(a, 32, 0ull); + return a[0]; +} + +// CHECK-LABEL: @test2 +int test2(int *a) { +// CHECK: %ptrint = ptrtoint +// CHECK: %maskedptr = and i64 %ptrint, 31 +// CHECK: %maskcond = icmp eq i64 %maskedptr, 0 +// CHECK: call void @llvm.assume(i1 %maskcond) + a = __builtin_assume_aligned(a, 32, 0); + return a[0]; +} + +// CHECK-LABEL: @test3 +int test3(int *a) { +// CHECK: %ptrint = ptrtoint +// CHECK: %maskedptr = and i64 %ptrint, 31 +// CHECK: %maskcond = icmp eq i64 %maskedptr, 0 +// CHECK: call void @llvm.assume(i1 %maskcond) + a = __builtin_assume_aligned(a, 32); + return a[0]; +} + +// CHECK-LABEL: @test4 +int test4(int *a, int b) { +// CHECK-DAG: %ptrint = ptrtoint +// CHECK-DAG: %conv = sext i32 +// CHECK: %offsetptr = sub i64 %ptrint, %conv +// CHECK: %maskedptr = and i64 %offsetptr, 31 +// CHECK: %maskcond = icmp eq i64 %maskedptr, 0 +// CHECK: call void @llvm.assume(i1 %maskcond) + a = __builtin_assume_aligned(a, 32, b); + return a[0]; +} + diff --git a/clang/test/CodeGen/builtin-assume.c b/clang/test/CodeGen/builtin-assume.c index a381a4c1dfb..041e9f48d0b 100644 --- a/clang/test/CodeGen/builtin-assume.c +++ b/clang/test/CodeGen/builtin-assume.c @@ -1,8 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s // RUN: %clang_cc1 -triple i386-mingw32 -fms-extensions -emit-llvm -o - %s | FileCheck %s // CHECK-LABEL: @test1 -int test1(int *a) { - __assume(a != 0); +int test1(int *a, int i) { +// CHECK: %0 = load i32** %a.addr +// CHECK: %cmp = icmp ne i32* %0, null +// CHECK: call void @llvm.assume(i1 %cmp) +#ifdef _MSC_VER + __assume(a != 0) +#else + __builtin_assume(a != 0); +#endif + +// Nothing is generated for an assume with side effects... +// CHECK-NOT: load i32** %i.addr +// CHECK-NOT: call void @llvm.assume +#ifdef _MSC_VER + __assume(++i != 0) +#else + __builtin_assume(++i != 0); +#endif + return a[0]; } diff --git a/clang/test/Sema/builtin-assume-aligned.c b/clang/test/Sema/builtin-assume-aligned.c new file mode 100644 index 00000000000..884a7fb6895 --- /dev/null +++ b/clang/test/Sema/builtin-assume-aligned.c @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +int test1(int *a) { + a = __builtin_assume_aligned(a, 32, 0ull); + return a[0]; +} + +int test2(int *a) { + a = __builtin_assume_aligned(a, 32, 0); + return a[0]; +} + +int test3(int *a) { + a = __builtin_assume_aligned(a, 32); + return a[0]; +} + +int test4(int *a) { + a = __builtin_assume_aligned(a, -32); // expected-error {{requested alignment is not a power of 2}} + a = __builtin_assume_aligned(a, 1ULL << 63); + return a[0]; +} + +int test5(int *a, unsigned *b) { + a = __builtin_assume_aligned(a, 32, b); // expected-warning {{incompatible pointer to integer conversion passing 'unsigned int *' to parameter of type}} + return a[0]; +} + +int test6(int *a) { + a = __builtin_assume_aligned(a, 32, 0, 0); // expected-error {{too many arguments to function call, expected at most 3, have 4}} + return a[0]; +} + +int test7(int *a) { + a = __builtin_assume_aligned(a, 31); // expected-error {{requested alignment is not a power of 2}} + return a[0]; +} + +int test8(int *a, int j) { + a = __builtin_assume_aligned(a, j); // expected-error {{must be a constant integer}} + return a[0]; +} + diff --git a/clang/test/Sema/builtin-assume.c b/clang/test/Sema/builtin-assume.c index 1f6a3a0cd91..512eeeccdc4 100644 --- a/clang/test/Sema/builtin-assume.c +++ b/clang/test/Sema/builtin-assume.c @@ -1,11 +1,18 @@ // RUN: %clang_cc1 -triple i386-mingw32 -fms-extensions -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s int foo(int *a, int i) { +#ifdef _MSC_VER __assume(i != 4); - __assume(++i > 2); //expected-warning {{the argument to __assume has side effects that will be discarded}} + __assume(++i > 2); //expected-warning {{the argument to '__assume' has side effects that will be discarded}} int test = sizeof(struct{char qq[(__assume(i != 5), 7)];}); +#else + __builtin_assume(i != 4); + __builtin_assume(++i > 2); //expected-warning {{the argument to '__builtin_assume' has side effects that will be discarded}} + int test = sizeof(struct{char qq[(__builtin_assume(i != 5), 7)];}); +#endif return a[i]; } diff --git a/clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp b/clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp new file mode 100644 index 00000000000..a1d78ae5dd3 --- /dev/null +++ b/clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template<int z> +int test9(int *a) { + a = (int *) __builtin_assume_aligned(a, z + 1); // expected-error {{requested alignment is not a power of 2}} + return a[0]; +} + +void test9i(int *a) { + test9<42>(a); // expected-note {{in instantiation of function template specialization 'test9<42>' requested here}} +} + +template<typename T> +int test10(int *a, T z) { + a = (int *) __builtin_assume_aligned(a, z + 1); // expected-error {{must be a constant integer}} + return a[0]; +} + +int test10i(int *a) { + return test10(a, 42); // expected-note {{in instantiation of function template specialization 'test10<int>' requested here}} +} + |