r259011 - [Sema] Make extended vectors of `bool` an error.
George Burgess IV via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 27 17:38:18 PST 2016
Author: gbiv
Date: Wed Jan 27 19:38:18 2016
New Revision: 259011
URL: http://llvm.org/viewvc/llvm-project?rev=259011&view=rev
Log:
[Sema] Make extended vectors of `bool` an error.
In OpenCL, `bool` vectors are a reserved type, and are therefore
illegal.
Outside of OpenCL, if we try to make an extended vector of N `bool`s,
Clang will lower it to an `[N x i1]`. LLVM has no ABI for bitvectors, so
lots of operations on such vectors are thoroughly broken. As a result,
this patch makes them illegal in everything else, as well. :)
Differential Revision: http://reviews.llvm.org/D15721
Added:
cfe/trunk/test/SemaOpenCL/bool-vectors.cl
Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGen/convertvector.c
cfe/trunk/test/Sema/ext_vector_casts.c
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=259011&r1=259010&r2=259011&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Jan 27 19:38:18 2016
@@ -2183,10 +2183,16 @@ QualType Sema::BuildArrayType(QualType T
/// Run the required checks for the extended vector type.
QualType Sema::BuildExtVectorType(QualType T, Expr *ArraySize,
SourceLocation AttrLoc) {
- // unlike gcc's vector_size attribute, we do not allow vectors to be defined
+ // Unlike gcc's vector_size attribute, we do not allow vectors to be defined
// in conjunction with complex types (pointers, arrays, functions, etc.).
- if (!T->isDependentType() &&
- !T->isIntegerType() && !T->isRealFloatingType()) {
+ //
+ // Additionally, OpenCL prohibits vectors of booleans (they're considered a
+ // reserved data type under OpenCL v2.0 s6.1.4), we don't support selects
+ // on bitvectors, and we have no well-defined ABI for bitvectors, so vectors
+ // of bool aren't allowed.
+ if ((!T->isDependentType() && !T->isIntegerType() &&
+ !T->isRealFloatingType()) ||
+ T->isBooleanType()) {
Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << T;
return QualType();
}
@@ -2200,7 +2206,7 @@ QualType Sema::BuildExtVectorType(QualTy
return QualType();
}
- // unlike gcc's vector_size attribute, the size is specified as the
+ // Unlike gcc's vector_size attribute, the size is specified as the
// number of elements, not the number of bytes.
unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue());
Modified: cfe/trunk/test/CodeGen/convertvector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/convertvector.c?rev=259011&r1=259010&r2=259011&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/convertvector.c (original)
+++ cfe/trunk/test/CodeGen/convertvector.c Wed Jan 27 19:38:18 2016
@@ -9,14 +9,6 @@ typedef unsigned long vector8ulong _
typedef unsigned short vector8ushort __attribute__((__vector_size__(16)));
#ifdef __cplusplus
-#define BOOL bool
-#else
-#define BOOL _Bool
-#endif
-
-typedef BOOL vector8bool __attribute__((__ext_vector_type__(8)));
-
-#ifdef __cplusplus
extern "C" {
#endif
@@ -32,13 +24,6 @@ vector8double flt_ext(vector8float x) {
// CHECK: fpext <8 x float> %{{[^ ]}} to <8 x double>
}
-vector8bool flt_tobool(vector8float x) {
- return __builtin_convertvector(x, vector8bool);
- // CHECK-LABEL: @flt_tobool
- // CHECK-NOT: fptoui <8 x float> %{{[^ ]}} to <8 x i1>
- // CHECK: fcmp une <8 x float> %{{[^ ]}}, zeroinitializer
-}
-
vector8long flt_tosi(vector8float x) {
return __builtin_convertvector(x, vector8long);
// CHECK-LABEL: @flt_tosi
@@ -69,13 +54,6 @@ vector8long int_sext(vector8short x) {
// CHECK: sext <8 x i16> %{{[^ ]}} to <8 x i64>
}
-vector8bool int_tobool(vector8short x) {
- return __builtin_convertvector(x, vector8bool);
- // CHECK-LABEL: @int_tobool
- // CHECK-NOT: trunc <8 x i16> %{{[^ ]}} to <8 x i1>
- // CHECK: icmp ne <8 x i16> %{{[^ ]}}, zeroinitializer
-}
-
vector8float int_tofp(vector8short x) {
return __builtin_convertvector(x, vector8float);
// CHECK-LABEL: @int_tofp
Modified: cfe/trunk/test/Sema/ext_vector_casts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ext_vector_casts.c?rev=259011&r1=259010&r2=259011&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ext_vector_casts.c (original)
+++ cfe/trunk/test/Sema/ext_vector_casts.c Wed Jan 27 19:38:18 2016
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -fsyntax-only -verify -fno-lax-vector-conversions -Wconversion %s
+typedef __attribute__((ext_vector_type(8))) _Bool BoolVector; // expected-error {{invalid vector element type '_Bool'}}
+
typedef __attribute__(( ext_vector_type(2) )) float float2;
typedef __attribute__(( ext_vector_type(3) )) float float3;
typedef __attribute__(( ext_vector_type(4) )) int int4;
Added: cfe/trunk/test/SemaOpenCL/bool-vectors.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/bool-vectors.cl?rev=259011&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/bool-vectors.cl (added)
+++ cfe/trunk/test/SemaOpenCL/bool-vectors.cl Wed Jan 27 19:38:18 2016
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+typedef __attribute__((ext_vector_type(16))) _Bool bool8; // expected-error{{invalid vector element type 'bool'}}
More information about the cfe-commits
mailing list