]> granicus.if.org Git - clang/commitdiff
PR4339: make sure to properly extend/trunc the index of a vector element
authorEli Friedman <eli.friedman@gmail.com>
Sat, 6 Jun 2009 19:09:26 +0000 (19:09 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 6 Jun 2009 19:09:26 +0000 (19:09 +0000)
insert/extract; the relevant instructions are defined to take only an
i32.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73005 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGen/vector.c

index c5f23879d1c392c7276d80657cf43ee1ea70ebab..c52e6bd0c5c70c4aaedf39419945922095ddc1ad 100644 (file)
@@ -843,14 +843,16 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
 LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
   // The index must always be an integer, which is not an aggregate.  Emit it.
   llvm::Value *Idx = EmitScalarExpr(E->getIdx());
-  
+  QualType IdxTy  = E->getIdx()->getType();
+  bool IdxSigned = IdxTy->isSignedIntegerType();
+
   // If the base is a vector type, then we are forming a vector element lvalue
   // with this subscript.
   if (E->getBase()->getType()->isVectorType()) {
     // Emit the vector as an lvalue to get its address.
     LValue LHS = EmitLValue(E->getBase());
     assert(LHS.isSimple() && "Can only subscript lvalue vectors here!");
-    // FIXME: This should properly sign/zero/extend or truncate Idx to i32.
+    Idx = Builder.CreateIntCast(Idx, llvm::Type::Int32Ty, IdxSigned, "vidx");
     return LValue::MakeVectorElt(LHS.getAddress(), Idx,
       E->getBase()->getType().getCVRQualifiers());
   }
@@ -859,8 +861,6 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
   llvm::Value *Base = EmitScalarExpr(E->getBase());
   
   // Extend or truncate the index type to 32 or 64-bits.
-  QualType IdxTy  = E->getIdx()->getType();
-  bool IdxSigned = IdxTy->isSignedIntegerType();
   unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
   if (IdxBitwidth != LLVMPointerWidth)
     Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth),
index 2e753b42c4d70293c4d39dfd74d2fbb9bc61aaad..1084f6d20b9b600b16e8d7f36b4d92c6be01ae1c 100644 (file)
@@ -11,3 +11,11 @@ __v4hi y = {1,2,3,4};
 
 typedef int vty __attribute((vector_size(16)));
 int a() { vty b; return b[2LL]; }
+
+// PR4339
+typedef float vec4 __attribute__((vector_size(16)));
+
+void vac ( vec4* a, char b, float c )
+{
+       (*a)[b] = c;
+}