lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,
Joerg came accross some warnings in gcc and clang after adding Lua to
the NetBSD base. This patch resolves them.

PS I think __dead needs a wrapper in luaconf.h:

/*
 * HAVE_NORETURN_ATTRIBUTE should be defined if compiler supports
 * __noreturn__
 */
#if !defined(LUA_ANSI) && defined(HAVE_NORETURN_ATTRIBUTE)
#define __dead __attribute__((__noreturn__))
#else
#define __dead
#endif


----- Forwarded message from Joerg Sonnenberger <joerg@britannica.bec.de> -----

Date: Thu, 15 Mar 2012 02:59:22 +0100
From: Joerg Sonnenberger <joerg@britannica.bec.de>
To: Alexander Nasonov <alnsn@netbsd.org>
Subject: Re: CVS commit: src/external/mit/lua/dist/src

On Thu, Mar 15, 2012 at 01:02:20AM +0000, Alexander Nasonov wrote:
> Module Name:	src
> Committed By:	alnsn
> Date:		Thu Mar 15 01:02:20 UTC 2012
> 
> Modified Files:
> 	src/external/mit/lua/dist/src: luaconf.h
> 
> Log Message:
> Don't overwrite Roberto's external $Id.

Are you in concat with him? The attached patch is what is needed for
building with WARNS=4 and both Clang and GCC.

The __dead attribution is __attribute__((__noreturn__)), it helps both
optimizers and static analysis.

The change to cast() and using it consistently shuts up warnings about
const casts. At least using the macro consistently would be nice.
Maybe conditionalize it on __STDC__VERSION__ >= 199900.

The change to lauxlib.c avoids empty body warning with clang.

Joerg

Index: src/lauxlib.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/lauxlib.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 lauxlib.c
--- src/lauxlib.c	15 Mar 2012 00:08:09 -0000	1.1.1.2
+++ src/lauxlib.c	15 Mar 2012 01:07:21 -0000
@@ -576,7 +576,8 @@ LUALIB_API int luaL_loadfile (lua_State 
     lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
     if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
     /* skip eventual `#!...' */
-   while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
+    do c = getc(lf.f);
+    while (c != EOF && c != LUA_SIGNATURE[0]);
     lf.extraline = 0;
   }
   ungetc(c, lf.f);
Index: src/ldblib.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/ldblib.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 ldblib.c
--- src/ldblib.c	15 Mar 2012 00:08:10 -0000	1.1.1.2
+++ src/ldblib.c	15 Mar 2012 01:51:33 -0000
@@ -18,6 +18,7 @@
 
 #include "lauxlib.h"
 #include "lualib.h"
+#include "llimits.h"
 
 
 
@@ -209,7 +210,7 @@ static const char KEY_HOOK = 'h';
 static void hookf (lua_State *L, lua_Debug *ar) {
   static const char *const hooknames[] =
     {"call", "return", "line", "count", "tail return"};
-  lua_pushlightuserdata(L, (void *)&KEY_HOOK);
+  lua_pushlightuserdata(L, cast(void *, &KEY_HOOK));
   lua_rawget(L, LUA_REGISTRYINDEX);
   lua_pushlightuserdata(L, L);
   lua_rawget(L, -2);
@@ -245,12 +246,12 @@ static char *unmakemask (int mask, char 
 
 
 static void gethooktable (lua_State *L) {
-  lua_pushlightuserdata(L, (void *)&KEY_HOOK);
+  lua_pushlightuserdata(L, cast(void *, &KEY_HOOK));
   lua_rawget(L, LUA_REGISTRYINDEX);
   if (!lua_istable(L, -1)) {
     lua_pop(L, 1);
     lua_createtable(L, 0, 1);
-    lua_pushlightuserdata(L, (void *)&KEY_HOOK);
+    lua_pushlightuserdata(L, cast(void *, &KEY_HOOK));
     lua_pushvalue(L, -2);
     lua_rawset(L, LUA_REGISTRYINDEX);
   }
Index: src/ldebug.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/ldebug.h,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 ldebug.h
--- src/ldebug.h	15 Mar 2012 00:08:14 -0000	1.1.1.2
+++ src/ldebug.h	15 Mar 2012 01:11:06 -0000
@@ -21,14 +21,14 @@
 
 
 LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
-                                             const char *opname);
-LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
+                                             const char *opname) __dead;
+LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2) __dead;
 LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,
