Bug 10682 – [ICE](cgcod.c line 1561) with ^^ operator and ulong

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-07-20T11:06:00Z
Last change time
2013-09-12T04:27:15Z
Keywords
ice, pull
Assigned to
yebblies
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-07-20T11:06:06Z
void main() { ulong x = 1; ulong y = 2 ^^ x; } DMD 2.064alpha gives: Internal error: backend\cgcod.c 1561
Comment #1 by hsteoh — 2013-08-30T11:45:05Z
Seems to have been fixed in git HEAD (46e495b), tested on Linux/64bit. Could you verify if it's also fixed on Windows?
Comment #2 by hsteoh — 2013-08-30T12:00:28Z
In fact, all versions of dmd from 2.063.2 up to commit 50a484a60cc3794281a98c51346fc0dfacfc0f24 (Fix Issue 5943 - Power expression optimisation: 2^^unsigned ==> 1<<unsigned) displayed an error message of the form: test.d(3): Error: must import std.math to use ^^ operator and all versions thereafter (that I tested) simply compiles it with no error. Maybe it was an intermittent failure that was quickly fixed, or maybe it only happens with specific compiler flags, or maybe it's Windows-specific?
Comment #3 by bearophile_hugs — 2013-08-30T13:36:04Z
(In reply to comment #1) > Seems to have been fixed in git HEAD (46e495b), tested on Linux/64bit. Could > you verify if it's also fixed on Windows? I see the same error (Windows 32, no compilation switches): Internal error: backend\cgcod.c 1561
Comment #4 by hsteoh — 2013-08-30T13:48:35Z
OK, must be a Windows-specific problem then. Sorry, can't help you there (don't have a Windows dev machine). :-(
Comment #5 by yebblies — 2013-09-06T07:08:45Z
A quick look shows that: void main() { ulong x = 1; ulong y = 2 ^^ x; } Is expanded to: ulong x = 1LU; ulong y = 1LU << x * 1LU; return 0; while void main() { ulong x = 1LU; ulong y = 1LU << x * 1LU; } is expanded to ulong x = 1LU; ulong y = 1LU << cast(int)(x * 1LU); return 0; And it seems the register allocator (or something) can't handle a ulong shift amount. Usually, a cast to int is inserted during semantic on the ShlExp, but as this one was created during optimize, it never happened. https://github.com/D-Programming-Language/dmd/pull/2528
Comment #6 by github-bugzilla — 2013-09-12T04:26:48Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d656898cd69ee242a56bf1d0300a7862338674ea Fix Issue 10682 - [ICE](cgcod.c line 1561) with ^^ operator The backend can't handle a shift expression with a ulong rhs, so simulate the cast that is usually added by semantic. https://github.com/D-Programming-Language/dmd/commit/6a90c4df6a25640e745a0c4aa95defb5a084f8ce Merge pull request #2528 from yebblies/issue10682 Fix Issue 10682 - [ICE](cgcod.c line 1561) with ^^ operator