diff options
author | Eric Christopher <echristo@gmail.com> | 2015-10-15 23:47:11 +0000 |
---|---|---|
committer | Eric Christopher <echristo@gmail.com> | 2015-10-15 23:47:11 +0000 |
commit | 15709991d09d940834029baf20a078d44f55234a (patch) | |
tree | 30185b97f8eb0a29fa9fd46df53f4f7bd34963a0 /clang/test | |
parent | a15785bb5b644d92ea27b247d01be4f87b46307c (diff) | |
download | bcm5719-llvm-15709991d09d940834029baf20a078d44f55234a.tar.gz bcm5719-llvm-15709991d09d940834029baf20a078d44f55234a.zip |
Add an error when calling a builtin that requires features that don't
match the feature set of the function that they're being called from.
This ensures that we can effectively diagnose some[1] code that would
instead ICE in the backend with a failure to select message.
Example:
__m128d foo(__m128d a, __m128d b) {
return __builtin_ia32_addsubps(b, a);
}
compiled for normal x86_64 via:
clang -target x86_64-linux-gnu -c
would fail to compile in the back end because the normal subtarget
features for x86_64 only include sse2 and the builtin requires sse3.
[1] We're still not erroring on:
__m128i bar(__m128i const *p) { return _mm_lddqu_si128(p); }
where we should fail and error on an always_inline function being
inlined into a function that doesn't support the subtarget features
required.
llvm-svn: 250473
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGen/target-builtin-error-2.c | 13 | ||||
-rw-r--r-- | clang/test/CodeGen/target-builtin-error.c | 8 | ||||
-rw-r--r-- | clang/test/CodeGen/target-builtin-noerror.c | 30 |
3 files changed, 51 insertions, 0 deletions
diff --git a/clang/test/CodeGen/target-builtin-error-2.c b/clang/test/CodeGen/target-builtin-error-2.c new file mode 100644 index 00000000000..949f2cc7846 --- /dev/null +++ b/clang/test/CodeGen/target-builtin-error-2.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - +#define __MM_MALLOC_H + +#include <x86intrin.h> + +// Since we do code generation on a function level this needs to error out since +// the subtarget feature won't be available. +__m256d wombat(__m128i a) { + if (__builtin_cpu_supports("avx")) + return __builtin_ia32_cvtdq2pd256((__v4si)a); // expected-error {{'__builtin_ia32_cvtdq2pd256' needs target feature avx}} + else + return (__m256d){0, 0, 0, 0}; +} diff --git a/clang/test/CodeGen/target-builtin-error.c b/clang/test/CodeGen/target-builtin-error.c new file mode 100644 index 00000000000..ee41277706a --- /dev/null +++ b/clang/test/CodeGen/target-builtin-error.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - +#define __MM_MALLOC_H + +#include <x86intrin.h> + +__m128d foo(__m128d a, __m128d b) { + return __builtin_ia32_addsubps(b, a); // expected-error {{'__builtin_ia32_addsubps' needs target feature sse3}} +} diff --git a/clang/test/CodeGen/target-builtin-noerror.c b/clang/test/CodeGen/target-builtin-noerror.c new file mode 100644 index 00000000000..fd9f68e5b43 --- /dev/null +++ b/clang/test/CodeGen/target-builtin-noerror.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -o - +#define __MM_MALLOC_H + +#include <x86intrin.h> + +// No warnings. +extern __m256i a; +int __attribute__((target("avx"))) bar(__m256i a) { + return _mm256_extract_epi32(a, 3); +} + +int baz() { + return bar(a); +} + +int __attribute__((target("avx"))) qq_avx(__m256i a) { + return _mm256_extract_epi32(a, 3); +} + +int qq_noavx() { + return 0; +} + +extern __m256i a; +int qq() { + if (__builtin_cpu_supports("avx")) + return qq_avx(a); + else + return qq_noavx(); +} |