Bug 8624 – Regression: CTFE: long comparisons completely broken

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-05T19:17:00Z
Last change time
2015-06-09T05:11:43Z
Keywords
CTFE, wrong-code
Assigned to
nobody
Creator
ellery-newcomer

Comments

Comment #0 by ellery-newcomer — 2012-09-05T19:17:47Z
dmd 2.060 x64 linux. code: int generateHashAndValueArrays() { import std.string; assert(H("a") != H("A"), xformat("%x == %x", H("a"), H("A"))); return 1; } enum s = (generateHashAndValueArrays()); ulong H(string str) { if(str[0] == 'a') return 0x6161636772; return 0x4161636772; } fireworks: HtmlEntities.d(4): Error: ['6','1','6','1','6','3','6','7','7','2',' ','=','=',' ','4','1','6','1','6','3','6','7','7','2'][0LU..24LU] ehh, HtmlEntities.d(4): Error: "6161636772 == 4161636772"
Comment #1 by clugdbug — 2012-09-06T23:44:46Z
This is one of the worst bugs of all time. I can't believe this slipped through the test suite. The top 32 bits of longs is entirely ignored in CTFE == and != comparisons. Reduced test case: ==================== int bug8624() { long m = 0x1_0000_0000; assert(m != 0); return 1; } static assert( bug8624() ); ==================== It's a typo in interpret.c, which results in an implicit conversion from long to int. This might be worth an emergency release.
Comment #2 by braddr — 2012-09-07T17:41:58Z
In which version did it last work correctly?
Comment #3 by bugzilla — 2012-09-08T13:14:27Z
(In reply to comment #1) > It's a typo in interpret.c, which results in an implicit conversion from long > to int. > This might be worth an emergency release. Please post pull request, and I'll get it pulled at least.
Comment #4 by github-bugzilla — 2012-09-10T01:33:07Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/9a732a03c9f671a7c45a9f7dbe485a0b3489f997 Fix issue 8624 Regression: CTFE: long comparisons completely broken An implicit narrowing cast from long to int. Catastrophic. https://github.com/D-Programming-Language/dmd/commit/475178efa63597d6d55a074406678ab92f1075ed Merge pull request #1112 from donc/regression8624ctfe Fix issue 8624 Regression: CTFE: long comparisons completely broken