D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17087 - [REG2.072] Wrong generated with cfloat and creal when casting from int
Summary: [REG2.072] Wrong generated with cfloat and creal when casting from int
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: SIMD, wrong-code
Depends on:
Blocks:
 
Reported: 2017-01-13 18:52 UTC by ZombineDev
Modified: 2017-01-24 11:54 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ZombineDev 2017-01-13 18:52:59 UTC
//Minimal test case
void main()
{
    cfloat toComplex(int x) { return cast(cfloat)x; }
    auto a = toComplex(1);
    auto b = cast(creal)1;
    assert (a == b);
}


Output:
core.exception.AssertError@/tmp/test.d(6): Assertion failure


//Longer test case
D toComplex(D, S)(S val)
{
    return cast(D) val;
}

alias Seq(T...) = T;

enum isComplex(T) = is(T == cfloat) || is(T == cdouble) || is(T == creal);

void main()
{
    bool hasErrors;

    foreach (OriginalType; Seq!(byte, short, int, long, float, double, real, cfloat, cdouble, creal))
    foreach (DestType; Seq!(byte, short, int, long, float, double, real, cfloat, cdouble, creal))
    {
        import std.stdio;

        static if (isComplex!OriginalType)
           enum orig = OriginalType(1 + 0i);
        else
            enum orig = OriginalType(1);

        auto a = toComplex!DestType(orig);
        auto b = cast(DestType)orig;

        if (orig != a)
        {
            hasErrors = true;
            "Error: orig != a when converting from %s to %s {orig(%s) != a(%s)}"
                .writefln(OriginalType.stringof, DestType.stringof, orig, a, b);
        }

        if (orig != b)
        {
            hasErrors = true;
            "Error: orig != b when converting from %s to %s {orig(%s) != b(%s)}"
                .writefln(OriginalType.stringof, DestType.stringof, orig, a, b);
        }

        if (a != b)
        {
            hasErrors = true;
            "Error: a != b when converting from %s to %s {orig(%s) a(%s) != b(%s)}"
                .writefln(OriginalType.stringof, DestType.stringof, orig, a, b);
        }
    }

    !hasErrors || assert(0);
}

Output:
Error: orig != a when converting from byte to cfloat {orig(1) != a(0+0i)}
Error: a != b when converting from byte to cfloat {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from byte to creal {orig(1) != a(0+0i)}
Error: a != b when converting from byte to creal {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from short to cfloat {orig(1) != a(0+0i)}
Error: a != b when converting from short to cfloat {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from short to creal {orig(1) != a(0+0i)}
Error: a != b when converting from short to creal {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from int to cfloat {orig(1) != a(0+0i)}
Error: a != b when converting from int to cfloat {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from int to creal {orig(1) != a(0+0i)}
Error: a != b when converting from int to creal {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from long to cfloat {orig(1) != a(0+0i)}
Error: a != b when converting from long to cfloat {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from long to creal {orig(1) != a(0+0i)}
Error: a != b when converting from long to creal {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from double to cfloat {orig(1) != a(0+0i)}
Error: a != b when converting from double to cfloat {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from double to creal {orig(1) != a(0+0i)}
Error: a != b when converting from double to creal {orig(1) a(0+0i) != b(1+0i)}
Error: orig != a when converting from cfloat to double {orig(1+0i) != a(1)}
Error: orig != b when converting from cfloat to double {orig(1+0i) != b(1)}
Error: orig != a when converting from cdouble to byte {orig(1+0i) != a(1)}
Error: orig != b when converting from cdouble to byte {orig(1+0i) != b(1)}
Error: orig != a when converting from cdouble to short {orig(1+0i) != a(1)}
Error: orig != b when converting from cdouble to short {orig(1+0i) != b(1)}
Error: orig != a when converting from cdouble to int {orig(1+0i) != a(1)}
Error: orig != b when converting from cdouble to int {orig(1+0i) != b(1)}
Error: orig != a when converting from cdouble to long {orig(1+0i) != a(1)}
Error: orig != b when converting from cdouble to long {orig(1+0i) != b(1)}
Error: orig != a when converting from cdouble to float {orig(1+0i) != a(1)}
Error: orig != b when converting from cdouble to float {orig(1+0i) != b(1)}
Error: orig != a when converting from cdouble to double {orig(1+0i) != a(1)}
Error: orig != b when converting from cdouble to double {orig(1+0i) != b(1)}
core.exception.AssertError@/tmp/test.d(49): Assertion failure
Comment 1 Citrus 2017-01-13 21:54:09 UTC
Introduced by https://github.com/dlang/dmd/pull/6238
cdorth -> orthxmm is the culprit, changing it back to orth87 makes the (first) test case succeed.
Comment 2 Walter Bright 2017-01-17 08:11:16 UTC
https://github.com/dlang/dmd/pull/6459
Comment 3 Walter Bright 2017-01-17 08:29:02 UTC
https://github.com/dlang/dmd/pull/6460/
Comment 4 github-bugzilla 2017-01-18 00:34:04 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/7cf3c764da8b85f9d7054b0895384f3a86ce2684
fix Issue 17087 - [REG2.072] Wrong generated with cfloat and creal when casting from int

https://github.com/dlang/dmd/commit/3c0b76985ea1cc4c32a213975a4b7702bcb9d90c
Merge pull request #6460 from WalterBright/fix17087

fix Issue 17087 - [REG2.072] Wrong generated with cfloat and creal wh…
Comment 5 github-bugzilla 2017-01-18 13:53:02 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/7cf3c764da8b85f9d7054b0895384f3a86ce2684
fix Issue 17087 - [REG2.072] Wrong generated with cfloat and creal when casting from int

https://github.com/dlang/dmd/commit/3c0b76985ea1cc4c32a213975a4b7702bcb9d90c
Merge pull request #6460 from WalterBright/fix17087
Comment 6 github-bugzilla 2017-01-24 11:54:57 UTC
Commits pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/7cf3c764da8b85f9d7054b0895384f3a86ce2684
fix Issue 17087 - [REG2.072] Wrong generated with cfloat and creal when casting from int

https://github.com/dlang/dmd/commit/3c0b76985ea1cc4c32a213975a4b7702bcb9d90c
Merge pull request #6460 from WalterBright/fix17087