Skip to content

Commit 590eb76

Browse files
committed
[test] Add C++ ext_vector_type tests
Add initial tests for the behavior of ext_vector_type vectors for vector vs scalar ops in C++. Their behavior doesn't agree with the behavior in C and what the behavior seems like it should be, these are baseline tests before implementing those changes. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D151059
1 parent ca1b994 commit 590eb76

File tree

1 file changed

+227
-0
lines changed

1 file changed

+227
-0
lines changed

clang/test/SemaCXX/vector.cpp

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,230 @@ void triggerIntegerRankCheck() {
545545
auto b4 = (v4 >= 0x12);
546546
}
547547
#endif
548+
549+
namespace all_operators {
550+
typedef unsigned int v2u __attribute__((ext_vector_type(2)));
551+
typedef float v2f __attribute__((ext_vector_type(2)));
552+
553+
void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
554+
// Operators with one integer vector and one integer scalar operand. The scalar will splat.
555+
(void)(v2ua + ua);
556+
(void)(ua + v2ua);
557+
(void)(v2ua - ua);
558+
(void)(ua - v2ua);
559+
(void)(v2ua * ua);
560+
(void)(ua * v2ua);
561+
(void)(v2ua / ua);
562+
(void)(ua / v2ua);
563+
(void)(v2ua % ua);
564+
(void)(ua % v2ua);
565+
566+
(void)(v2ua == ua);
567+
(void)(ua == v2ua);
568+
(void)(v2ua != ua);
569+
(void)(ua != v2ua);
570+
(void)(v2ua <= ua);
571+
(void)(ua <= v2ua);
572+
(void)(v2ua >= ua);
573+
(void)(ua >= v2ua);
574+
(void)(v2ua < ua);
575+
(void)(ua < v2ua);
576+
(void)(v2ua > ua);
577+
(void)(ua > v2ua);
578+
(void)(v2ua && ua);
579+
(void)(ua && v2ua);
580+
(void)(v2ua || ua);
581+
(void)(ua || v2ua);
582+
583+
(void)(v2ua & ua);
584+
(void)(ua & v2ua);
585+
(void)(v2ua | ua);
586+
(void)(ua | v2ua);
587+
(void)(v2ua ^ ua);
588+
(void)(ua ^ v2ua);
589+
(void)(v2ua << ua);
590+
(void)(ua << v2ua);
591+
(void)(v2ua >> ua);
592+
(void)(ua >> v2ua);
593+
594+
v2ua += ua;
595+
v2ua -= ua;
596+
v2ua *= ua;
597+
v2ua /= ua;
598+
v2ua %= ua;
599+
v2ua &= ua;
600+
v2ua |= ua;
601+
v2ua ^= ua;
602+
v2ua >>= ua;
603+
v2ua <<= ua;
604+
605+
ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
606+
ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
607+
ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
608+
ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
609+
ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
610+
ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
611+
ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
612+
ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
613+
ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
614+
ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
615+
}
616+
617+
void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
618+
// Operators with one float vector and one float scalar operand. The scalar will splat.
619+
(void)(v2fa + fa);
620+
(void)(fa + v2fa);
621+
(void)(v2fa - fa);
622+
(void)(fa - v2fa);
623+
(void)(v2fa * fa);
624+
(void)(fa * v2fa);
625+
(void)(v2fa / fa);
626+
(void)(fa / v2fa);
627+
(void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
628+
(void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}
629+
630+
(void)(v2fa == fa);
631+
(void)(fa == v2fa);
632+
(void)(v2fa != fa);
633+
(void)(fa != v2fa);
634+
(void)(v2fa <= fa);
635+
(void)(fa <= v2fa);
636+
(void)(v2fa >= fa);
637+
(void)(fa >= v2fa);
638+
(void)(v2fa < fa);
639+
(void)(fa < v2fa);
640+
(void)(v2fa > fa);
641+
(void)(fa > v2fa);
642+
(void)(v2fa && fa);
643+
(void)(fa && v2fa);
644+
(void)(v2fa || fa);
645+
(void)(fa || v2fa);
646+
647+
(void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
648+
(void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
649+
(void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
650+
(void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
651+
(void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
652+
(void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
653+
(void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
654+
(void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
655+
(void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
656+
(void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
657+
(void)(v2fa >> fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
658+
(void)(v2fa >> ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
659+
(void)(fa >> v2fa); // expected-error{{used type 'float' where integer is required}}
660+
(void)(ua >> v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
661+
662+
v2fa += fa;
663+
v2fa -= fa;
664+
v2fa *= fa;
665+
v2fa /= fa;
666+
v2fa %= fa; // expected-error{{invalid operands to binary expression}}
667+
v2fa &= fa; // expected-error{{invalid operands to binary expression}}
668+
v2fa |= fa; // expected-error{{invalid operands to binary expression}}
669+
v2fa ^= fa; // expected-error{{invalid operands to binary expression}}
670+
v2fa >>= fa; // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
671+
v2fa <<= fa; // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
672+
673+
fa += v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
674+
fa -= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
675+
fa *= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
676+
fa /= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
677+
fa %= v2fa; // expected-error{{invalid operands to binary expression}}
678+
fa &= v2fa; // expected-error{{invalid operands to binary expression}}
679+
fa |= v2fa; // expected-error{{invalid operands to binary expression}}
680+
fa ^= v2fa; // expected-error{{invalid operands to binary expression}}
681+
fa >>= v2fa; // expected-error{{used type 'float' where integer is required}}
682+
fa <<= v2fa; // expected-error{{used type 'float' where integer is required}}
683+
}
684+
685+
enum Enum { ENUM };
686+
687+
void test_enum_vector_scalar(Enum ea, v2u v2ua) {
688+
// Operators with one integer vector and one enum scalar operand.
689+
// The scalar will have an implicit conversion to an integral type and then splat.
690+
// FIXME: These should behave the same as in C, they should be accepted via
691+
// the enum converting to an integer then splatting to the vector width.
692+
// https://github.com/llvm/llvm-project/issues/62869
693+
(void)(v2ua + ea); // expected-error{{cannot convert between vector values of different size}}
694+
(void)(ea + v2ua); // expected-error{{cannot convert between vector values of different size}}
695+
(void)(v2ua - ea); // expected-error{{cannot convert between vector values of different size}}
696+
(void)(ea - v2ua); // expected-error{{cannot convert between vector values of different size}}
697+
(void)(v2ua * ea); // expected-error{{cannot convert between vector values of different size}}
698+
(void)(ea * v2ua); // expected-error{{cannot convert between vector values of different size}}
699+
(void)(v2ua / ea); // expected-error{{cannot convert between vector values of different size}}
700+
(void)(ea / v2ua); // expected-error{{cannot convert between vector values of different size}}
701+
(void)(v2ua % ea); // expected-error{{cannot convert between vector values of different size}}
702+
(void)(ea % v2ua); // expected-error{{cannot convert between vector values of different size}}
703+
704+
(void)(v2ua == ea); // expected-error{{cannot convert between vector values of different size}}
705+
(void)(ea == v2ua); // expected-error{{cannot convert between vector values of different size}}
706+
(void)(v2ua != ea); // expected-error{{cannot convert between vector values of different size}}
707+
(void)(ea != v2ua); // expected-error{{cannot convert between vector values of different size}}
708+
(void)(v2ua <= ea); // expected-error{{cannot convert between vector values of different size}}
709+
(void)(ea <= v2ua); // expected-error{{cannot convert between vector values of different size}}
710+
(void)(v2ua >= ea); // expected-error{{cannot convert between vector values of different size}}
711+
(void)(ea >= v2ua); // expected-error{{cannot convert between vector values of different size}}
712+
(void)(v2ua < ea); // expected-error{{cannot convert between vector values of different size}}
713+
(void)(ea < v2ua); // expected-error{{cannot convert between vector values of different size}}
714+
(void)(v2ua > ea); // expected-error{{cannot convert between vector values of different size}}
715+
(void)(ea > v2ua); // expected-error{{cannot convert between vector values of different size}}
716+
(void)(v2ua && ea); // expected-error{{cannot convert between vector values of different size}}
717+
// expected-error@-1{{invalid operands to binary expression}}
718+
(void)(ea && v2ua); // expected-error{{cannot convert between vector values of different size}}
719+
// expected-error@-1{{invalid operands to binary expression}}
720+
(void)(v2ua || ea); // expected-error{{cannot convert between vector values of different size}}
721+
// expected-error@-1{{invalid operands to binary expression}}
722+
(void)(ea || v2ua); // expected-error{{cannot convert between vector values of different size}}
723+
// expected-error@-1{{invalid operands to binary expression}}
724+
725+
(void)(v2ua & ea); // expected-error{{cannot convert between vector values of different size}}
726+
(void)(ea & v2ua); // expected-error{{cannot convert between vector values of different size}}
727+
(void)(v2ua | ea); // expected-error{{cannot convert between vector values of different size}}
728+
(void)(ea | v2ua); // expected-error{{cannot convert between vector values of different size}}
729+
(void)(v2ua ^ ea); // expected-error{{cannot convert between vector values of different size}}
730+
(void)(ea ^ v2ua); // expected-error{{cannot convert between vector values of different size}}
731+
// FIXME: Vector/scalar shifts cause an assertion failure
732+
// https://github.com/llvm/llvm-project/issues/62870
733+
// (void)(v2ua << ea);
734+
// (void)(ea << v2ua);
735+
// (void)(v2ua >> ea);
736+
// (void)(ea >> v2ua);
737+
738+
v2ua += ea; // expected-error{{cannot convert between vector values of different size}}
739+
v2ua -= ea; // expected-error{{cannot convert between vector values of different size}}
740+
v2ua *= ea; // expected-error{{cannot convert between vector values of different size}}
741+
v2ua /= ea; // expected-error{{cannot convert between vector values of different size}}
742+
v2ua %= ea; // expected-error{{cannot convert between vector values of different size}}
743+
v2ua &= ea; // expected-error{{cannot convert between vector values of different size}}
744+
v2ua |= ea; // expected-error{{cannot convert between vector values of different size}}
745+
v2ua ^= ea; // expected-error{{cannot convert between vector values of different size}}
746+
// FIXME: Vector/scalar shifts cause an assertion failure
747+
// https://github.com/llvm/llvm-project/issues/62870
748+
// v2ua >>= ea;
749+
// v2ua <<= ea;
750+
751+
ea += v2ua; // expected-error{{cannot convert between vector values of different size}}
752+
ea -= v2ua; // expected-error{{cannot convert between vector values of different size}}
753+
ea *= v2ua; // expected-error{{cannot convert between vector values of different size}}
754+
ea /= v2ua; // expected-error{{cannot convert between vector values of different size}}
755+
ea %= v2ua; // expected-error{{cannot convert between vector values of different size}}
756+
ea &= v2ua; // expected-error{{cannot convert between vector values of different size}}
757+
ea |= v2ua; // expected-error{{cannot convert between vector values of different size}}
758+
ea ^= v2ua; // expected-error{{cannot convert between vector values of different size}}
759+
// FIXME: Vector/scalar shifts cause an assertion failure
760+
// https://github.com/llvm/llvm-project/issues/62870
761+
// ea >>= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
762+
// ea <<= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
763+
}
764+
765+
#if __cplusplus >= 201103L // C++11 or later
766+
enum class EnumClass { ENUM };
767+
768+
void test_scoped_enum_vector(EnumClass ea, v2u v2ua) {
769+
// Scoped enumerations are only compatible with exactly matching types. They shouldn't integral promote.
770+
(void)(v2ua + ea); // expected-error{{cannot convert between vector and non-scalar values}}
771+
(void)(ea + v2ua); // expected-error{{cannot convert between vector and non-scalar values}}
772+
}
773+
#endif
774+
}

0 commit comments

Comments
 (0)