Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
Bug 57 - Comparing small structs fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed May 28, 2013
1 parent ee730a1 commit 58f0382
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
5 changes: 5 additions & 0 deletions gcc/d/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
* d-builtins.c(gcc_d_backend_init): Rename to d_backend_init.
(gcc_d_backend_term): Rename to d_backend_term.

* d-elem.cc(AssignExp::toElem): Remove handling of fillHoles, use
memset to implement (struct = 0).
(StructLiteralExp::toElem): Handle fillHoles here, creating a
temporary var that is zero init'd with memset and returned.

2013-05-27 Iain Buclaw <ibuclaw@gdcproject.org>

* d-codegen.cc(IRState::localVar): Rename to build_local_var.
Expand Down
77 changes: 44 additions & 33 deletions gcc/d/d-elem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -935,51 +935,48 @@ AssignExp::toElem (IRState *irs)
if (op == TOKconstruct)
{
tree lhs = e1->toElem (irs);
tree rhs = convert_for_assignment (e2->toElem (irs), e2->type, e1->type);
Type *tb1 = e1->type->toBasetype();
tree result = NULL_TREE;

if (e1->op == TOKvar)
if (tb1->ty == Tstruct && e2->op == TOKint64)
{
Declaration *decl = ((VarExp *) e1)->var;
// Look for reference initializations
if (decl->storage_class & (STCout | STCref))
StructDeclaration *sd = ((TypeStruct *) tb1)->sym;

// D Front end uses IntegerExp (0) to mean zero-init a structure.
// Use memset to fill struct.
result = d_build_call_nary (builtin_decl_explicit (BUILT_IN_MEMSET), 3,
build_address (lhs), size_zero_node,
size_int (sd->structsize));


// Maybe set-up hidden pointer to outer scope context.
if (sd->isNested())
{
// Want reference to lhs, not indirect ref.
lhs = TREE_OPERAND (lhs, 0);
rhs = build_address (rhs);
tree vthis_field = sd->vthis->toSymbol()->Stree;
tree vthis_value = irs->getVThis (sd, this);

tree vthis_exp = modify_expr (component_ref (lhs, vthis_field), vthis_value);
result = maybe_compound_expr (result, vthis_exp);
}
}
result = modify_expr (type->toCtype(), lhs, rhs);

if (tb1->ty == Tstruct)
else
{
if (e2->op == TOKstructliteral)
{
// Initialize all alignment 'holes' to zero.
StructLiteralExp *sle = ((StructLiteralExp *) e2);
if (sle->fillHoles)
{
unsigned sz = sle->type->size();
tree init = d_build_call_nary (builtin_decl_explicit (BUILT_IN_MEMSET), 3,
build_address (lhs), size_zero_node, size_int (sz));
result = maybe_compound_expr (init, result);
}
}
else if (e2->op == TOKint64)
tree rhs = convert_for_assignment (e2->toElem (irs), e2->type, e1->type);

if (e1->op == TOKvar)
{
// Maybe set-up hidden pointer to outer scope context.
StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
if (sd->isNested())
Declaration *decl = ((VarExp *) e1)->var;
// Look for reference initializations
if (decl->storage_class & (STCout | STCref))
{
tree vthis_field = sd->vthis->toSymbol()->Stree;
tree vthis_value = irs->getVThis (sd, this);

tree vthis_exp = modify_expr (component_ref (lhs, vthis_field), vthis_value);
result = maybe_compound_expr (result, vthis_exp);
// Want reference to lhs, not indirect ref.
lhs = TREE_OPERAND (lhs, 0);
rhs = build_address (rhs);
}
}
result = modify_expr (type->toCtype(), lhs, rhs);
}

return result;
}

Expand Down Expand Up @@ -2255,6 +2252,7 @@ StructLiteralExp::toElem (IRState *irs)
// %% Could use memset if is zero init...
exp_tree = build_local_var (fld_type->toCtype());
Type *etype = fld_type;

while (etype->ty == Tsarray)
etype = etype->nextOf();

Expand Down Expand Up @@ -2301,7 +2299,20 @@ StructLiteralExp::toElem (IRState *irs)
}

tree ctor = build_constructor (type->toCtype(), ce);
return ctor;
tree var = build_local_var (TREE_TYPE (ctor));
tree init = NULL_TREE;

if (fillHoles)
{
// Initialize all alignment 'holes' to zero.
init = d_build_call_nary (builtin_decl_explicit (BUILT_IN_MEMSET), 3,
build_address (var), size_zero_node,
size_int (sd->structsize));
}

init = maybe_compound_expr (init, modify_expr (var, ctor));

return compound_expr (init, var);
}

elem *
Expand Down

0 comments on commit 58f0382

Please sign in to comment.