Bug 17087 – [REG2.072] Wrong generated with cfloat and creal when casting from int

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-01-13T18:52:00Z
Last change time
2017-01-24T11:54:57Z
Keywords
SIMD, wrong-code
Assigned to
nobody
Creator
petar.p.kirov

Comments

Comment #0 by petar.p.kirov — 2017-01-13T18:52:59Z
//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 by bitter.taste — 2017-01-13T21:54:09Z
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 by bugzilla — 2017-01-17T08:11:16Z
Comment #3 by bugzilla — 2017-01-17T08:29:02Z
Comment #4 by github-bugzilla — 2017-01-18T00:34:04Z
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 by github-bugzilla — 2017-01-18T13:53:02Z
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 by github-bugzilla — 2017-01-24T11:54:57Z
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