From 7ab4794a05e9030d38816202e9c911a54798d07c Mon Sep 17 00:00:00 2001 From: George Koehler Date: Fri, 25 Oct 2019 18:17:13 -0400 Subject: [PATCH] Reduce clang warnings from ncg If a .c file included "types.h" before "mach.h", then it missed the declaration of mach_option(). Fix by adding "xmach.h". Fix mach/powerpc/ncg/mach.h and mach/vc4/ncg/mach.h to use the correct type in their printf() format strings. --- mach/i386/ncg/mach.c | 2 +- mach/i86/ncg/mach.c | 2 +- mach/m68020/ncg/mach.c | 4 ++-- mach/powerpc/ncg/mach.h | 6 +++--- mach/proto/ncg/build.lua | 1 + mach/proto/ncg/codegen.c | 2 +- mach/proto/ncg/fillem.c | 17 +++++++++++++---- mach/proto/ncg/gencode.c | 2 +- mach/proto/ncg/main.c | 2 +- mach/proto/ncg/types.h | 4 ---- mach/proto/ncg/xmach.h | 15 +++++++++++++++ mach/vc4/ncg/mach.h | 6 +++--- 12 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 mach/proto/ncg/xmach.h diff --git a/mach/i386/ncg/mach.c b/mach/i386/ncg/mach.c index 5f67a3dfb..008d683cf 100644 --- a/mach/i386/ncg/mach.c +++ b/mach/i386/ncg/mach.c @@ -16,7 +16,7 @@ static char rcs_mh[]= ID_MH ; */ void -con_part(sz,w) register sz; word w; { +con_part(int sz, word w) { while (part_size % sz) part_size++; diff --git a/mach/i86/ncg/mach.c b/mach/i86/ncg/mach.c index 17cc876b6..31d1926ea 100644 --- a/mach/i86/ncg/mach.c +++ b/mach/i86/ncg/mach.c @@ -14,7 +14,7 @@ static char rcs_mh[]= ID_MH ; */ void -con_part(sz,w) register sz; word w; { +con_part(int sz, word w) { while (part_size % sz) part_size++; diff --git a/mach/m68020/ncg/mach.c b/mach/m68020/ncg/mach.c index 0df6c8389..b86a06bbd 100644 --- a/mach/m68020/ncg/mach.c +++ b/mach/m68020/ncg/mach.c @@ -18,7 +18,7 @@ #include void -con_part(sz,w) register sz; word w; { +con_part(int sz, word w) { while (part_size % sz) part_size++; @@ -88,7 +88,7 @@ regscore(off,size,typ,score,totyp) return score; } struct regsav_t { - char *rs_reg; /* e.g. "a3" or "d5" */ + const char *rs_reg; /* e.g. "a3" or "d5" */ long rs_off; /* offset of variable */ int rs_size; /* 2 or 4 bytes */ } regsav[9]; diff --git a/mach/powerpc/ncg/mach.h b/mach/powerpc/ncg/mach.h index 0bca86fae..10c3a6a35 100644 --- a/mach/powerpc/ncg/mach.h +++ b/mach/powerpc/ncg/mach.h @@ -9,10 +9,10 @@ #define newilb(x) fprintf(codefile,"%s:\n",x) #define newdlb(x) fprintf(codefile,"%s:\n",x) #define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) -#define newlbss(l,x) fprintf(codefile,".comm %s,%u\n",l,x); +#define newlbss(l,x) fprintf(codefile,".comm %s,%ld\n",l,x); -#define cst_fmt "%d" -#define off_fmt "%d" +#define cst_fmt "%ld" +#define off_fmt "%ld" #define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/mach/proto/ncg/build.lua b/mach/proto/ncg/build.lua index 1210382fc..6ab573a8a 100644 --- a/mach/proto/ncg/build.lua +++ b/mach/proto/ncg/build.lua @@ -20,6 +20,7 @@ definerule("build_ncg", "mach/proto/ncg/result.h", "mach/proto/ncg/state.h", "mach/proto/ncg/types.h", + "mach/proto/ncg/xmach.h", "mach/"..e.arch.."/ncg/mach.c", "mach/"..e.arch.."/ncg/*.h", } diff --git a/mach/proto/ncg/codegen.c b/mach/proto/ncg/codegen.c index 4ae6363f0..cb1bba8ac 100644 --- a/mach/proto/ncg/codegen.c +++ b/mach/proto/ncg/codegen.c @@ -706,7 +706,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for do { npos = exactmatch = 0; - for (rpp = reglist[propno]; rp = *rpp; rpp++) + for (rpp = reglist[propno]; (rp = *rpp) != NULL; rpp++) if (getrefcount((int)(rp - machregs), FALSE) == 0) { pos[npos++] = rp - machregs; diff --git a/mach/proto/ncg/fillem.c b/mach/proto/ncg/fillem.c index 7f0e4c681..c83144b1a 100644 --- a/mach/proto/ncg/fillem.c +++ b/mach/proto/ncg/fillem.c @@ -23,6 +23,9 @@ static char rcsid2[] = "$Id$"; #include "regvar.h" #include #endif +#ifdef USE_TES +#include "label.h" +#endif #include "extern.h" /* @@ -80,10 +83,16 @@ static int regallowed=0; extern char em_flag[]; extern short em_ptyp[]; -/* machine dependent */ +/* + * Declare the machine dependent functions. + * + * These functions now return void, which is not compatible with + * traditional K&R C. Old mach.c files stop working until one fixes + * them to return void, not int. + */ void con_part(int, word); void con_mult(word); -void con_float(void); /* actually returns void, but need K&R C compatibility */ +void con_float(void); void prolog(full nlocals); void mes(word); @@ -706,8 +715,8 @@ static void savelab(void) { } p = argstr; q = labstr; - while (*q++ = *p++) - ; + while ((*q++ = *p++) != '\0') + continue; } static void dumplab(void) { diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index 5b092340f..8b097f9ec 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -13,7 +13,7 @@ static char rcsid[] = "$Id$"; #include "result.h" #include "extern.h" #ifdef USE_TES -#include "mach.h" +#include "xmach.h" #endif /* diff --git a/mach/proto/ncg/main.c b/mach/proto/ncg/main.c index 0b3a40f86..80915e94d 100644 --- a/mach/proto/ncg/main.c +++ b/mach/proto/ncg/main.c @@ -6,7 +6,7 @@ static char rcsid[] = "$Id$"; #include "param.h" #include "tables.h" #include "types.h" -#include "mach.h" +#include "xmach.h" /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. diff --git a/mach/proto/ncg/types.h b/mach/proto/ncg/types.h index 825d2e42d..6427ffbf7 100644 --- a/mach/proto/ncg/types.h +++ b/mach/proto/ncg/types.h @@ -67,7 +67,3 @@ void garbage_collect(void); void itokcost(void); void error(const char *s, ...); void fatal(const char *s, ...); - -#ifdef MACH_OPTIONS -void mach_option(char *); /* machine dependent */ -#endif diff --git a/mach/proto/ncg/xmach.h b/mach/proto/ncg/xmach.h new file mode 100644 index 000000000..7211c00af --- /dev/null +++ b/mach/proto/ncg/xmach.h @@ -0,0 +1,15 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ + +/* + * Include "mach.h", then if "mach.h" defines MACH_OPTIONS, also + * declare mach_option(), a machine dependent function. + */ + +#include "mach.h" + +#ifdef MACH_OPTIONS +void mach_option(char *); +#endif diff --git a/mach/vc4/ncg/mach.h b/mach/vc4/ncg/mach.h index 89d2b8a97..a17bf9b6f 100644 --- a/mach/vc4/ncg/mach.h +++ b/mach/vc4/ncg/mach.h @@ -11,10 +11,10 @@ #define newilb(x) fprintf(codefile,"%s:\n",x) #define newdlb(x) fprintf(codefile,"%s:\n",x) #define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) -#define newlbss(l,x) fprintf(codefile,".comm %s,%u\n",l,x); +#define newlbss(l,x) fprintf(codefile,".comm %s,%ld\n",l,x); -#define cst_fmt "%d" -#define off_fmt "%d" +#define cst_fmt "%ld" +#define off_fmt "%ld" #define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d"