aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Sema/builtins-elementwise-math.c
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2021-10-26 15:38:32 +0100
committerFlorian Hahn <flo@fhahn.com>2021-10-26 16:53:40 +0100
commit1ef25d28c19e3b2e956ffcb39c91f98c154f9b3f (patch)
tree28858076debf93d765e27eb40da9d914ade6b93c /clang/test/Sema/builtins-elementwise-math.c
parent4f423e91276d302550b3b4d932c6694297d6882e (diff)
downloadllvm-1ef25d28c19e3b2e956ffcb39c91f98c154f9b3f.zip
llvm-1ef25d28c19e3b2e956ffcb39c91f98c154f9b3f.tar.gz
llvm-1ef25d28c19e3b2e956ffcb39c91f98c154f9b3f.tar.bz2
[Clang] Add elementwise min/max builtins.
This patch implements __builtin_elementwise_max and __builtin_elementwise_min, as specified in D111529. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D111985
Diffstat (limited to 'clang/test/Sema/builtins-elementwise-math.c')
-rw-r--r--clang/test/Sema/builtins-elementwise-math.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/clang/test/Sema/builtins-elementwise-math.c b/clang/test/Sema/builtins-elementwise-math.c
new file mode 100644
index 0000000..7c3c1aa
--- /dev/null
+++ b/clang/test/Sema/builtins-elementwise-math.c
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 -std=c99 %s -pedantic -verify -triple=x86_64-apple-darwin9
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+typedef int int3 __attribute__((ext_vector_type(3)));
+
+struct Foo {
+ char *p;
+};
+
+__attribute__((address_space(1))) int int_as_one;
+typedef int bar;
+bar b;
+
+void test_builtin_elementwise_max(int i, short s, double d, float4 v, int3 iv, int *p) {
+ i = __builtin_elementwise_max(p, d);
+ // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
+
+ struct Foo foo = __builtin_elementwise_max(i, i);
+ // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+
+ i = __builtin_elementwise_max(i);
+ // expected-error@-1 {{too few arguments to function call, expected 2, have 1}}
+
+ i = __builtin_elementwise_max();
+ // expected-error@-1 {{too few arguments to function call, expected 2, have 0}}
+
+ i = __builtin_elementwise_max(i, i, i);
+ // expected-error@-1 {{too many arguments to function call, expected 2, have 3}}
+
+ i = __builtin_elementwise_max(v, iv);
+ // expected-error@-1 {{arguments are of different types ('float4' (vector of 4 'float' values) vs 'int3' (vector of 3 'int' values))}}
+
+ s = __builtin_elementwise_max(i, s);
+
+ enum e { one,
+ two };
+ i = __builtin_elementwise_max(one, two);
+
+ enum f { three };
+ enum f x = __builtin_elementwise_max(one, three);
+
+ _ExtInt(32) ext;
+ ext = __builtin_elementwise_max(ext, ext);
+
+ const int ci;
+ i = __builtin_elementwise_max(ci, i);
+ i = __builtin_elementwise_max(i, ci);
+ i = __builtin_elementwise_max(ci, ci);
+
+ i = __builtin_elementwise_max(i, int_as_one); // ok (attributes don't match)?
+ i = __builtin_elementwise_max(i, b); // ok (sugar doesn't match)?
+
+ int A[10];
+ A = __builtin_elementwise_max(A, A);
+ // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'int *')}}
+
+ int(ii);
+ int j;
+ j = __builtin_elementwise_max(i, j);
+
+ _Complex float c1, c2;
+ c1 = __builtin_elementwise_max(c1, c2);
+ // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
+
+void test_builtin_elementwise_min(int i, short s, double d, float4 v, int3 iv, int *p) {
+ i = __builtin_elementwise_min(p, d);
+ // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
+
+ struct Foo foo = __builtin_elementwise_min(i, i);
+ // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+
+ i = __builtin_elementwise_min(i);
+ // expected-error@-1 {{too few arguments to function call, expected 2, have 1}}
+
+ i = __builtin_elementwise_min();
+ // expected-error@-1 {{too few arguments to function call, expected 2, have 0}}
+
+ i = __builtin_elementwise_min(i, i, i);
+ // expected-error@-1 {{too many arguments to function call, expected 2, have 3}}
+
+ i = __builtin_elementwise_min(v, iv);
+ // expected-error@-1 {{arguments are of different types ('float4' (vector of 4 'float' values) vs 'int3' (vector of 3 'int' values))}}
+
+ s = __builtin_elementwise_min(i, s);
+
+ enum e { one,
+ two };
+ i = __builtin_elementwise_min(one, two);
+
+ enum f { three };
+ enum f x = __builtin_elementwise_min(one, three);
+
+ _ExtInt(32) ext;
+ ext = __builtin_elementwise_min(ext, ext);
+
+ const int ci;
+ i = __builtin_elementwise_min(ci, i);
+ i = __builtin_elementwise_min(i, ci);
+ i = __builtin_elementwise_min(ci, ci);
+
+ i = __builtin_elementwise_min(i, int_as_one); // ok (attributes don't match)?
+ i = __builtin_elementwise_min(i, b); // ok (sugar doesn't match)?
+
+ int A[10];
+ A = __builtin_elementwise_min(A, A);
+ // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'int *')}}
+
+ int(ii);
+ int j;
+ j = __builtin_elementwise_min(i, j);
+
+ _Complex float c1, c2;
+ c1 = __builtin_elementwise_min(c1, c2);
+ // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}