Skip to content

Commit

Permalink
Merge pull request #397 from dawgfoto/master
Browse files Browse the repository at this point in the history
check that block displacement fits into immediate
  • Loading branch information
WalterBright committed Sep 23, 2011
2 parents bcc14a3 + c5e22f5 commit 243fd91
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/backend/cc.h
Expand Up @@ -212,7 +212,7 @@ typedef struct Srcpos
#endif
#if MARS
const char *Sfilename;
#define srcpos_name(p) ((p).SFname)
#define srcpos_name(p) ((p)->Sfilename)
#endif
#if M_UNIX
short Sfilnum; // file number
Expand Down
19 changes: 16 additions & 3 deletions src/backend/cod3.c
Expand Up @@ -5419,7 +5419,6 @@ STATIC void do64bit(enum FL fl,union evc *uev,int flags)
{ char *p;
symbol *s;
targ_size_t ad;
long tmp;

assert(I64);
switch (fl)
Expand Down Expand Up @@ -5505,7 +5504,6 @@ STATIC void do32bit(enum FL fl,union evc *uev,int flags, targ_size_t val)
{ char *p;
symbol *s;
targ_size_t ad;
long tmp;

//printf("do32bit(flags = x%x)\n", flags);
switch (fl)
Expand Down Expand Up @@ -5670,6 +5668,12 @@ STATIC void do16bit(enum FL fl,union evc *uev,int flags)
break;
case FLblock: /* displacement to another block */
ad = uev->Vblock->Boffset - OFFSET() - 2;
#ifdef DEBUG
{
targ_ptrdiff_t delta = uev->Vblock->Boffset - OFFSET() - 2;
assert((signed short)delta == delta);
}
#endif
L1:
GENP(2,&ad); // displacement
return;
Expand All @@ -5690,14 +5694,23 @@ STATIC void do16bit(enum FL fl,union evc *uev,int flags)

STATIC void do8bit(enum FL fl,union evc *uev)
{ char c;
targ_ptrdiff_t delta;

switch (fl)
{
case FLconst:
c = uev->Vuns;
break;
case FLblock:
c = uev->Vblock->Boffset - OFFSET() - 1;
delta = uev->Vblock->Boffset - OFFSET() - 1;
if ((signed char)delta != delta)
{
if (uev->Vblock->Bsrcpos.Slinnum)
fprintf(stderr, "%s(%d): ", uev->Vblock->Bsrcpos.Sfilename, uev->Vblock->Bsrcpos.Slinnum);
fprintf(stderr, "block displacement of %lld exceeds the maximum offset of -128 to 127.\n", (long long)delta);
err_exit();
}
c = delta;
#ifdef DEBUG
assert(uev->Vblock->Boffset > OFFSET() || c != 0x7F);
#endif
Expand Down
15 changes: 15 additions & 0 deletions test/fail_compilation/fail353.d
@@ -0,0 +1,15 @@
void foo()
{
enum NOP = 0x9090_9090_9090_9090;

asm
{
L1:
dq NOP,NOP,NOP,NOP; // 32
dq NOP,NOP,NOP,NOP; // 64
dq NOP,NOP,NOP,NOP; // 96
dq NOP,NOP,NOP,NOP; // 128
// unnoticed signed underflow of rel8 with DMD2.056
loop L1;
}
}

0 comments on commit 243fd91

Please sign in to comment.