Skip to content

Commit

Permalink
fix warnings/errors found by static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Nov 13, 2011
1 parent 14d74dd commit 72b6fc9
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/backend/cgelem.c
Expand Up @@ -339,7 +339,7 @@ STATIC elem *fixconvop(elem *e)
elem **pe;
unsigned cop,icop,op;
tym_t tycop,tym,tyme;
static char invconvtab[] =
static unsigned char invconvtab[] =
{
OPbool, // OPb_8
OPs32_d, // OPd_s32
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cgreg.c
Expand Up @@ -48,7 +48,7 @@ static int *weights;

void cgreg_init()
{
if (!config.flags4 & CFG4optimized)
if (!(config.flags4 & CFG4optimized))
return;

// Use calloc() instead because sometimes the alloc is too large
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cod3.c
Expand Up @@ -321,7 +321,7 @@ void cod3_set64()

void cod3_align()
{
static char nops[7] = { 0x90,0x90,0x90,0x90,0x90,0x90,0x90 };
static unsigned char nops[7] = { 0x90,0x90,0x90,0x90,0x90,0x90,0x90 };
unsigned nbytes;
#if OMFOBJ
if (config.flags4 & CFG4speed) // if optimized for speed
Expand Down
32 changes: 16 additions & 16 deletions src/backend/evalu8.c
Expand Up @@ -1664,7 +1664,7 @@ elem * evalu8(elem *e)
case OPgt:
if (!tyfloating(tym))
goto Lnle;
i ^= d1 > d2;
i ^= (int)(d1 > d2);
e->EV.Vint = i;
break;

Expand All @@ -1674,14 +1674,14 @@ elem * evalu8(elem *e)
case OPle:
if (uns)
{
i ^= ((targ_ullong) l1) <= ((targ_ullong) l2);
i ^= (int)(((targ_ullong) l1) <= ((targ_ullong) l2));
}
else
{
if (tyfloating(tym))
i ^= d1 <= d2;
i ^= (int)(d1 <= d2);
else
i ^= l1 <= l2;
i ^= (int)(l1 <= l2);
}
e->EV.Vint = i;
break;
Expand All @@ -1691,7 +1691,7 @@ elem * evalu8(elem *e)
case OPge:
if (!tyfloating(tym))
goto Lnlt;
i ^= d1 >= d2;
i ^= (int)(d1 >= d2);
e->EV.Vint = i;
break;

Expand All @@ -1701,14 +1701,14 @@ elem * evalu8(elem *e)
case OPlt:
if (uns)
{
i ^= ((targ_ullong) l1) < ((targ_ullong) l2);
i ^= (int)(((targ_ullong) l1) < ((targ_ullong) l2));
}
else
{
if (tyfloating(tym))
i ^= d1 < d2;
i ^= (int)(d1 < d2);
else
i ^= l1 < l2;
i ^= (int)(l1 < l2);
}
e->EV.Vint = i;
break;
Expand All @@ -1725,33 +1725,33 @@ elem * evalu8(elem *e)
isnan(e2->EV.Vcfloat.re) || isnan(e2->EV.Vcfloat.im))
i ^= 1;
else
i ^= (e1->EV.Vcfloat.re == e2->EV.Vcfloat.re) &&
(e1->EV.Vcfloat.im == e2->EV.Vcfloat.im);
i ^= (int)((e1->EV.Vcfloat.re == e2->EV.Vcfloat.re) &&
(e1->EV.Vcfloat.im == e2->EV.Vcfloat.im));
break;
case TYcdouble:
if (isnan(e1->EV.Vcdouble.re) || isnan(e1->EV.Vcdouble.im) ||
isnan(e2->EV.Vcdouble.re) || isnan(e2->EV.Vcdouble.im))
i ^= 1;
else
i ^= (e1->EV.Vcdouble.re == e2->EV.Vcdouble.re) &&
(e1->EV.Vcdouble.im == e2->EV.Vcdouble.im);
i ^= (int)((e1->EV.Vcdouble.re == e2->EV.Vcdouble.re) &&
(e1->EV.Vcdouble.im == e2->EV.Vcdouble.im));
break;
case TYcldouble:
if (isnan(e1->EV.Vcldouble.re) || isnan(e1->EV.Vcldouble.im) ||
isnan(e2->EV.Vcldouble.re) || isnan(e2->EV.Vcldouble.im))
i ^= 1;
else
i ^= (e1->EV.Vcldouble.re == e2->EV.Vcldouble.re) &&
(e1->EV.Vcldouble.im == e2->EV.Vcldouble.im);
i ^= (int)((e1->EV.Vcldouble.re == e2->EV.Vcldouble.re) &&
(e1->EV.Vcldouble.im == e2->EV.Vcldouble.im));
break;
default:
i ^= d1 == d2;
i ^= (int)(d1 == d2);
break;
}
//printf("%Lg + %Lgi, %Lg + %Lgi\n", e1->EV.Vcldouble.re, e1->EV.Vcldouble.im, e2->EV.Vcldouble.re, e2->EV.Vcldouble.im);
}
else
i ^= l1 == l2;
i ^= (int)(l1 == l2);
e->EV.Vint = i;
break;

