зеркало из https://github.com/microsoft/clang-1.git
Handle non-constant initializers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43301 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
35634f5ed6
Коммит
a83cc33195
|
@ -121,14 +121,15 @@ public:
|
|||
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) {
|
||||
|
|
|
@ -22,3 +22,14 @@ static void test2() {
|
|||
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});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче