Skip to content

Commit

Permalink
fix 64 bit sign extension bug
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Mar 28, 2011
1 parent e764b39 commit 5c746ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/backend/cod4.c
Expand Up @@ -493,8 +493,8 @@ code *cdeq(elem *e,regm_t *pretregs)
cl = movregconst(cl,cs.Irm & 7,p[1],0);
}
}
else if (I64 && sz == 8 && *p != *(unsigned *)p)
{
else if (I64 && sz == 8 && *p >= 0x80000000)
{ // Use 64 bit MOV, as the 32 bit one gets sign extended
// MOV reg,imm64
// MOV EA,reg
regm_t rregm = allregs & ~idxregm(&cs);
Expand Down
18 changes: 16 additions & 2 deletions test/runnable/literal.d
Expand Up @@ -30,7 +30,7 @@ int dotype(uint x) { return T_uint; }
int dotype(long x) { return T_long; }
int dotype(ulong x) { return T_ulong; }

int main()
void test1()
{
/*
* 0x7FFF 077777 32767
Expand Down Expand Up @@ -209,7 +209,21 @@ int main()
assert(dotype(9223372036854775807uL) == T_ulong);
assert(dotype(9223372036854775808uL) == T_ulong);
assert(dotype(18446744073709551615uL) == T_ulong);
}

void test2()
{
ulong[] a = [ 2_463_534_242UL ];

foreach(e; a)
assert(e == 2_463_534_242UL);
}

int main()
{
test1();
test2();

printf("Success\n");
return EXIT_SUCCESS;
return 0;
}

1 comment on commit 5c746ca

@WalterBright
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to braddr for tracking this one down and providing the patches.

Please sign in to comment.