Skip to content

Commit

Permalink
[flang1] Fix compilation warnings; NFCI
Browse files Browse the repository at this point in the history
Fix the Flang code base so that WITH_WERROR=on can be used at CMake time to
enable stricter linting. This patch mainly addresses the following types of
warnings:

- -Wcast-qual warnings as a result of mixing (char *) fields and parameters
  with (const char *) values, especially string literals. Most of these can
  be trivially fixed by changing the type of the fields/parameters in question
  to (const char *). Tricky cases are handled with explicit casts (e.g. of
  string literals to (char *)).

- -Wunused-variable and -Wsometimes-uninitialized warnings. Unused variables
  are deleted, and ones that are used conditionally are initialized with
  sensible defaults.

- -Wmissing-field-initializers warnings for partial initializers in data
  structure definitions.

- -Wformat warnings (e.g. "%d" vs. "%ld", "%p" for non-(void *) arguments).
  • Loading branch information
Kush Bhagat authored and bryanpkc committed Jun 16, 2021
1 parent aa9a6ee commit e939d38
Show file tree
Hide file tree
Showing 96 changed files with 1,572 additions and 2,426 deletions.
6 changes: 3 additions & 3 deletions tools/flang1/flang1exe/accpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static char *suffix = ".obj";
static char *suffix = ".o";
#endif

static char *prevfile = NULL;
static const char *prevfile = NULL;
static int prevline = -1;

/* True if dodef() is parsing a #define string (nextok needs to know this) */
Expand Down Expand Up @@ -631,7 +631,7 @@ static INT tobinary(char *, int *, INT *);
static INT tobinary64(char *, int *, DBLINT64);
static int gettoken(void);
static void parse(int, PTOK *);
static void pr_line(char *, int, LOGICAL);
static void pr_line(const char *, int, LOGICAL);
static void doline(int, char *);
static int dopragma(void);
static void doerror(void);
Expand Down Expand Up @@ -1235,7 +1235,7 @@ accpp(void)
* (both the string and its length)
*/
static void
pr_line(char *name, int line, LOGICAL from_stdinc)
pr_line(const char *name, int line, LOGICAL from_stdinc)
{
static INT last_inclev = -1;
char *header_origin;
Expand Down
2 changes: 1 addition & 1 deletion tools/flang1/flang1exe/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -6997,7 +6997,7 @@ dump_std(void)

/* routine must be externally visible */
void
dump_stg_stat(char *where)
dump_stg_stat(const char *where)
{
FILE *fil;
if (gbl.dbgfil == NULL)
Expand Down
2 changes: 1 addition & 1 deletion tools/flang1/flang1exe/astout.c
Original file line number Diff line number Diff line change
Expand Up @@ -3495,7 +3495,7 @@ static int
find_member_base(int dtype)
{
int basesptr, dty, mem;
char *rtnNm = mkRteRtnNm(RTE_member_base);
const char *rtnNm = mkRteRtnNm(RTE_member_base);
basesptr = lookupsymbol(rtnNm);
if (basesptr == 0 || STYPEG(basesptr) != ST_CMBLK) {
return NOSYM;
Expand Down
31 changes: 12 additions & 19 deletions tools/flang1/flang1exe/commopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,11 @@
extern int rewrite_opfields;

static void commopt(void);
static void shmem_opt1(void);
static void shmem_opt2(void);
static void shmemopt1(void);
static void shmemopt2(void);
static void comm_optimize_init(void);
static LOGICAL same_forall_bnds(int, int, int);
static LOGICAL is_fusable(int, int, int);
static LOGICAL smp_conflict(int, int);
static LOGICAL is_in_block(int, int);
static LOGICAL is_different_scalar_mask(int, int);
static LOGICAL Conflict(int, int, int, LOGICAL, int, int);
static LOGICAL is_branch_between(int, int);
static LOGICAL is_contains_ast_between(int, int, int);
Expand All @@ -63,14 +58,18 @@ static LOGICAL Conflict_(int);
static LOGICAL is_same_idx(int, int);
static LOGICAL is_dominator_fg(int, int);
static LOGICAL must_follow(int, int, int, int);
static int find_lp(int);
#if DEBUG
int find_lp(int);
#endif
static void init_optsum(void);
#if DEBUG
static void optsummary(void);
#endif
static void alloc2ast(void);
static void opt_allocate(void);
static LOGICAL is_same_def(int, int);
#if DEBUG
LOGICAL is_same_def(int, int);
#endif
static LOGICAL is_safe_copy(int);
static LOGICAL is_allocatable_assign(int ast);
static int propagate_bound(LITEMF *defs_to_propagate, int bound);
Expand All @@ -82,16 +81,6 @@ static LOGICAL independent_commtype(int, int);
static LOGICAL is_olap_conflict(int, int);
static LOGICAL is_pcalls(int, int);
static void forall_make_same_idx(int);
static void eliminate_ownerproc(void);
static void gather_ownerproc(int atyp, int lp);
static void share_ownerproc(void);
static void transform_ownerproc(void);
static void barrier_opt(void);
static void opt_anti_barrier(void);
static void opt_flow_barrier(void);
static LOGICAL can_reach_no_barrier(int fg1, int fg2);
static LOGICAL _can_reach(int fg1, int fg2);
static void omem_barrier(void);

#if DEBUG
static int dodebug = 0;
Expand Down Expand Up @@ -1790,7 +1779,8 @@ is_same_array_alignment_for_schedule(int sptr, int sptr1)
return TRUE;
}

static int
#if DEBUG
int
find_lp(int std)
{
int i;
Expand All @@ -1806,6 +1796,7 @@ find_lp(int std)
assert(0, "find_lp: loop not found", std, 3);
return 0;
}
#endif

static void
eliminate_alloc(int lp, int lp1, int rt_std, int rt1_std)
Expand Down Expand Up @@ -3229,7 +3220,8 @@ is_safe_copy(int deflist)
return TRUE;
} /* is_safe_copy */

static LOGICAL
#if DEBUG
LOGICAL
is_same_def(int def, int def1)
{
int std, std1;
Expand Down Expand Up @@ -3270,6 +3262,7 @@ is_same_def(int def, int def1)

return TRUE;
}
#endif

/* This routine is checks that def has only one definition and
* src of that definition is a constant; if so, it returns
Expand Down
43 changes: 20 additions & 23 deletions tools/flang1/flang1exe/datadep.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "soc.h"
#include "fdirect.h"
#include "extern.h"
#include "ilidir.h" /* for open_pragma, close_pragma */

#if DEBUG
#define TRACE0(s) \
Expand Down Expand Up @@ -131,7 +132,7 @@
#endif

#if DEBUG
static ISZ_T
ISZ_T
DBGcnst(int s)
{
ISZ_T yy;
Expand Down Expand Up @@ -182,7 +183,6 @@ static void build_loop_dd(int loop);
static void dd_compute(void);
void dd_edge(int src, int sink, DIRVEC vec);
static void dd_succ(int loop);
static void dd_exact();

static void resolve_vv(void);
static void resolve_pv(void);
Expand Down Expand Up @@ -754,7 +754,6 @@ static void
resolve_pv(void)
{
int ptr, var;
int sym;

/* use a combination of optimizer utilities & stolen optimizer code */
if (NME_TYPE(ddinfo.basenm1) == NT_IND) {
Expand Down Expand Up @@ -819,9 +818,8 @@ resolve_vv(void)
int nm1, nm2;
DIRVEC dir;
int buf1[MAXNMESIZ], buf2[MAXNMESIZ];
int i, end;
int i;
int j;
DV *p, *q, *q1, *p1;

/* check for both scalar */
if (MR_SCALR(ddinfo.mr1) && MR_SCALR(ddinfo.mr2)) {
Expand Down Expand Up @@ -1157,7 +1155,6 @@ bound_add(int *ibound, LOGICAL upflag, int var)
BOUND b1;
BOUND b2;
int j, k;
int d1, d2;
int icon0 = ad_icon(0);

/* express the bound in terms of the free variables */
Expand Down Expand Up @@ -1191,7 +1188,6 @@ static LOGICAL
check_bounds(void)
{
int k;
int d1, d2;
BOUND *p, *q;

/* compare bounds from nfree down */
Expand Down Expand Up @@ -1289,9 +1285,8 @@ do_subscript(int nsubs)
int i, j, k, k1, bnd, n1;
int q, d1, d2, sgn, sc, ili;
int d;
int t, t1;
int stride1, stride2;
DIRVEC vec, vec1, vec2;
int t;
DIRVEC vec, vec1;
int icon0, icon1, iconneg1;
int sub;
int invar1, invar2;
Expand All @@ -1315,7 +1310,7 @@ do_subscript(int nsubs)
break;
}
if (SB_STRIDE(ddinfo.subs1 - sub)[i] < 0 ||
SB_STRIDE(ddinfo.subs1 - sub)[i] >= astb.stg_avail) {
SB_STRIDE(ddinfo.subs1 - sub)[i] >= (int)astb.stg_avail) {
fprintf(stderr, "sub=%d,ddinfo.subs1=%d,i=%d,SB_STRICE(%d)[%d]=%d\n",
sub, ddinfo.subs1, i, ddinfo.subs1 - sub, i,
SB_STRIDE(ddinfo.subs1 - sub)[i]);
Expand All @@ -1329,7 +1324,7 @@ do_subscript(int nsubs)
break;
}
if (SB_STRIDE(ddinfo.subs2 - sub)[i] < 0 ||
SB_STRIDE(ddinfo.subs2 - sub)[i] >= astb.stg_avail) {
SB_STRIDE(ddinfo.subs2 - sub)[i] >= (int)astb.stg_avail) {
fprintf(stderr, "sub=%d,ddinfo.subs2=%d,i=%d,SB_STRICE(%d)[%d]=%d\n",
sub, ddinfo.subs2, i, ddinfo.subs2 - sub, i,
SB_STRIDE(ddinfo.subs2 - sub)[i]);
Expand Down Expand Up @@ -2154,7 +2149,7 @@ mkSub(int astliTriples, int sub, int astmpyr, int ast)
{
int i;
int astli;
int aststride, astbase, astid, astcnst;
int aststride, astbase;
LOGICAL bLinear;

switch (A_TYPEG(ast)) {
Expand Down Expand Up @@ -2290,7 +2285,7 @@ static int
fill_subscripts(int astRef, int mr, int subStart, int ntriples,
int astliTriples)
{
int n, asd, ndim, sub, i;
int n, asd, ndim, sub;
switch (A_TYPEG(astRef)) {
case A_ID:
n = 0;
Expand Down Expand Up @@ -2351,7 +2346,7 @@ dd_array_conflict(int astliTriples, int astArrSrc, int astArrSink,
int astli;
int lp, lpOuter;
int sub, nsubsSrc, nsubsSink, subStart, nsubs;
int astTriple, astSub;
int astTriple;
int asdSrc, asdSink, aSrc, aSink, nSrc, nSink;
int mrSink, mrSrc;

Expand Down Expand Up @@ -2781,7 +2776,7 @@ sum(ARITH_LIST lst)
static ARITH_LIST
distrib(int ili, int mpyr)
{
int ili1, ili2, ilitmp;
int ili2, ilitmp;
int opc, opc1;
ARITH_LIST l1, l2, l;

Expand Down Expand Up @@ -2963,11 +2958,9 @@ ili_symbolic(int ili)
{
/* perform symbolic manipulation on ili to simplify its form */
int opc;
int icon0 = ad_icon(0L), icon1 = ad_icon(1L);
int icon1 = ad_icon(1L);
ARITH_LIST lst1, lst2;
int ilires;
int i;
LOGICAL changed;

if (use_visit && ILI_REPL(ili))
return ILI_REPL(ili);
Expand Down Expand Up @@ -3052,8 +3045,8 @@ ad1ili(int opc, int ast1)
static int
ad2ili(int opc, int ast1, int ast2)
{
int optype;
int dtype;
int optype = 0;
int dtype = 0;
int astx;

switch (opc) {
Expand Down Expand Up @@ -3187,7 +3180,8 @@ dirv_print(DIRVEC dir)
void
dump_dd(DDEDGE *p)
{
static char *types[] = {"flow", "anti", "outp", "????"};
static const char *types[] = {"flow", "anti",
"outp", "????"};

for (; p != 0; p = DD_NEXT(p)) {
fprintf(gbl.dbgfil, " %4d %4s %-32s\n", DD_SINK(p), types[DD_TYPE(p)],
Expand Down Expand Up @@ -3287,8 +3281,9 @@ dump_two_bound(BOUND *p, BOUND *q, int k, LOGICAL btype)
fprintf(gbl.dbgfil, "\n");
}

#if DEBUG
/* Dump a list of arithmetic terms. */
static void
void
dump_termlist(ARITH_LIST lst)
{
ARITH_LIST l;
Expand All @@ -3310,3 +3305,5 @@ dump_termlist(ARITH_LIST lst)
#endif

#endif

#endif
Loading

0 comments on commit e939d38

Please sign in to comment.