Make DtoIndexAggregate return a DLValue (#4112)

This commit is contained in:
Nicholas Wilson 2022-09-04 21:34:31 +08:00 committed by GitHub
parent 78c37450d6
commit 7d8638c27a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 13 deletions

View file

@ -1878,7 +1878,7 @@ FuncDeclaration *getParentFunc(Dsymbol *sym) {
return nullptr;
}
LLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
VarDeclaration *vd) {
IF_LOG Logger::println("Indexing aggregate field %s:", vd->toPrettyChars());
LOG_SCOPE;
@ -1924,7 +1924,7 @@ LLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
val = DtoBitCast(val, DtoPtrToType(vd->type));
IF_LOG Logger::cout() << "Value: " << *val << '\n';
return val;
return new DLValue(vd->type, val);
}
unsigned getFieldGEPIndex(AggregateDeclaration *ad, VarDeclaration *vd) {

View file

@ -132,7 +132,7 @@ void findDefaultTarget();
/// Returns a pointer to the given member field of an aggregate.
///
/// 'src' is a pointer to the start of the memory of an 'ad' instance.
LLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
VarDeclaration *vd);
/// Returns the index of a given member variable in the resulting LLVM type of

View file

@ -145,7 +145,7 @@ LLValue *DtoUnpaddedStruct(Type *dty, LLValue *v) {
LLValue *newval = llvm::UndefValue::get(DtoUnpaddedStructType(dty));
for (unsigned i = 0; i < fields.length; i++) {
LLValue *fieldptr = DtoIndexAggregate(v, sty->sym, fields[i]);
LLValue *fieldptr = DtoLVal(DtoIndexAggregate(v, sty->sym, fields[i]));
LLValue *fieldval;
if (fields[i]->type->ty == TY::Tstruct) {
// Nested structs are the only members that can contain padding
@ -165,7 +165,7 @@ void DtoPaddedStruct(Type *dty, LLValue *v, LLValue *lval) {
VarDeclarations &fields = sty->sym->fields;
for (unsigned i = 0; i < fields.length; i++) {
LLValue *fieldptr = DtoIndexAggregate(lval, sty->sym, fields[i]);
LLValue *fieldptr = DtoLVal(DtoIndexAggregate(lval, sty->sym, fields[i]));
LLValue *fieldval = DtoExtractValue(v, i);
if (fields[i]->type->ty == TY::Tstruct) {
// Nested structs are the only members that can contain padding

View file

@ -129,16 +129,16 @@ static void write_struct_literal(Loc loc, LLValue *mem, StructDeclaration *sd,
// get a pointer to this field
assert(!isSpecialRefVar(vd) && "Code not expected to handle special ref "
"vars, although it can easily be made to.");
DLValue field(vd->type, DtoIndexAggregate(mem, sd, vd));
DLValue *field = DtoIndexAggregate(mem, sd, vd);
// initialize the field
if (expr) {
IF_LOG Logger::println("expr = %s", expr->toChars());
// try to construct it in-place
if (!toInPlaceConstruction(&field, expr)) {
DtoAssign(loc, &field, toElem(expr), EXP::blit);
if (!toInPlaceConstruction(field, expr)) {
DtoAssign(loc, field, toElem(expr), EXP::blit);
if (expr->isLvalue())
callPostblit(loc, expr, DtoLVal(&field));
callPostblit(loc, expr, DtoLVal(field));
}
} else {
assert(vd == sd->vthis);
@ -146,7 +146,7 @@ static void write_struct_literal(Loc loc, LLValue *mem, StructDeclaration *sd,
LOG_SCOPE
DImValue val(vd->type,
DtoBitCast(DtoNestedContext(loc, sd), DtoType(vd->type)));
DtoAssign(loc, &field, &val, EXP::blit);
DtoAssign(loc, field, &val, EXP::blit);
}
// Make sure to zero out padding bytes counted as being part of the type in
@ -917,7 +917,7 @@ public:
// Logger::cout() << *DtoType(e1type) << '\n';
if (VarDeclaration *vd = e->var->isVarDeclaration()) {
LLValue *arrptr;
DLValue *arrptr;
// indexing struct pointer
if (e1type->ty == TY::Tpointer) {
assert(e1type->nextOf()->ty == TY::Tstruct);
@ -937,8 +937,9 @@ public:
llvm_unreachable("Unknown DotVarExp type for VarDeclaration.");
}
// Logger::cout() << "mem: " << *arrptr << '\n';
result = new DLValue(e->type, DtoBitCast(arrptr, DtoPtrToType(e->type)));
// Logger::cout() << "mem: " << *DtoLVal(arrptr) << '\n';
result = new DLValue(e->type, DtoBitCast(DtoLVal(arrptr),
DtoPtrToType(e->type)));
} else if (FuncDeclaration *fdecl = e->var->isFuncDeclaration()) {
// This is a bit more convoluted than it would need to be, because it
// has to take templated interface methods into account, for which