Skip to content

Commit

Permalink
Add noreturn support for MSVC, fix warnings
Browse files Browse the repository at this point in the history
Adding the noreturn attribute for MSVC incurs additional warnings
for unreachable code. As we're only aiming to support the big three
compilers - all of which have attributes - we can fix unreachable
code warnings by just removing said code.
  • Loading branch information
Meorawr committed Jul 17, 2021
1 parent 6184b47 commit 2e456c7
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 17 deletions.
2 changes: 2 additions & 0 deletions include/luaconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
*/
#if defined(__GNUC__) || defined(__clang__)
#define LUA_NORETURN __attribute__((noreturn))
#elif defined(_MSC_VER)
#define LUA_NORETURN __declspec(noreturn)
#else
#define LUA_NORETURN
#endif
Expand Down
1 change: 0 additions & 1 deletion src/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@ LUA_API int lua_error (lua_State *L) {
api_checknelems(L, 1);
luaG_errormsg(L);
lua_unlock(L);
return 0; /* to avoid warnings */
}


Expand Down
2 changes: 1 addition & 1 deletion src/ldebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
}


int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
void luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
const char *t1 = luaT_typenames[ttype(p1)];
const char *t2 = luaT_typenames[ttype(p2)];
if (t1[2] == t2[2])
Expand Down
12 changes: 6 additions & 6 deletions src/ldebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#define resethookcount(L) (L->hookcount = L->basehookcount)


LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, const char *opname) LUA_NORETURN;
LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2) LUA_NORETURN;
LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) LUA_NORETURN;
LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) LUA_NORETURN;
LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...) LUA_NORETURN;
LUAI_FUNC void luaG_errormsg (lua_State *L) LUA_NORETURN;
LUAI_FUNC LUA_NORETURN void luaG_typeerror (lua_State *L, const TValue *o, const char *opname);
LUAI_FUNC LUA_NORETURN void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
LUAI_FUNC LUA_NORETURN void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2);
LUAI_FUNC LUA_NORETURN void luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2);
LUAI_FUNC LUA_NORETURN void luaG_runerror (lua_State *L, const char *fmt, ...);
LUAI_FUNC LUA_NORETURN void luaG_errormsg (lua_State *L);
LUAI_FUNC int luaG_checkcode (const Proto *pt);
LUAI_FUNC int luaG_checkopenop (Instruction i);

Expand Down
2 changes: 1 addition & 1 deletion src/ldo.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
LUAI_FUNC void luaD_growstack (lua_State *L, int n);

LUAI_FUNC void luaD_throw (lua_State *L, int errcode) LUA_NORETURN;
LUAI_FUNC LUA_NORETURN void luaD_throw (lua_State *L, int errcode);
LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);

LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
Expand Down
4 changes: 2 additions & 2 deletions src/llex.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
LUAI_FUNC void luaX_next (LexState *ls);
LUAI_FUNC void luaX_lookahead (LexState *ls);
LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token) LUA_NORETURN;
LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s) LUA_NORETURN;
LUAI_FUNC LUA_NORETURN void luaX_lexerror (LexState *ls, const char *msg, int token);
LUAI_FUNC LUA_NORETURN void luaX_syntaxerror (LexState *ls, const char *s);
LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);


Expand Down
1 change: 0 additions & 1 deletion src/lmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,

void *luaM_toobig (lua_State *L) {
luaG_runerror(L, "memory allocation error: block too big");
return NULL; /* to avoid warnings */
}


Expand Down
1 change: 0 additions & 1 deletion src/ltable.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ static int findindex (lua_State *L, Table *t, StkId key) {
else n = gnext(n);
} while (n);
luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
return 0; /* to avoid warnings */
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/lvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,21 @@ static int l_strcmp (const TString *ls, const TString *rs) {
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
int res;
if (ttype(l) != ttype(r))
return luaG_ordererror(L, l, r);
luaG_ordererror(L, l, r);
else if (ttisnumber(l))
return luai_numlt(nvalue(l), nvalue(r));
else if (ttisstring(l))
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
return res;
return luaG_ordererror(L, l, r);
luaG_ordererror(L, l, r);
}


static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
int res;
if (ttype(l) != ttype(r))
return luaG_ordererror(L, l, r);
luaG_ordererror(L, l, r);
else if (ttisnumber(l))
return luai_numle(nvalue(l), nvalue(r));
else if (ttisstring(l))
Expand All @@ -258,7 +258,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
return res;
else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
return !res;
return luaG_ordererror(L, l, r);
luaG_ordererror(L, l, r);
}


Expand Down

0 comments on commit 2e456c7

Please sign in to comment.