[PATCH] D15721: [Sema] Fix ICE on casting a vector of bools to a vector of T

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 26 14:28:48 PST 2016


george.burgess.iv added a comment.

> I think we will also need to forbid the invalid conversions too at some point.


test/SemaOpenCL/vector_conv_invalid.cl checks that clang gives you errors converting e.g. a `4 x unsigned` to a `4 x int`. So, unless you were referring to something else, that seems to be covered already. :)


================
Comment at: lib/Sema/SemaExpr.cpp:5715
@@ +5714,3 @@
+  // when compiling code as e.g. C++)
+  uint64_t srcEltSize =
+      srcEltTy->isBooleanType() ? 1 : Context.getTypeSize(srcEltTy);
----------------
Anastasia wrote:
> Ok, I see now. I think your code here makes sense.
> 
> I am just generally a bit confused about how it should work. If I look at a slightly different example:
> 
>   typedef __attribute__((__ext_vector_type__(4))) bool BoolVector; 
>   typedef __attribute__((__ext_vector_type__(1))) int IntVector;
> 
>   int main() {
>     BoolVector bv;
>     bool b=1;
>     bv.s1 = b;
>   }
> 
> this generates in IR:
>   store <4 x i1> %2, <4 x i1>* %bv
> 
> seems a bit odd to see a store of 4 bits. Would it be changed by a middlend/backend then?
That's a good question! Clang+LLVM seems to handle straight-line code with odd-sized vectors fine, and seem to produce working x86 binaries (though, as you can probably tell, I'm far from an expert on vectors, so I could certainly be wrong).

We apparently have an issue with function calls, though. When I run the executable produced by this:

```
typedef __attribute__((__ext_vector_type__(4))) _Bool BoolVector;
BoolVector flip(BoolVector bv) {
  BoolVector bv2 = (BoolVector)1;
  return bv2 ^ bv;
}

int main() {
  BoolVector bv = (BoolVector)0;
  bv = flip(bv);
  printf("bv[0] = %d, bv[1] = %d, bv[2] = %d, bv[3] = %d\n", bv[0], bv[1], bv[2], bv[3]);
}
```

I see "bv[0] = 1, bv[1] = 0, bv[2] = 0, bv[3] = 0". I'm pretty sure it should be printing all 1s, since that's what I get if I manually inline `flip`, or change the vector element type to e.g. `char`.

After poking around a bit, I think the problem may be in how we pack/unpack these bit vectors as arguments and returned values (the same problem occurs even if `flip` is marked `always_inline`). Will look into it more/file a bug later today.

================
Comment at: lib/Sema/SemaType.cpp:2191
@@ +2190,3 @@
+  // Additionally, OpenCL prohibits vectors of booleans (they're considered a
+  // reserved data type under Section 6.1.4), but we do allow their use outside
+  // of OpenCL.
----------------
Anastasia wrote:
> Could you change (there can be differences depending on a language version):
> 
> under Section 6.1.4 -> OpenCL v2.0 s6.1.4
Nice catch.


http://reviews.llvm.org/D15721





More information about the cfe-commits mailing list