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 f7569e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
4 changes: 4 additions & 0 deletions gcc/d/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* 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.
(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
47 changes: 23 additions & 24 deletions gcc/d/d-elem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -952,32 +952,17 @@ AssignExp::toElem (IRState *irs)
}
result = modify_expr (type->toCtype(), lhs, rhs);

if (tb1->ty == Tstruct)
if (e2->op == TOKint64 && tb1->ty == Tstruct)
{
if (e2->op == TOKstructliteral)
// Maybe set-up hidden pointer to outer scope context.
StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
if (sd->isNested())
{
// 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)
{
// Maybe set-up hidden pointer to outer scope context.
StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
if (sd->isNested())
{
tree vthis_field = sd->vthis->toSymbol()->Stree;
tree vthis_value = irs->getVThis (sd, this);
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);
}
tree vthis_exp = modify_expr (component_ref (lhs, vthis_field), vthis_value);
result = maybe_compound_expr (result, vthis_exp);
}
}
return result;
Expand Down Expand Up @@ -2300,8 +2285,22 @@ StructLiteralExp::toElem (IRState *irs)
gcc_assert (sinit == NULL);
}


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 (type->size()));
}

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

return compound_expr (init, var);
}

elem *
Expand Down

0 comments on commit f7569e0

Please sign in to comment.