mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-06 02:45:25 +03:00
Use type gep in initializeArrayLiteral
(#4092)
This commit is contained in:
parent
3c2b8906b0
commit
f2155c6dd9
3 changed files with 8 additions and 6 deletions
|
@ -588,7 +588,8 @@ llvm::Constant *arrayLiteralToConst(IRState *p, ArrayLiteralExp *ale) {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void initializeArrayLiteral(IRState *p, ArrayLiteralExp *ale, LLValue *dstMem) {
|
void initializeArrayLiteral(IRState *p, ArrayLiteralExp *ale,
|
||||||
|
LLValue *dstMem, LLType *dstType) {
|
||||||
size_t elemCount = ale->elements->length;
|
size_t elemCount = ale->elements->length;
|
||||||
|
|
||||||
// Don't try to write nothing to a zero-element array, we might represent it
|
// Don't try to write nothing to a zero-element array, we might represent it
|
||||||
|
@ -618,7 +619,7 @@ void initializeArrayLiteral(IRState *p, ArrayLiteralExp *ale, LLValue *dstMem) {
|
||||||
for (size_t i = 0; i < elemCount; ++i) {
|
for (size_t i = 0; i < elemCount; ++i) {
|
||||||
Expression *rhsExp = indexArrayLiteral(ale, i);
|
Expression *rhsExp = indexArrayLiteral(ale, i);
|
||||||
|
|
||||||
LLValue *lhsPtr = DtoGEP(dstMem, 0, i, "", p->scopebb());
|
LLValue *lhsPtr = DtoGEP(dstType, dstMem, 0, i, "", p->scopebb());
|
||||||
DLValue lhs(rhsExp->type, DtoBitCast(lhsPtr, DtoPtrToType(rhsExp->type)));
|
DLValue lhs(rhsExp->type, DtoBitCast(lhsPtr, DtoPtrToType(rhsExp->type)));
|
||||||
|
|
||||||
// try to construct it in-place
|
// try to construct it in-place
|
||||||
|
|
|
@ -53,7 +53,8 @@ llvm::Constant *arrayLiteralToConst(IRState *p, ArrayLiteralExp *ale);
|
||||||
/// Initializes a chunk of memory with the contents of an array literal.
|
/// Initializes a chunk of memory with the contents of an array literal.
|
||||||
///
|
///
|
||||||
/// dstMem is expected to be a pointer to the array allocation.
|
/// dstMem is expected to be a pointer to the array allocation.
|
||||||
void initializeArrayLiteral(IRState *p, ArrayLiteralExp *ale, LLValue *dstMem);
|
void initializeArrayLiteral(IRState *p, ArrayLiteralExp *ale,
|
||||||
|
LLValue *dstMem, LLType *dstType);
|
||||||
|
|
||||||
void DtoArrayAssign(const Loc &loc, DValue *lhs, DValue *rhs, EXP op,
|
void DtoArrayAssign(const Loc &loc, DValue *lhs, DValue *rhs, EXP op,
|
||||||
bool canSkipPostblit);
|
bool canSkipPostblit);
|
||||||
|
|
|
@ -2210,13 +2210,13 @@ public:
|
||||||
e->loc, arrayType,
|
e->loc, arrayType,
|
||||||
new DConstValue(Type::tsize_t, DtoConstSize_t(len)), false);
|
new DConstValue(Type::tsize_t, DtoConstSize_t(len)), false);
|
||||||
initializeArrayLiteral(
|
initializeArrayLiteral(
|
||||||
p, e, DtoBitCast(dynSlice->getPtr(), getPtrToType(llStoType)));
|
p, e, DtoBitCast(dynSlice->getPtr(), getPtrToType(llStoType)), llStoType);
|
||||||
result = dynSlice;
|
result = dynSlice;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
llvm::Value *storage =
|
llvm::Value *storage =
|
||||||
DtoRawAlloca(llStoType, DtoAlignment(e->type), "arrayliteral");
|
DtoRawAlloca(llStoType, DtoAlignment(e->type), "arrayliteral");
|
||||||
initializeArrayLiteral(p, e, storage);
|
initializeArrayLiteral(p, e, storage, llStoType);
|
||||||
if (arrayType->ty == TY::Tsarray) {
|
if (arrayType->ty == TY::Tsarray) {
|
||||||
result = new DLValue(e->type, storage);
|
result = new DLValue(e->type, storage);
|
||||||
} else if (arrayType->ty == TY::Tpointer) {
|
} else if (arrayType->ty == TY::Tpointer) {
|
||||||
|
@ -2815,7 +2815,7 @@ bool toInPlaceConstruction(DLValue *lhs, Expression *rhs) {
|
||||||
else if (auto al = rhs->isArrayLiteralExp()) {
|
else if (auto al = rhs->isArrayLiteralExp()) {
|
||||||
if (lhs->type->toBasetype()->ty == TY::Tsarray) {
|
if (lhs->type->toBasetype()->ty == TY::Tsarray) {
|
||||||
Logger::println("success, in-place-constructing array literal");
|
Logger::println("success, in-place-constructing array literal");
|
||||||
initializeArrayLiteral(gIR, al, DtoLVal(lhs));
|
initializeArrayLiteral(gIR, al, DtoLVal(lhs), DtoMemType(lhs->type));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue