Skip to content

Commit

Permalink
Merge pull request #2469 from WalterBright/fix-clang-warnings
Browse files Browse the repository at this point in the history
fix warnings emitted by clang
  • Loading branch information
andralex committed Aug 16, 2013
2 parents a5c9b9a + caf8426 commit cf78035
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/backend/cgcod.c
Expand Up @@ -2163,8 +2163,8 @@ STATIC code * comsub(elem *e,regm_t *pretregs)
//printf("comsub(e = %p, *pretregs = %s)\n",e,regm_str(*pretregs));
elem_debug(e);
#ifdef DEBUG
if (e->Ecomsub > e->Ecount)
elem_print(e);
//if (e->Ecomsub > e->Ecount)
//elem_print(e);
#endif
assert(e->Ecomsub <= e->Ecount);

Expand Down Expand Up @@ -2201,7 +2201,7 @@ if (debugw)
{
printf("comsub(e=%p): *pretregs=%s, emask=%s, csemask=%s, regcon.cse.mval=%s, regcon.mvar=%s\n",
e,regm_str(*pretregs),regm_str(emask),regm_str(csemask),regm_str(regcon.cse.mval),regm_str(regcon.mvar));
if (regcon.cse.mval & 1) elem_print(regcon.cse.value[i]);
if (regcon.cse.mval & 1) elem_print(regcon.cse.value[0]);
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/backend/cgelem.c
Expand Up @@ -2506,8 +2506,8 @@ STATIC bool optim_loglog(elem **pe)
if (0 && eq->E2->Eoper != OPconst)
{
printf("eq = %p, eq->E2 = %p\n", eq, eq->E2);
printf("first = %d, i = %d, last = %d, Eoper = %d\n", first, i, last, eq->E2->Eoper);
printf("any = %d, n = %d, count = %d, min = %d, max = %d\n", any, (int)n, last - first + 1, (int)emin, (int)emax);
printf("first = %d, i = %d, last = %d, Eoper = %d\n", (int)first, (int)i, (int)last, eq->E2->Eoper);
printf("any = %d, n = %d, count = %d, min = %d, max = %d\n", any, (int)n, (int)(last - first + 1), (int)emin, (int)emax);
}
assert(eq->E2->Eoper == OPconst);
bits |= (targ_ullong)1 << (el_tolong(eq->E2) - emin);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/el.c
Expand Up @@ -1793,7 +1793,7 @@ int el_noreturn(elem *e)
{ elem_debug(e);
switch (e->Eoper)
{ case OPcomma:
if (result |= el_noreturn(e->E1))
if ((result |= el_noreturn(e->E1)) != 0)
break;
e = e->E2;
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/backend/gloop.c
Expand Up @@ -886,8 +886,8 @@ void loopopt()
if (dfo[i]->Belem)
{ // If there is any hope of making an improvement
if (domexit || l->Llis)
{ if (dfo[i] != l->Lhead)
; //domexit |= 2;
{ //if (dfo[i] != l->Lhead)
//domexit |= 2;
movelis(dfo[i]->Belem, dfo[i], l, &domexit);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/backend/gother.c
Expand Up @@ -1315,9 +1315,9 @@ STATIC void accumda(elem *n,vec_t DEAD, vec_t POSS)
POSS[i] = tmp1 | tmp2;
}
#else
{ DEAD[i] |= POSS[i] & Dl[i] & Dr[i] |
~POSS[i] & (Dl[i] | Dr[i]);
POSS[i] = Pl[i] & Pr[i] | ~POSS[i] & (Pl[i] | Pr[i]);
{ DEAD[i] |= (POSS[i] & Dl[i] & Dr[i]) |
(~POSS[i] & (Dl[i] | Dr[i]));
POSS[i] = (Pl[i] & Pr[i]) | (~POSS[i] & (Pl[i] | Pr[i]));
}
#endif
vec_free(Pl); vec_free(Pr); vec_free(Dl); vec_free(Dr);
Expand Down
1 change: 1 addition & 0 deletions src/backend/machobj.c
Expand Up @@ -2148,6 +2148,7 @@ int Obj::external(Symbol *s)
symbol_debug(s);
extern_symbuf->write(&s, sizeof(s));
s->Sxtrnnum = 1;
return 0;
}

/*******************************
Expand Down
2 changes: 1 addition & 1 deletion src/backend/nteh.c
Expand Up @@ -344,7 +344,7 @@ code *nteh_prolog()
cs.IEV2.Vint = -1;
c1 = gen(CNIL,&cs); // PUSH -1

if (usednteh & NTEHcpp || MARS)
if ((usednteh & NTEHcpp) || MARS)
{
// PUSH &framehandler
cs.IFL2 = FLframehandler;
Expand Down
3 changes: 3 additions & 0 deletions src/backend/util2.c
Expand Up @@ -55,6 +55,9 @@ void util_assert(const char *file, int line)
fflush(stdout);
printf("Internal error: %s %d\n",file,line);
err_exit();
#if __clang__
__builtin_unreachable();
#endif
}

/****************************
Expand Down
2 changes: 1 addition & 1 deletion src/clone.c
Expand Up @@ -715,7 +715,7 @@ FuncDeclaration *StructDeclaration::buildCpCtor(Scope *sc)

stc = mergeFuncAttrs(stc, postblit->storage_class);
if (stc & STCsafe) // change to @trusted for unsafe casts
stc = stc & ~STCsafe | STCtrusted;
stc = (stc & ~STCsafe) | STCtrusted;

Parameters *fparams = new Parameters;
fparams->push(new Parameter(STCref, type->constOf(), Id::p, NULL));
Expand Down
5 changes: 5 additions & 0 deletions src/ctfeexpr.c
Expand Up @@ -808,6 +808,8 @@ int comparePointers(Loc loc, TOK op, Type *type, Expression *agg1, dinteger_t of
case TOKnotequal:
cmp = (null1 == null2);
break;
default:
assert(0);
}
}
else
Expand Down Expand Up @@ -905,6 +907,9 @@ void intUnary(TOK op, IntegerExp *e)
case TOKtilde:
e->value = ~e->value;
break;
default:
assert(0);
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/expression.c
Expand Up @@ -1932,7 +1932,7 @@ Expression *Expression::copy()
}
e = (Expression *)mem.malloc(size);
//printf("Expression::copy(op = %d) e = %p\n", op, e);
return (Expression *)memcpy(e, this, size);
return (Expression *)memcpy((void*)e, (void*)this, size);

This comment has been minimized.

Copy link
@yebblies

yebblies Aug 19, 2013

Member

These memcpy changes broke DDMD, just FYI. What exactly was wrong with the original code?

This comment has been minimized.

Copy link
@ibuclaw

ibuclaw Aug 19, 2013

Member

Wow...

  1. I'm surprised at Walter for fixing warning issues in the front-end - something I've mentioned to having pet peeves about as far back as 2 years ago because I was having to weave through literally thousands of warnings being emitted when compiling the D frontend against gdc to find the reason why compilation failed during front-end updates, only to have it brushed off as 'none of these are actually bugs'.
  2. AHEM - none of these memcpy changes are actually bugs :)

This comment has been minimized.

Copy link
@yebblies

yebblies Aug 19, 2013

Member

I suppose I need a better way to copy classes than hacking memcpy...

This comment has been minimized.

Copy link
@WalterBright

WalterBright Aug 19, 2013

Member

Since we'll be moving to clang for OS X, I felt it worthwhile removing some of the blizzard of warnings clang emits. Unfortunately, a blizzard of irritatingly meaningless non-bug messages remain.

This comment has been minimized.

Copy link
@ibuclaw

ibuclaw Aug 19, 2013

Member

Try building under linux with -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings and you'll know how I felt. ;-)

}

/**************************
Expand Down
5 changes: 5 additions & 0 deletions src/iasm.c
Expand Up @@ -3981,6 +3981,8 @@ STATIC OPND *asm_rel_exp()
case TOKle:
o1->disp = o1->disp <= o2->disp;
break;
default:
assert(0);
}
}
else
Expand Down Expand Up @@ -4563,6 +4565,9 @@ STATIC OPND *asm_primary_exp()
o1->ptype = Type::tint32;
asm_token();
break;

default:
break;
}
Lret:
return o1;
Expand Down
6 changes: 3 additions & 3 deletions src/inline.c
Expand Up @@ -765,7 +765,7 @@ Expression *DeclarationExp::doInline(InlineDoState *ids)
VarDeclaration *vto;

vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
memcpy(vto, vd, sizeof(VarDeclaration));
memcpy((void*)vto, (void*)vd, sizeof(VarDeclaration));
vto->parent = ids->parent;
vto->csym = NULL;
vto->isym = NULL;
Expand Down Expand Up @@ -859,7 +859,7 @@ Expression *IndexExp::doInline(InlineDoState *ids)
VarDeclaration *vto;

vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
memcpy(vto, vd, sizeof(VarDeclaration));
memcpy((void*)vto, (void*)vd, sizeof(VarDeclaration));
vto->parent = ids->parent;
vto->csym = NULL;
vto->isym = NULL;
Expand Down Expand Up @@ -896,7 +896,7 @@ Expression *SliceExp::doInline(InlineDoState *ids)
VarDeclaration *vto;

vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
memcpy(vto, vd, sizeof(VarDeclaration));
memcpy((void*)vto, (void*)vd, sizeof(VarDeclaration));
vto->parent = ids->parent;
vto->csym = NULL;
vto->isym = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/interpret.c
Expand Up @@ -3961,7 +3961,7 @@ Expression *interpretAssignToSlice(InterState *istate, CtfeGoal goal, Loc loc,
return newval;

Expression *aggregate = resolveReferences(sexp->e1);
dinteger_t firstIndex = lowerbound;
sinteger_t firstIndex = lowerbound;

ArrayLiteralExp *existingAE = NULL;
StringExp *existingSE = NULL;
Expand Down Expand Up @@ -4894,7 +4894,7 @@ Expression *IndexExp::interpret(InterState *istate, CtfeGoal goal)
{
dinteger_t len = ArrayLength(Type::tsize_t, agg)->toInteger();
//Type *pointee = ((TypePointer *)agg->type)->next;
if ((indx + ofs) < 0 || (indx+ofs) > len)
if ((sinteger_t)(indx + ofs) < 0 || (indx+ofs) > len)
{
error("pointer index [%lld] exceeds allocated memory block [0..%lld]",
indx+ofs, len);
Expand Down
4 changes: 2 additions & 2 deletions src/mars.c
Expand Up @@ -1541,14 +1541,14 @@ Language changes listed by -transition=id:\n\
if (global.params.moduleDeps)
{
OutBuffer* ob = global.params.moduleDeps;
if (global.params.moduleDepsFile)
if (global.params.moduleDepsFile)
{
File deps(global.params.moduleDepsFile);
deps.setbuffer((void*)ob->data, ob->offset);
deps.writev();
}
else
printf("%.*s", ob->offset, ob->data);
printf("%.*s", (int)ob->offset, ob->data);
}

// Scan for functions to inline
Expand Down
6 changes: 3 additions & 3 deletions src/mtype.c
Expand Up @@ -157,7 +157,7 @@ const char *Type::kind()
Type *Type::copy()
{
Type *t = (Type *)mem.malloc(sizeTy[ty]);
memcpy(t, this, sizeTy[ty]);
memcpy((void*)t, (void*)this, sizeTy[ty]);
return t;
}

Expand Down Expand Up @@ -396,7 +396,7 @@ Type *Type::nullAttributes()
{
unsigned sz = sizeTy[ty];
Type *t = (Type *)mem.malloc(sz);
memcpy(t, this, sz);
memcpy((void*)t, (void*)this, sz);
// t->mod = NULL; // leave mod unchanged
t->deco = NULL;
t->arrayof = NULL;
Expand Down Expand Up @@ -5534,7 +5534,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
for (size_t i = 0; i < parameters->dim; i++)
{ Parameter *arg = (*parameters)[i];
Parameter *cpy = (Parameter *)mem.malloc(sizeof(Parameter));
memcpy(cpy, arg, sizeof(Parameter));
memcpy((void*)cpy, (void*)arg, sizeof(Parameter));
(*tf->parameters)[i] = cpy;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/optimize.c
Expand Up @@ -354,7 +354,7 @@ Expression *AddrExp::optimize(int result, bool keepLvalue)

if (ae->e2->op == TOKint64 && ae->e1->op == TOKvar)
{
dinteger_t index = ae->e2->toInteger();
sinteger_t index = ae->e2->toInteger();
VarExp *ve = (VarExp *)ae->e1;
if (ve->type->ty == Tsarray
&& !ve->var->isImportedSymbol())
Expand Down
4 changes: 2 additions & 2 deletions src/s2ir.c
Expand Up @@ -765,12 +765,12 @@ void ReturnStatement::toIR(IRState *irs)
if (exp->op == TOKstructliteral)
{ StructLiteralExp *se = (StructLiteralExp *)exp;
char save[sizeof(StructLiteralExp)];
memcpy(save, se, sizeof(StructLiteralExp));
memcpy(save, (void*)se, sizeof(StructLiteralExp));
se->sym = irs->shidden;
se->soffset = 0;
se->fillHoles = 1;
e = exp->toElemDtor(irs);
memcpy(se, save, sizeof(StructLiteralExp));
memcpy((void*)se, save, sizeof(StructLiteralExp));

}
else
Expand Down
4 changes: 4 additions & 0 deletions src/scanmach.c
Expand Up @@ -167,10 +167,12 @@ void scanMachObjModule(void* pctx, void (*pAddSymbol)(void* pctx, char* name, in
; //printf(" N_STAB");
else
{
#if 0
if (s->n_type & N_PEXT)
;
if (s->n_type & N_EXT)
;
#endif
switch (s->n_type & N_TYPE)
{
case N_UNDF:
Expand Down Expand Up @@ -208,10 +210,12 @@ void scanMachObjModule(void* pctx, void (*pAddSymbol)(void* pctx, char* name, in
; //printf(" N_STAB");
else
{
#if 0
if (s->n_type & N_PEXT)
;
if (s->n_type & N_EXT)
;
#endif
switch (s->n_type & N_TYPE)
{
case N_UNDF:
Expand Down

0 comments on commit cf78035

Please sign in to comment.