Expand Down
12 changes: 6 additions & 6 deletions src/backend/rtlsym.c
Expand Up @@ -85,12 +85,12 @@ void rtlsym_init()
#endif

#undef SYMBOL_Z
#define SYMBOL_Z(e, fl, saved, n, flags, ty) \
if (ty) rtlsym[RTLSYM_##e]->Stype = ty; \
if (fl != FLfunc) rtlsym[RTLSYM_##e]->Sfl = fl; \
if (flags) rtlsym[RTLSYM_##e]->Sflags = flags; \
if (saved != FREGSAVED) rtlsym[RTLSYM_##e]->Sregsaved = saved; \
strcpy(rtlsym[RTLSYM_##e]->Sident, n); \
#define SYMBOL_Z(e, fl, saved, n, flags, ty) \
if (ty) rtlsym[RTLSYM_##e]->Stype = (ty); \
if ((fl) != FLfunc) rtlsym[RTLSYM_##e]->Sfl = (fl); \
if (flags) rtlsym[RTLSYM_##e]->Sflags = (flags); \
if ((saved) != FREGSAVED) rtlsym[RTLSYM_##e]->Sregsaved = (saved); \
strcpy(rtlsym[RTLSYM_##e]->Sident, (n)); \

RTLSYMS
}
Expand Down
2 changes: 1 addition & 1 deletion src/expression.c
Expand Up @@ -7670,7 +7670,7 @@ Expression *CallExp::semantic(Scope *sc)
if (sc->func->setImpure())
error("pure function '%s' cannot call impure function pointer '%s'", sc->func->toChars(), e1->toChars());
}
if (sc->func && !((TypeFunction *)t1)->trust <= TRUSTsystem)
if (sc->func && ((TypeFunction *)t1)->trust <= TRUSTsystem)
{
if (sc->func->setUnsafe())
error("safe function '%s' cannot call system function pointer '%s'", sc->func->toChars(), e1->toChars());
Expand Down
10 changes: 9 additions & 1 deletion src/iasm.c
Expand Up @@ -52,6 +52,10 @@
#include "code.h"
#include "iasm.h"

#if DMDV1
#undef _DH
#endif

// I32 isn't set correctly yet because this is the front end, and I32
// is a backend flag
#undef I16
Expand Down Expand Up @@ -3895,7 +3899,7 @@ STATIC OPND *asm_una_exp()
ASM_JUMPTYPE ajt = ASM_JUMPTYPE_UNSPECIFIED;
char bPtr = 0;

switch (tok_value)
switch ((int)tok_value)
{
#if 0
case TOKand:
Expand Down Expand Up @@ -4399,6 +4403,9 @@ Statement *AsmStatement::semantic(Scope *sc)
FuncDeclaration *fd = sc->parent->isFuncDeclaration();

assert(fd);
#if DMDV1
fd->inlineAsm = 1;
#endif

if (!tokens)
return NULL;
Expand Down Expand Up @@ -4561,6 +4568,7 @@ Statement *AsmStatement::semantic(Scope *sc)
opnd_free(o1);
opnd_free(o2);
opnd_free(o3);
o1 = o2 = o3 = NULL;

if (tok_value != TOKeof)
asmerr(EM_eol); // end of line expected
Expand Down
20 changes: 10 additions & 10 deletions src/intrange.c
Expand Up @@ -21,7 +21,7 @@
static uinteger_t copySign(uinteger_t x, bool sign)
{
// return sign ? -x : x;
return (x - sign) ^ -sign;
return (x - (uinteger_t)sign) ^ -(uinteger_t)sign;
}

#ifndef UINT64_MAX
Expand Down Expand Up @@ -127,7 +127,7 @@ SignExtendedNumber SignExtendedNumber::operator/(const SignExtendedNumber& a) co
anything / INT65_MIN = 0
+ / 0 = INT65_MAX (eh?)
- / 0 = INT65_MIN (eh?)
*/
*/
if (a.value == 0)
{
if (a.negative)
Expand All @@ -136,8 +136,8 @@ SignExtendedNumber SignExtendedNumber::operator/(const SignExtendedNumber& a) co
return extreme(negative);
}

uinteger_t aAbs = copySign(a.value, a.negative);
uinteger_t rvVal;
uinteger_t aAbs = copySign(a.value, a.negative);
uinteger_t rvVal;

if (!isMinimum())
rvVal = copySign(value, negative) / aAbs;
Expand All @@ -146,7 +146,7 @@ SignExtendedNumber SignExtendedNumber::operator/(const SignExtendedNumber& a) co
else if (aAbs & (aAbs-1))
rvVal = UINT64_MAX / aAbs;
// otherwise, it's the same as reversing the bits of x.
else
else
{
if (aAbs == 1)
return extreme(!a.negative);
Expand Down Expand Up @@ -210,7 +210,7 @@ SignExtendedNumber SignExtendedNumber::operator<<(const SignExtendedNumber& a) c
return extreme(negative);

uinteger_t v = copySign(value, negative);

// compute base-2 log of 'v' to determine the maximum allowed bits to shift.
// Ref: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog

Expand All @@ -236,7 +236,7 @@ SignExtendedNumber SignExtendedNumber::operator>>(const SignExtendedNumber& a) c
return negative ? SignExtendedNumber(-1, true) : SignExtendedNumber(0);
else if (isMinimum())
return a.value == 0 ? *this : SignExtendedNumber(-1ULL << (64-a.value), true);

uinteger_t x = value ^ -negative;
x >>= a.value;
return SignExtendedNumber(x ^ -negative, negative);
Expand Down Expand Up @@ -308,11 +308,11 @@ IntRange& IntRange::castUnsigned(uinteger_t mask)
{
// .... 0x1eff ] [0x1f00 .. 0x1fff] [0 .. 0xff] [0x100 .. 0x1ff] [0x200 ....
//
// regular unsigned type. We just need to see if ir steps across the
// regular unsigned type. We just need to see if ir steps across the
// boundary of validRange. If yes, ir will represent the whole validRange,
// otherwise, we just take the modulus.
// e.g. [0x105, 0x107] & 0xff == [5, 7]
// [0x105, 0x207] & 0xff == [0, 0xff]
// [0x105, 0x207] & 0xff == [0, 0xff]
uinteger_t minChunk = imin.value & ~mask;
uinteger_t maxChunk = imax.value & ~mask;
if (minChunk == maxChunk && imin.negative == imax.negative)
Expand Down Expand Up @@ -455,7 +455,7 @@ void IntRange::splitBySign(IntRange& negRange, bool& hasNegRange,


#if !PERFORM_UNITTEST
const IntRange& IntRange::dump(const char* funcName, Expression *e) const
const IntRange& IntRange::dump(const char* funcName, Expression *e) const
{
printf("[(%c)%#018llx, (%c)%#018llx] @ %s ::: %s\n",
imin.negative?'-':'+', (unsigned long long)imin.value,
Expand Down

0 comments on commit 72b6fc9

Please sign in to comment.