If you thought gcc -ansi -pedantic was pedantic, just wait
until you meet clang -fsanitize=undefined.
I think this addresses all the reported "errors", but we'll
need another run to be sure.
all.bash still passes.
Update #5764
Dave, can you please try again?
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/
13334049
#define BGETLE2(bp)\
((bp)->icount<=-2?((bp)->icount+=2,((bp)->ebuf[(bp)->icount-2])|((bp)->ebuf[(bp)->icount-1]<<8)):Bgetle2((bp)))
#define BGETLE4(bp)\
- ((bp)->icount<=-4?((bp)->icount+=4,((bp)->ebuf[(bp)->icount-4])|((bp)->ebuf[(bp)->icount-3]<<8)|((bp)->ebuf[(bp)->icount-2]<<16)|((bp)->ebuf[(bp)->icount-1]<<24)):Bgetle4((bp)))
+ (int)((bp)->icount<=-4?((bp)->icount+=4,((bp)->ebuf[(bp)->icount-4])|((bp)->ebuf[(bp)->icount-3]<<8)|((bp)->ebuf[(bp)->icount-2]<<16)|((uint32)(bp)->ebuf[(bp)->icount-1]<<24)):Bgetle4((bp)))
/*
* These macros put 1-, 2-, and 4-byte integer values by writing the
if(lt->width == 8)
hi = big(0, ~0ULL);
else
- hi = big(0, (1LL<<(l->type->width*8))-1);
+ hi = big(0, (1ULL<<(l->type->width*8))-1);
}else{
- lo = big(~0ULL, -(1LL<<(l->type->width*8-1)));
- hi = big(0, (1LL<<(l->type->width*8-1))-1);
+ lo = big(~0ULL, -(1ULL<<(l->type->width*8-1)));
+ hi = big(0, (1ULL<<(l->type->width*8-1))-1);
}
switch(op){
c += 10-'A';
else
goto bad;
- nn = n*16 + c;
+ nn = (uvlong)n*16 + c;
if(n < 0 && nn >= 0)
goto bad;
n = nn;
lookup(void)
{
Sym *s;
- int32 h;
+ uint32 h;
char *p;
int c, l;
char *r, *w;
if(c >= '0' && c <= '9') {
if(c > '7' && c1 == 3)
break;
- yylval.lval <<= c1;
+ yylval.lval = (uvlong)yylval.lval << c1;
yylval.lval += c - '0';
c = GETC();
continue;
if(c >= 'A' && c <= 'F')
c += 'a' - 'A';
if(c >= 'a' && c <= 'f') {
- yylval.lval <<= c1;
+ yylval.lval = (uvlong)yylval.lval << c1;
yylval.lval += c - 'a' + 10;
c = GETC();
continue;
f = 65536L;
fr = modf(fr*f, &ho);
ieee->l = ho;
- ieee->l <<= 16;
+ ieee->l = (uint32)ieee->l << 16;
ieee->l |= (int32)(fr*f);
}
if(i < 0 || i >= bv->n)
fatal("bvset: index %d is out of bounds with length %d\n", i, bv->n);
- mask = 1 << (i % WORDBITS);
+ mask = 1U << (i % WORDBITS);
bv->b[i / WORDBITS] |= mask;
}
struct Strlit
{
int32 len;
- char s[3]; // variable
+ char s[1]; // variable
};
enum
for(i=0; i<16; i++) {
j = i*4;
- X[i] = p[j] | (p[j+1]<<8) | (p[j+2]<<16) | (p[j+3]<<24);
+ X[i] = p[j] | (p[j+1]<<8) | (p[j+2]<<16) | ((uint32)p[j+3]<<24);
}
// Round 1.
return 0;
}
- v = (vlong)a->a[0];
- v |= (vlong)a->a[1] << Mpscale;
- v |= (vlong)a->a[2] << (Mpscale+Mpscale);
+ v = (uvlong)a->a[0];
+ v |= (uvlong)a->a[1] << Mpscale;
+ v |= (uvlong)a->a[2] << (Mpscale+Mpscale);
if(a->neg)
- v = -v;
+ v = -(uvlong)v;
return v;
}
x = c;
if(x < 0) {
a->neg = 1;
- x = -x;
+ x = -(uvlong)x;
}
a1 = &a->a[0];
uint32
stringhash(char *p)
{
- int32 h;
+ uint32 h;
int c;
h = 0;
h = h*PRIME1 + c;
}
- if(h < 0) {
+ if((int32)h < 0) {
h = -h;
- if(h < 0)
+ if((int32)h < 0)
h = 0;
}
return h;
static int
hashstr(char *name)
{
- int h;
+ uint32 h;
char *cp;
h = 0;
for(cp = name; *cp; h += *cp++)
h *= 1119;
- // not if(h < 0) h = ~h, because gcc 4.3 -O2 miscompiles it.
h &= 0xffffff;
return h;
}
{
Sym *s;
char *p;
- int32 h;
+ uint32 h;
int c;
h = v;
uint32
le32(uchar *b)
{
- return b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24;
+ return b[0] | b[1]<<8 | b[2]<<16 | (uint32)b[3]<<24;
}
uint64
uint32
be32(uchar *b)
{
- return b[0]<<24 | b[1]<<16 | b[2]<<8 | b[3];
+ return (uint32)b[0]<<24 | b[1]<<16 | b[2]<<8 | b[3];
}
uint64
int
hashstr(char *name)
{
- int h;
+ uint32 h;
char *cp;
h = 0;
for(cp = name; *cp; h += *cp++)
h *= 1119;
-
- // the code used to say
- // if(h < 0)
- // h = ~h;
- // but on gcc 4.3 with -O2 on some systems,
- // the if(h < 0) gets compiled away as not possible.
- // use a mask instead, leaving plenty of bits but
- // definitely not the sign bit.
-
return h & 0xfffffff;
}
BGETC(bp);
break;
case D_CONST2:
- BGETLE4(bp); // fall through
+ Bgetle4(bp); // fall through
case D_OREG:
case D_CONST:
case D_BRANCH:
off = ((vlong)l << 32) | (off & 0xFFFFFFFF);
}
if(off < 0)
- off = -off;
+ off = -(uvlong)off;
}
if(a.flags & T_SYM)
a.sym = BGETC(bp);
off = -off;
}
if(a.flags & T_OFFSET2){
- BGETLE4(bp);
+ Bgetle4(bp);
}
if(a.flags & T_SYM)
a.sym = BGETC(bp);
static void
objlookup(int id, char *name, int type, uint sig)
{
- int32 h;
+ uint32 h;
char *cp;
Sym *s;
Symtab *sp;