[PATCH] D33732: Catch invalid bitwise operation on vector of floats
This revision was automatically updated to reflect the committed changes. Closed by commit rL304963: Catch invalid bitwise operation on vector of floats (authored by sepavloff). Changed prior to commit: https://reviews.llvm.org/D33732?vs=101359&id=101856#toc Repository: rL LLVM https://reviews.llvm.org/D33732 Files: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/Sema/ext_vector_ops.c Index: cfe/trunk/test/Sema/ext_vector_ops.c === --- cfe/trunk/test/Sema/ext_vector_ops.c +++ cfe/trunk/test/Sema/ext_vector_ops.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion -triple x86_64-apple-darwin10 + +typedef unsigned int v2u __attribute__ ((ext_vector_type(2))); +typedef int v2s __attribute__ ((ext_vector_type(2))); +typedef float v2f __attribute__ ((ext_vector_type(2))); + +void test1(v2u v2ua, v2s v2sa, v2f v2fa) { + // Bitwise binary operators + (void)(v2ua & v2ua); + (void)(v2fa & v2fa); // expected-error{{invalid operands to binary expression}} + + // Unary operators + (void)(~v2ua); + (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 'float' values) to unary}} + + // Comparison operators + v2sa = (v2ua==v2sa); + + // Arrays + int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values}} + int array2[17]; + // FIXME: error message below needs type! + (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}} + + v2u *v2u_ptr = 0; + v2s *v2s_ptr; +} Index: cfe/trunk/lib/Sema/SemaExpr.cpp === --- cfe/trunk/lib/Sema/SemaExpr.cpp +++ cfe/trunk/lib/Sema/SemaExpr.cpp @@ -11975,16 +11975,13 @@ << resultType << Input.get()->getSourceRange(); else if (resultType->hasIntegerRepresentation()) break; -else if (resultType->isExtVectorType()) { - if (Context.getLangOpts().OpenCL) { -// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate -// on vector float types. -QualType T = resultType->getAs()->getElementType(); -if (!T->isIntegerType()) - return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); - } - break; +else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) { + // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate + // on vector float types. + QualType T = resultType->getAs()->getElementType(); + if (!T->isIntegerType()) +return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) + << resultType << Input.get()->getSourceRange()); } else { return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) << resultType << Input.get()->getSourceRange()); Index: cfe/trunk/test/Sema/ext_vector_ops.c === --- cfe/trunk/test/Sema/ext_vector_ops.c +++ cfe/trunk/test/Sema/ext_vector_ops.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion -triple x86_64-apple-darwin10 + +typedef unsigned int v2u __attribute__ ((ext_vector_type(2))); +typedef int v2s __attribute__ ((ext_vector_type(2))); +typedef float v2f __attribute__ ((ext_vector_type(2))); + +void test1(v2u v2ua, v2s v2sa, v2f v2fa) { + // Bitwise binary operators + (void)(v2ua & v2ua); + (void)(v2fa & v2fa); // expected-error{{invalid operands to binary expression}} + + // Unary operators + (void)(~v2ua); + (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 'float' values) to unary}} + + // Comparison operators + v2sa = (v2ua==v2sa); + + // Arrays + int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values}} + int array2[17]; + // FIXME: error message below needs type! + (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}} + + v2u *v2u_ptr = 0; + v2s *v2s_ptr; +} Index: cfe/trunk/lib/Sema/SemaExpr.cpp === --- cfe/trunk/lib/Sema/SemaExpr.cpp +++ cfe/trunk/lib/Sema/SemaExpr.cpp @@ -11975,16 +11975,13 @@ << resultType << Input.get()->getSourceRange(); else if (resultType->hasIntegerRepresentation()) break; -else if (resultType->isExtVectorType()) { - if (Context.getLangOpts().OpenCL) { -// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate -// on vector float types. -QualType T = resultType->getAs()->getElementType(); -if (!T->isIntegerType()) - return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); - } - break; +else if (resultType->isExt
[PATCH] D33732: Catch invalid bitwise operation on vector of floats
bruno accepted this revision. bruno added a comment. This revision is now accepted and ready to land. LGTM Comment at: test/Sema/ext_vector_ops.c:22 + int array2[17]; + // FIXME: error message below needs type! + (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}} Can you file a PR for this? https://reviews.llvm.org/D33732 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33732: Catch invalid bitwise operation on vector of floats
sepavloff updated this revision to Diff 101359. sepavloff added a comment. Updated regression test The new regression test was obtained from Sema/vector-ops.c, the part of it that checks binary complement was copied. https://reviews.llvm.org/D33732 Files: lib/Sema/SemaExpr.cpp test/Sema/ext_vector_ops.c Index: test/Sema/ext_vector_ops.c === --- /dev/null +++ test/Sema/ext_vector_ops.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion -triple x86_64-apple-darwin10 + +typedef unsigned int v2u __attribute__ ((ext_vector_type(2))); +typedef int v2s __attribute__ ((ext_vector_type(2))); +typedef float v2f __attribute__ ((ext_vector_type(2))); + +void test1(v2u v2ua, v2s v2sa, v2f v2fa) { + // Bitwise binary operators + (void)(v2ua & v2ua); + (void)(v2fa & v2fa); // expected-error{{invalid operands to binary expression}} + + // Unary operators + (void)(~v2ua); + (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 'float' values) to unary}} + + // Comparison operators + v2sa = (v2ua==v2sa); + + // Arrays + int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values}} + int array2[17]; + // FIXME: error message below needs type! + (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}} + + v2u *v2u_ptr = 0; + v2s *v2s_ptr; +} Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -11953,16 +11953,13 @@ << resultType << Input.get()->getSourceRange(); else if (resultType->hasIntegerRepresentation()) break; -else if (resultType->isExtVectorType()) { - if (Context.getLangOpts().OpenCL) { -// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate -// on vector float types. -QualType T = resultType->getAs()->getElementType(); -if (!T->isIntegerType()) - return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); - } - break; +else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) { + // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate + // on vector float types. + QualType T = resultType->getAs()->getElementType(); + if (!T->isIntegerType()) +return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) + << resultType << Input.get()->getSourceRange()); } else { return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) << resultType << Input.get()->getSourceRange()); Index: test/Sema/ext_vector_ops.c === --- /dev/null +++ test/Sema/ext_vector_ops.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion -triple x86_64-apple-darwin10 + +typedef unsigned int v2u __attribute__ ((ext_vector_type(2))); +typedef int v2s __attribute__ ((ext_vector_type(2))); +typedef float v2f __attribute__ ((ext_vector_type(2))); + +void test1(v2u v2ua, v2s v2sa, v2f v2fa) { + // Bitwise binary operators + (void)(v2ua & v2ua); + (void)(v2fa & v2fa); // expected-error{{invalid operands to binary expression}} + + // Unary operators + (void)(~v2ua); + (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 'float' values) to unary}} + + // Comparison operators + v2sa = (v2ua==v2sa); + + // Arrays + int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values}} + int array2[17]; + // FIXME: error message below needs type! + (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}} + + v2u *v2u_ptr = 0; + v2s *v2s_ptr; +} Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -11953,16 +11953,13 @@ << resultType << Input.get()->getSourceRange(); else if (resultType->hasIntegerRepresentation()) break; -else if (resultType->isExtVectorType()) { - if (Context.getLangOpts().OpenCL) { -// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate -// on vector float types. -QualType T = resultType->getAs()->getElementType(); -if (!T->isIntegerType()) - return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); - } - break; +else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) { + // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate + // on vector float types. + QualType T = resultType->getAs()->getElementType(); + if (!T->isInteger
[PATCH] D33732: Catch invalid bitwise operation on vector of floats
sepavloff added inline comments. Comment at: test/Sema/types.c:92 + +typedef float __attribute__((ext_vector_type(4))) float4; +float4 test3(float4 x) { bruno wrote: > Can you also add a test for the `vector_type` variant? It might be more > appropriate to put this at test/Sema/ext_vector* and test/Sema/vector* The test for the `vector_type` variant already exists in `test/Sema/vector-ops.c`. I tried to made similar test file for `ext_vector_type` by copying vector-ops.c and replacing vector types accordingly, but there are many differences in diagnostic, so only the part that checks the complement operation was copied. https://reviews.llvm.org/D33732 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33732: Catch invalid bitwise operation on vector of floats
bruno added a comment. Hi, Comment at: test/Sema/types.c:92 + +typedef float __attribute__((ext_vector_type(4))) float4; +float4 test3(float4 x) { Can you also add a test for the `vector_type` variant? It might be more appropriate to put this at test/Sema/ext_vector* and test/Sema/vector* https://reviews.llvm.org/D33732 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33732: Catch invalid bitwise operation on vector of floats
sepavloff created this revision. Bitwise complement applied to vector of floats described with attribute `ext_vector_type` is not diagnosed as error. Attempt to compile such construct causes assertion violation in Instruction.cpp. With this change the complement is treated similar to the case of vector type described with attribute `vector_size`. https://reviews.llvm.org/D33732 Files: lib/Sema/SemaExpr.cpp test/Sema/types.c Index: test/Sema/types.c === --- test/Sema/types.c +++ test/Sema/types.c @@ -88,3 +88,8 @@ int &*_Atomic null_type_0; // expected-error {{expected identifier or '('}} int &*__restrict__ null_type_1; // expected-error {{expected identifier or '('}} int ^_Atomic null_type_2; // expected-error {{block pointer to non-function type is invalid}} + +typedef float __attribute__((ext_vector_type(4))) float4; +float4 test3(float4 x) { + return ~x; // expected-error{{invalid argument type 'float4' (vector of 4 'float' values) to unary expression}} +} Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -11951,16 +11951,13 @@ << resultType << Input.get()->getSourceRange(); else if (resultType->hasIntegerRepresentation()) break; -else if (resultType->isExtVectorType()) { - if (Context.getLangOpts().OpenCL) { -// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate -// on vector float types. -QualType T = resultType->getAs()->getElementType(); -if (!T->isIntegerType()) - return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); - } - break; +else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) { + // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate + // on vector float types. + QualType T = resultType->getAs()->getElementType(); + if (!T->isIntegerType()) +return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) + << resultType << Input.get()->getSourceRange()); } else { return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) << resultType << Input.get()->getSourceRange()); Index: test/Sema/types.c === --- test/Sema/types.c +++ test/Sema/types.c @@ -88,3 +88,8 @@ int &*_Atomic null_type_0; // expected-error {{expected identifier or '('}} int &*__restrict__ null_type_1; // expected-error {{expected identifier or '('}} int ^_Atomic null_type_2; // expected-error {{block pointer to non-function type is invalid}} + +typedef float __attribute__((ext_vector_type(4))) float4; +float4 test3(float4 x) { + return ~x; // expected-error{{invalid argument type 'float4' (vector of 4 'float' values) to unary expression}} +} Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -11951,16 +11951,13 @@ << resultType << Input.get()->getSourceRange(); else if (resultType->hasIntegerRepresentation()) break; -else if (resultType->isExtVectorType()) { - if (Context.getLangOpts().OpenCL) { -// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate -// on vector float types. -QualType T = resultType->getAs()->getElementType(); -if (!T->isIntegerType()) - return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); - } - break; +else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) { + // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate + // on vector float types. + QualType T = resultType->getAs()->getElementType(); + if (!T->isIntegerType()) +return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) + << resultType << Input.get()->getSourceRange()); } else { return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) << resultType << Input.get()->getSourceRange()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits