[cfe-commits] r43301 - in /cfe/trunk: CodeGen/CGExprScalar.cpp test/CodeGen/ocu-vector.c
Devang Patel
dpatel at apple.com
Wed Oct 24 11:05:49 PDT 2007
Author: dpatel
Date: Wed Oct 24 13:05:48 2007
New Revision: 43301
URL: http://llvm.org/viewvc/llvm-project?rev=43301&view=rev
Log:
Handle non-constant initializers.
Modified:
cfe/trunk/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/ocu-vector.c
Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=43301&r1=43300&r2=43301&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Wed Oct 24 13:05:48 2007
@@ -121,14 +121,15 @@
Value *VisitPreDefinedExpr(Expr *E) { return EmitLValue(E).getAddress(); }
Value *VisitInitListExpr(InitListExpr *E) {
- std::vector<llvm::Constant *> Elements;
unsigned N = E->getNumInits();
+ QualType T = E->getInit(0)->getType();
+ Value *V = llvm::UndefValue::get(llvm::VectorType::get(ConvertType(T), N));
for (unsigned i = 0; i < N; ++i) {
- Value *V = Visit(E->getInit(i));
- llvm::Constant * C = cast<llvm::Constant>(V);
- Elements.push_back(C);
+ Value *NewV = Visit(E->getInit(i));
+ Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, i);
+ V = Builder.CreateInsertElement(V, NewV, Idx);
}
- return llvm::ConstantVector::get(Elements);
+ return V;
}
Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
Modified: cfe/trunk/test/CodeGen/ocu-vector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ocu-vector.c?rev=43301&r1=43300&r2=43301&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/ocu-vector.c (original)
+++ cfe/trunk/test/CodeGen/ocu-vector.c Wed Oct 24 13:05:48 2007
@@ -22,3 +22,14 @@
vec2.yx = vec2; // reverse
}
+static void test3(float4 *out) {
+ *out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f });
+}
+
+static void test4(float4 *out) {
+ float a = 1.0f;
+ float b = 2.0f;
+ float c = 3.0f;
+ float d = 4.0f;
+ *out = ((float4) {a,b,c,d});
+}
More information about the cfe-commits
mailing list