-                                              const TValue *p2);
+                                              const TValue *p2) __dead;
 LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,
                                              const TValue *p2);
-LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
-LUAI_FUNC void luaG_errormsg (lua_State *L);
+LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...) __dead;
+LUAI_FUNC void luaG_errormsg (lua_State *L) __dead;
 LUAI_FUNC int luaG_checkcode (const Proto *pt);
 LUAI_FUNC int luaG_checkopenop (Instruction i);
 
Index: src/ldo.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/ldo.h,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 ldo.h
--- src/ldo.h	15 Mar 2012 00:08:09 -0000	1.1.1.2
+++ src/ldo.h	15 Mar 2012 01:09:12 -0000
@@ -50,7 +50,7 @@ LUAI_FUNC void luaD_reallocCI (lua_State
 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);
+LUAI_FUNC void luaD_throw (lua_State *L, int errcode) __dead;
 LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
 
 LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
Index: src/llex.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/llex.h,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 llex.h
--- src/llex.h	15 Mar 2012 00:08:12 -0000	1.1.1.2
+++ src/llex.h	15 Mar 2012 01:11:42 -0000
@@ -75,8 +75,8 @@ LUAI_FUNC void luaX_setinput (lua_State 
 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);
-LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
+LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token) __dead;
+LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s) __dead;
 LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
 
 
Index: src/llimits.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/llimits.h,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 llimits.h
--- src/llimits.h	15 Mar 2012 00:08:12 -0000	1.1.1.2
+++ src/llimits.h	15 Mar 2012 01:49:54 -0000
@@ -12,7 +12,7 @@
 
 #include <limits.h>
 #include <stddef.h>
-
+#include <inttypes.h>
 
 #include "lua.h"
 
@@ -74,7 +74,7 @@ typedef LUAI_UACNUMBER l_uacNumber;
 
 
 #ifndef cast
-#define cast(t, exp)	((t)(exp))
+#define cast(t, exp)	((t)(uintptr_t)(exp))
 #endif
 
 #define cast_byte(i)	cast(lu_byte, (i))
Index: src/loadlib.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/loadlib.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 loadlib.c
--- src/loadlib.c	15 Mar 2012 00:08:12 -0000	1.1.1.2
+++ src/loadlib.c	15 Mar 2012 01:54:33 -0000
@@ -22,7 +22,7 @@
 
 #include "lauxlib.h"
 #include "lualib.h"
-
+#include "llimits.h"
 
 /* prefix for open functions in C libraries */
 #define LUA_POF		"luaopen_"
@@ -447,7 +447,7 @@ static int loader_preload (lua_State *L)
 
 
 static const int sentinel_ = 0;
-#define sentinel	((void *)&sentinel_)
+#define sentinel	(cast(void *, &sentinel_))
 
 
 static int ll_require (lua_State *L) {
Index: src/lparser.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/lparser.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 lparser.c
--- src/lparser.c	15 Mar 2012 00:08:07 -0000	1.1.1.2
+++ src/lparser.c	15 Mar 2012 01:12:14 -0000
@@ -64,13 +64,13 @@ static void anchor_token (LexState *ls) 
 }
 
 
-static void error_expected (LexState *ls, int token) {
+__dead static void error_expected (LexState *ls, int token) {
   luaX_syntaxerror(ls,
       luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token)));
 }
 
 
-static void errorlimit (FuncState *fs, int limit, const char *what) {
+__dead static void errorlimit (FuncState *fs, int limit, const char *what) {
   const char *msg = (fs->f->linedefined == 0) ?
     luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) :
     luaO_pushfstring(fs->L, "function at line %d has more than %d %s",
Index: src/lundump.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/mit/lua/dist/src/lundump.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 lundump.c
--- src/lundump.c	15 Mar 2012 00:08:14 -0000	1.1.1.2
+++ src/lundump.c	15 Mar 2012 01:12:31 -0000
@@ -35,7 +35,7 @@ typedef struct {
 #else
 #define IF(c,s)		if (c) error(S,s)
 
-static void error(LoadState* S, const char* why)
+__dead static void error(LoadState* S, const char* why)
 {
  luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
  luaD_throw(S->L,LUA_ERRSYNTAX);


----- End forwarded message -----

--