Added gcc option '-Wconversion'

No warnings for standard numerical types. Still pending alternative
numerical types.
This commit is contained in:
Roberto Ierusalimschy
2024-07-27 13:32:59 -03:00
parent 15231d4fb2
commit 0acd55898d
44 changed files with 398 additions and 359 deletions

View File

@@ -172,7 +172,8 @@ static void codename (LexState *ls, expdesc *e) {
** Register a new local variable in the active 'Proto' (for debug
** information).
*/
static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) {
static short registerlocalvar (LexState *ls, FuncState *fs,
TString *varname) {
Proto *f = fs->f;
int oldsize = f->sizelocvars;
luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars,
@@ -190,7 +191,7 @@ static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) {
** Create a new local variable with the given 'name' and given 'kind'.
** Return its index in the function.
*/
static int new_localvarkind (LexState *ls, TString *name, int kind) {
static int new_localvarkind (LexState *ls, TString *name, lu_byte kind) {
lua_State *L = ls->L;
FuncState *fs = ls->fs;
Dyndata *dyd = ls->dyd;
@@ -234,11 +235,11 @@ static Vardesc *getlocalvardesc (FuncState *fs, int vidx) {
** register. For that, search for the highest variable below that level
** that is in a register and uses its register index ('ridx') plus one.
*/
static int reglevel (FuncState *fs, int nvar) {
static lu_byte reglevel (FuncState *fs, int nvar) {
while (nvar-- > 0) {
Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */
if (vd->vd.kind != RDKCTC) /* is in a register? */
return vd->vd.ridx + 1;
return cast_byte(vd->vd.ridx + 1);
}
return 0; /* no variables in registers */
}
@@ -248,7 +249,7 @@ static int reglevel (FuncState *fs, int nvar) {
** Return the number of variables in the register stack for the given
** function.
*/
int luaY_nvarstack (FuncState *fs) {
lu_byte luaY_nvarstack (FuncState *fs) {
return reglevel(fs, fs->nactvar);
}
@@ -274,7 +275,7 @@ static LocVar *localdebuginfo (FuncState *fs, int vidx) {
static void init_var (FuncState *fs, expdesc *e, int vidx) {
e->f = e->t = NO_JUMP;
e->k = VLOCAL;
e->u.var.vidx = vidx;
e->u.var.vidx = cast(unsigned short, vidx);
e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx;
}
@@ -323,7 +324,7 @@ static void adjustlocalvars (LexState *ls, int nvars) {
for (i = 0; i < nvars; i++) {
int vidx = fs->nactvar++;
Vardesc *var = getlocalvardesc(fs, vidx);
var->vd.ridx = reglevel++;
var->vd.ridx = cast_byte(reglevel++);
var->vd.pidx = registerlocalvar(ls, fs, var->vd.name);
}
}
@@ -505,7 +506,7 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
if (needed > 0)
luaK_reserveregs(fs, needed); /* registers for extra values */
else /* adding 'needed' is actually a subtraction */
fs->freereg += needed; /* remove extra values */
fs->freereg = cast_byte(fs->freereg + needed); /* remove extra values */
}
@@ -682,7 +683,7 @@ static void leaveblock (FuncState *fs) {
BlockCnt *bl = fs->bl;
LexState *ls = fs->ls;
int hasclose = 0;
int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */
lu_byte stklevel = reglevel(fs, bl->nactvar); /* level outside the block */
removevars(fs, bl->nactvar); /* remove block locals */
lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */
if (bl->isloop) /* has to fix pending breaks? */
@@ -856,7 +857,7 @@ typedef struct ConsControl {
static void recfield (LexState *ls, ConsControl *cc) {
/* recfield -> (NAME | '['exp']') = exp */
FuncState *fs = ls->fs;
int reg = ls->fs->freereg;
lu_byte reg = ls->fs->freereg;
expdesc tab, key, val;
if (ls->t.token == TK_NAME) {
checklimit(fs, cc->nh, INT_MAX, "items in a constructor");
@@ -939,7 +940,7 @@ static void field (LexState *ls, ConsControl *cc) {
static int maxtostore (FuncState *fs) {
int numfreeregs = MAX_FSTACK - fs->freereg;
if (numfreeregs >= 160) /* "lots" of registers? */
return numfreeregs / 5u; /* use up to 1/5 of them */
return numfreeregs / 5; /* use up to 1/5 of them */
else if (numfreeregs >= 80) /* still "enough" registers? */
return 10; /* one 'SETLIST' instruction for each 10 values */
else /* save registers for potential more nesting */
@@ -1090,8 +1091,9 @@ static void funcargs (LexState *ls, expdesc *f) {
}
init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
luaK_fixline(fs, line);
fs->freereg = base+1; /* call removes function and arguments and leaves
one result (unless changed later) */
/* call removes function and arguments and leaves one result (unless
changed later) */
fs->freereg = cast_byte(base + 1);
}
@@ -1356,7 +1358,7 @@ struct LHS_assign {
*/
static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
FuncState *fs = ls->fs;
int extra = fs->freereg; /* eventual position to save local variable */
lu_byte extra = fs->freereg; /* eventual position to save local variable */
int conflict = 0;
for (; lh; lh = lh->prev) { /* check all previous assignments */
if (vkisindexed(lh->v.k)) { /* assignment to table field? */
@@ -1723,7 +1725,7 @@ static void localfunc (LexState *ls) {
}
static int getlocalattribute (LexState *ls) {
static lu_byte getlocalattribute (LexState *ls) {
/* ATTRIB -> ['<' Name '>'] */
if (testnext(ls, '<')) {
TString *ts = str_checkname(ls);
@@ -1760,7 +1762,7 @@ static void localstat (LexState *ls) {
expdesc e;
do {
TString *vname = str_checkname(ls);
int kind = getlocalattribute(ls);
lu_byte kind = getlocalattribute(ls);
vidx = new_localvarkind(ls, vname, kind);
if (kind == RDKTOCLOSE) { /* to-be-closed? */
if (toclose != -1) /* one already present? */