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

Fix unit tests for core.internal.convert and rt.util.typeinfo #768

Open
wants to merge 3 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions gcc/d/expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ along with GCC; see the file COPYING3. If not see

#include "d-tree.h"

/* Helper function for floating point identity comparison. Compare
only well-defined bits, ignore padding (e.g. for X86 80bit real). */

static tree build_float_identity (tree_code code, tree t1, tree t2)
{
/* For floating-point values, identity is defined as the bits in the
operands being identical. */
tree tmemcmp = builtin_decl_explicit (BUILT_IN_MEMCMP);
tree size = size_int (TYPE_PRECISION (TREE_TYPE (t1)) / BITS_PER_UNIT);

tree result = build_call_expr (tmemcmp, 3, build_address (t1),
build_address (t2), size);
return build_boolop (code, result, integer_zero_node);
}

/* Implements the visitor interface to build the GCC trees of all Expression
AST classes emitted from the D Front-end.
Expand Down Expand Up @@ -275,19 +289,23 @@ class ExprVisitor : public Visitor
this->result_ = d_convert (build_ctype (e->type),
build_boolop (code, t1, t2));
}
else if (tb1->isfloating () && tb1->ty != Tvector)
else if (tb1->iscomplex () && tb1->ty != Tvector)
{
/* For floating-point values, identity is defined as the bits in the
operands being identical. */
tree t1 = d_save_expr (build_expr (e->e1));
tree t2 = d_save_expr (build_expr (e->e2));

tree tmemcmp = builtin_decl_explicit (BUILT_IN_MEMCMP);
tree size = size_int (TYPE_PRECISION (TREE_TYPE (t1)) / BITS_PER_UNIT);
tree e1 = d_save_expr (build_expr (e->e1));
tree e2 = d_save_expr (build_expr (e->e2));
tree req = build_float_identity (code, real_part (e1), real_part (e2));
tree ieq = build_float_identity (code, imaginary_part (e1), imaginary_part (e2));

tree result = build_call_expr (tmemcmp, 3, build_address (t1),
build_address (t2), size);
this->result_ = build_boolop (code, result, integer_zero_node);
if (code == EQ_EXPR)
this->result_ = build_boolop (TRUTH_ANDIF_EXPR, req, ieq);
else
this->result_ = build_boolop (TRUTH_ORIF_EXPR, req, ieq);
}
else if (tb1->isfloating () && tb1->ty != Tvector)
{
tree e1 = d_save_expr (build_expr (e->e1));
tree e2 = d_save_expr (build_expr (e->e2));
this->result_ = build_float_identity (code, e1, e2);
}
else if (tb1->ty == Tstruct)
{
Expand Down
22 changes: 22 additions & 0 deletions gcc/testsuite/gdc.dg/runnable.d
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,27 @@ void test286()
assert(0);
}

/******************************************/
// https://bugzilla.gdcproject.org/show_bug.cgi?id=309

void test309()
{
creal f1 = +0.0 + 0.0i;
creal f2 = +0.0 - 0.0i;
creal f3 = -0.0 + 0.0i;
creal f4 = +0.0 + 0.0i;

assert(f1 !is f2);
assert(f1 !is f3);
assert(f2 !is f3);
assert(f1 is f4);

assert(!(f1 is f2));
assert(!(f1 is f3));
assert(!(f2 is f3));
assert(!(f1 !is f4));
}

/******************************************/

void main()
Expand Down Expand Up @@ -1570,6 +1591,7 @@ void main()
test273();
test285();
test286();
test309();

printf("Success!\n");
}
12 changes: 2 additions & 10 deletions libphobos/libdruntime/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,8 @@ ALL_DRUNTIME_COMPILE_DSOURCES += $(DRUNTIME_DSOURCES_GENERATED)

ALL_DRUNTIME_SOURCES = $(ALL_DRUNTIME_COMPILE_DSOURCES) $(DRUNTIME_CSOURCES) \
$(DRUNTIME_SSOURCES)
REAL_DRUNTIME_TEST_LOBJECTS = $(ALL_DRUNTIME_COMPILE_DSOURCES:.d=.t.lo)
REAL_DRUNTIME_TEST_OBJECTS = $(ALL_DRUNTIME_COMPILE_DSOURCES:.d=.t.o)
# Workaround issue #
DRUNTIME_TEST_OBJECTS = $(filter-out rt/util/typeinfo.t.o \
core/internal/convert.t.o, $(REAL_DRUNTIME_TEST_OBJECTS)) \
rt/util/typeinfo.o core/internal/convert.o

DRUNTIME_TEST_LOBJECTS = $(filter-out rt/util/typeinfo.t.lo \
core/internal/convert.t.lo, $(REAL_DRUNTIME_TEST_LOBJECTS)) \
rt/util/typeinfo.lo core/internal/convert.lo
DRUNTIME_TEST_LOBJECTS = $(ALL_DRUNTIME_COMPILE_DSOURCES:.d=.t.lo)
DRUNTIME_TEST_OBJECTS = $(ALL_DRUNTIME_COMPILE_DSOURCES:.d=.t.o)


# Main library build definitions
Expand Down
12 changes: 2 additions & 10 deletions libphobos/libdruntime/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -658,16 +658,8 @@ ALL_DRUNTIME_COMPILE_DSOURCES = $(DRUNTIME_DSOURCES) $(am__append_1) \
ALL_DRUNTIME_SOURCES = $(ALL_DRUNTIME_COMPILE_DSOURCES) $(DRUNTIME_CSOURCES) \
$(DRUNTIME_SSOURCES)

REAL_DRUNTIME_TEST_LOBJECTS = $(ALL_DRUNTIME_COMPILE_DSOURCES:.d=.t.lo)
REAL_DRUNTIME_TEST_OBJECTS = $(ALL_DRUNTIME_COMPILE_DSOURCES:.d=.t.o)
# Workaround issue #
DRUNTIME_TEST_OBJECTS = $(filter-out rt/util/typeinfo.t.o \
core/internal/convert.t.o, $(REAL_DRUNTIME_TEST_OBJECTS)) \
rt/util/typeinfo.o core/internal/convert.o

DRUNTIME_TEST_LOBJECTS = $(filter-out rt/util/typeinfo.t.lo \
core/internal/convert.t.lo, $(REAL_DRUNTIME_TEST_LOBJECTS)) \
rt/util/typeinfo.lo core/internal/convert.lo
DRUNTIME_TEST_LOBJECTS = $(ALL_DRUNTIME_COMPILE_DSOURCES:.d=.t.lo)
DRUNTIME_TEST_OBJECTS = $(ALL_DRUNTIME_COMPILE_DSOURCES:.d=.t.o)

@ENABLE_SHARED_TRUE@check_LTLIBRARIES = libgdruntime_t.la
toolexeclib_LTLIBRARIES = libgdruntime.la
Expand Down
Loading