Skip to content

Commit 6bdd3d3

Browse files
committed
Clean const-correctness issues with the VERSION data structure
1 parent b84295a commit 6bdd3d3

File tree

18 files changed

+257
-230
lines changed

18 files changed

+257
-230
lines changed

tools/flang1/flang1exe/version.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
/* COPYRIGHT is extern to make it easy to find in symbol table */
2626
/* it also has extra space to patch in interesting stuff */
27-
char COPYRIGHT[128] =
27+
const char COPYRIGHT[128] =
2828
"";
2929

3030
VERSION version = {LANGUAGE, VHOST, VSN, BLD, DVSN, TARGET, PRODUCT, COPYRIGHT};
3131

32-
char *
32+
const char *
3333
get_version_string(void)
3434
{
3535
static char buf[128];

tools/flang1/flang1exe/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ typedef struct {
2323
char *dvsn; /* date-based version number */
2424
char *target; /* target compiler */
2525
char *product; /* product designation */
26-
char *copyright;
26+
const char *copyright;
2727
} VERSION;
2828

2929
extern VERSION version;
3030

31-
char *get_version_string(void);
31+
const char *get_version_string(void);
3232

tools/flang2/flang2exe/cgmain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3726,7 +3726,7 @@ make_stmt(STMT_Type stmt_type, int ilix, bool deletable, SPTR next_bih_label,
37263726
LL_InstrListFlags store_flags = InstrListFlagsNull;
37273727
LL_Type *int_llt = NULL;
37283728
LL_Type *v4_llt = NULL;
3729-
msz = (MSZ)ILI_MSZ_OF_ST(ilix); // ???
3729+
msz = ILI_MSZ_OF_ST(ilix);
37303730
vect_dtype = ili_get_vect_dtype(ilix);
37313731
#if defined(TARGET_LLVM_ARM)
37323732
if (vect_dtype) {
@@ -7328,7 +7328,7 @@ gen_llvm_cmpxchg(int ilix)
73287328
CMPXCHG_MEMORY_ORDER order;
73297329

73307330
/* Construct aggregate type for result of cmpxchg. */
7331-
MSZ msz = (MSZ)atomic_info(ilix).msz; // ???
7331+
MSZ msz = atomic_info(ilix).msz;
73327332
LL_Module *module = cpu_llvm_module;
73337333
elements[0] = make_type_from_msz(msz);
73347334
elements[1] = ll_create_basic_type(module, LL_I1, 0);
@@ -7876,7 +7876,7 @@ gen_llvm_expr(int ilix, LL_Type *expected_type)
78767876
LL_InstrListFlags flags;
78777877
ld_ili = ILI_OPND(ilix, 1);
78787878
nme_ili = ILI_OPND(ilix, 2);
7879-
msz = (MSZ)ILI_MSZ_OF_LD(ilix); // ???
7879+
msz = ILI_MSZ_OF_LD(ilix);
78807880
if (opc == IL_ATOMICLDSP) {
78817881
fromdtype = DT_FLOAT;
78827882
todtype = DT_INT;
@@ -12977,7 +12977,7 @@ insert_entry_label(int ilt)
1297712977
INSTR_LIST *Curr_Instr = gen_instr(I_NONE, NULL, NULL, make_label_op(sptr));
1297812978
ad_instr(0, Curr_Instr);
1297912979
llvm_info.return_ll_type = make_lltype_from_dtype(
12980-
gbl.arets ? DT_INT : get_return_type(sptr)); // ???: possible bug
12980+
gbl.arets ? DT_INT : get_return_type(sptr)); // FIXME: possible bug
1298112981
}
1298212982

1298312983
void

tools/flang2/flang2exe/expand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ exp_mac(ILM_OP opc, ILM *ilmp, int curilm)
19391939
while (ilicnt-- > 0) {
19401940
ilmtpl = (ILMMAC *)&ilmtp[pattern];
19411941

1942-
newili.opc = ilmtpl->opc; /* get ili opcode */
1942+
newili.opc = (ILI_OP) ilmtpl->opc; /* get ili opcode */ // ???
19431943

19441944
/* Loop for each operand in this ili template */
19451945
for (i = 0, noprs = ilis[newili.opc].oprs; noprs > 0; ++i, --noprs) {

tools/flang2/flang2exe/expsmp.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
#include "llmputil.h"
4545
#include "symfun.h"
4646

47+
#ifdef __cplusplus
48+
inline SPTR GetPARUPLEVEL(SPTR sptr) {
49+
return static_cast<SPTR>(PARUPLEVELG(sptr));
50+
}
51+
#undef PARUPLEVELG
52+
#define PARUPLEVELG GetPARUPLEVEL
53+
#endif
54+
4755
static void incrOutlinedCnt(void);
4856
static void decrOutlinedCnt(void);
4957
static int getOutlinedTemp(char *, int);
@@ -144,7 +152,7 @@ typedef struct SectionsWrk_t {
144152
SPTR lb; /* start at 0 */
145153
SPTR ub; /* number of sections */
146154
SPTR st; /* stride 1 */
147-
int last; /* flag for last section */
155+
SPTR last; /* flag for last section */
148156
int cnt; /* running count */
149157
int bbih; /* start block for sections */
150158
} SectionsWrk_t;
@@ -809,7 +817,7 @@ setTaskloopVars(SPTR lb, SPTR ub, SPTR stride, SPTR lastitr)
809817
/* This code is in an outlined taskloop routine.
810818
* Load taskloop vars from arg1 to local/private vars.
811819
*/
812-
arg = (SPTR)ll_get_hostprog_arg(GBL_CURRFUNC, 2); // ???
820+
arg = ll_get_hostprog_arg(GBL_CURRFUNC, 2);
813821
basenm = addnme(NT_VAR, arg, 0, 0);
814822
baseili = ad_acon(arg, 0);
815823
baseili = mk_address(arg);
@@ -943,7 +951,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
943951
LLTask *task;
944952
bool is_cmblk;
945953
static sptrListT *copysptr_list = NULL;
946-
static int uplevel_sptr;
954+
static SPTR uplevel_sptr;
947955
static SPTR single_thread;
948956
static SPTR in_single;
949957
SPTR nlower, nupper, nstride;
@@ -1406,7 +1414,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
14061414
const int upper = ILM_OPND(ilmp, 2);
14071415
const int stride = ILM_OPND(ilmp, 3);
14081416
const int last = ILM_OPND(ilmp, 4);
1409-
const DTYPE dtype = (DTYPE)ILM_OPND(ilmp, 5); // ???
1417+
const DTYPE dtype = ILM_DTyOPND(ilmp, 5);
14101418
ili = ll_make_kmpc_dispatch_next(lower, upper, stride, last, dtype);
14111419
iltb.callfg = 1;
14121420
chk_block(ili);
@@ -1467,9 +1475,9 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
14671475
nupper = ILM_SymOPND(ilmp, 2);
14681476
nstride = ILM_SymOPND(ilmp, 3);
14691477
if (!XBIT(183, 0x100000)) {
1470-
nlower = (SPTR)getccsym_copy(nlower); // ???
1471-
nupper = (SPTR)getccsym_copy(nupper); // ???
1472-
nstride = (SPTR)getccsym_copy(nstride); // ???
1478+
nlower = getccsym_copy(nlower);
1479+
nupper = getccsym_copy(nupper);
1480+
nstride = getccsym_copy(nstride);
14731481
ENCLFUNCP(nlower, GBL_CURRFUNC);
14741482
ENCLFUNCP(nupper, GBL_CURRFUNC);
14751483
ENCLFUNCP(nstride, GBL_CURRFUNC);
@@ -1482,7 +1490,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
14821490
loop_args.stride = nstride;
14831491
loop_args.chunk = ILM_SymOPND(ilmp, 4);
14841492
loop_args.last = ILM_OPND(ilmp, 5);
1485-
loop_args.dtype = (DTYPE)ILM_OPND(ilmp, 6); // ???
1493+
loop_args.dtype = ILM_DTyOPND(ilmp, 6);
14861494
loop_args.sched = (kmpc_sched_e)ILM_OPND(ilmp, 7);
14871495
sched = mp_sched_to_kmpc_sched(loop_args.sched);
14881496
switch (sched) {
@@ -1530,7 +1538,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
15301538
loop_args.chunk = ILM_SymOPND(ilmp, 4);
15311539
loop_args.last = ILM_OPND(ilmp, 5);
15321540
loop_args.upperd = ILM_OPND(ilmp, 6);
1533-
loop_args.dtype = (DTYPE)ILM_OPND(ilmp, 7); // ???
1541+
loop_args.dtype = ILM_DTyOPND(ilmp, 7);
15341542
loop_args.sched = (kmpc_sched_e)ILM_OPND(ilmp, 8);
15351543
sched = mp_sched_to_kmpc_sched(loop_args.sched);
15361544
switch (sched) {
@@ -1561,7 +1569,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
15611569
break;
15621570
const int sched = mp_sched_to_kmpc_sched(ILM_OPND(ilmp, 2));
15631571
if (sched == KMP_ORD_STATIC || sched == KMP_ORD_DYNAMIC_CHUNKED) {
1564-
ili = ll_make_kmpc_dispatch_fini((DTYPE)ILM_OPND(ilmp, 1)); // ???
1572+
ili = ll_make_kmpc_dispatch_fini(ILM_DTyOPND(ilmp, 1));
15651573
iltb.callfg = 1;
15661574
chk_block(ili);
15671575
} else if (sched == KMP_SCH_STATIC || sched == KMP_SCH_STATIC_CHUNKED ||
@@ -2676,8 +2684,8 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
26762684
if (ISTASKDUPG(GBL_CURRFUNC)) {
26772685
INT offset;
26782686
int offset_sptr, ioffset, acon, load, nme;
2679-
SPTR secarg = (SPTR)ll_get_hostprog_arg(GBL_CURRFUNC, 1); // ???
2680-
SPTR lastitr = (SPTR)ll_get_hostprog_arg(GBL_CURRFUNC, 3); // ???
2687+
SPTR secarg = ll_get_hostprog_arg(GBL_CURRFUNC, 1);
2688+
SPTR lastitr = ll_get_hostprog_arg(GBL_CURRFUNC, 3);
26812689
offset_sptr = ILM_OPND(ilmp, 1);
26822690
offset = get_isz_cval(offset_sptr);
26832691
/* load from 3rd argument(int litr) into 1st argument at offset */

tools/flang2/flang2exe/ili-rewrite.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ int
384384
update_ili_operand(int ili, int opnd_index, int new_opnd)
385385
{
386386
if (ILI_OPND(ili, opnd_index) != new_opnd) {
387-
int j, opc = ILI_OPC(ili);
387+
int j;
388+
ILI_OP opc = ILI_OPC(ili);
388389
int opnds = IL_OPRS(opc);
389390
ILI newili;
390391
newili.opc = opc;

tools/flang2/flang2exe/ili.h

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ typedef unsigned short ILI_OP;
4040
/***** ILI Declarations *****/
4141

4242
typedef struct {
43-
unsigned short opc; /**< Logically an ILI_OP */
43+
ILI_OP opc;
4444
/* practically all hosts will insert 2 bytes of padding here. */
4545
int hshlnk;
4646
int count;
@@ -62,7 +62,7 @@ extern ILIB ilib;
6262

6363
#define ILI_REPL(i) ilib.stg_base[i].count
6464
#define ILI_OPC(i) ((ILI_OP)ilib.stg_base[i].opc)
65-
#define ILI_OPCP(i, j) ilib.stg_base[i].opc = ((unsigned short)j)
65+
#define ILI_OPCP(i, j) ilib.stg_base[i].opc = (j)
6666
#define ILI_HSHLNK(i) ilib.stg_base[i].hshlnk
6767
#define ILI_VISIT(i) ilib.stg_base[i].visit
6868
#define ILI_ALT(i) ilib.stg_base[i].alt
@@ -398,39 +398,6 @@ typedef enum CC_RELATION {
398398
#define SUF_i64x2 0x1000 /* " " " " " " */
399399
#define SUF_i64x4 0x2000 /* " " " " " " */
400400

401-
/*
402-
* Memory reference size/type codes.
403-
*
404-
* Legacy assumptions observed:
405-
* - (code & 3) < 2 if and only if the type size is 1 or 2 bytes.
406-
* - (code & 3) == log2(type size) if the type size is 1, 2, 4, or 8 bytes.
407-
*/
408-
typedef enum MSZ {
409-
MSZ_SBYTE = 0x00, /* signed byte */
410-
MSZ_SHWORD = 0x01, /* signed 16-bit short */
411-
MSZ_UBYTE = 0x04, /* unsigned byte */
412-
MSZ_UHWORD = 0x05, /* unsigned 16-bit short */
413-
414-
/* Codes for types larger than two bytes. These are all distinct values
415-
* suitable for use as case labels in switches. The holes in this sequence
416-
* of code values avoid violating the first legacy assumption described above.
417-
*/
418-
MSZ_SWORD = 0x02, /* signed 32-bit int */
419-
MSZ_SLWORD = 0x03, /* signed 64-bit long */
420-
MSZ_UWORD = 0x06, /* unsigned 32-bit int */
421-
MSZ_ULWORD = 0x07, /* unsigned 64-bit long */
422-
MSZ_FWORD = 0x0a, /* 32-bit single precision float */
423-
MSZ_FLWORD = 0x0b, /* 64-bit double precision float */
424-
MSZ_I8 = 0x0f, /* distinct 64-bit integer type */
425-
MSZ_PTR = 0x13, /* distinct 64-bit pointer type */
426-
MSZ_F10 = 0x16, /* X87 FPU 80-bit extended precision */
427-
MSZ_F16 = 0x17, /* 128-bit quad precision float */
428-
MSZ_F32 = 0x1a, /* 256-bit float */
429-
MSZ_F8x2 = 0x1b, /* 128-bit double-double float */
430-
431-
MSZ_UNDEF = 0xff, /* undefined MSZ code */
432-
} MSZ;
433-
434401
#ifdef __cplusplus
435402
inline MSZ MSZ_ILI_OPND(int i, int opn) {
436403
return static_cast<MSZ>(ILI_OPND(i, opn));
@@ -527,6 +494,19 @@ extern bool share_qjsr_ili; /* defd in iliutil.c */
527494

528495
#include "iliutil.h"
529496

497+
#ifdef __cplusplus
498+
inline MSZ GetILI_MSZ_OF_Load(int ilix) {
499+
return static_cast<MSZ>(ILI_MSZ_OF_LD(ilix));
500+
}
501+
#undef ILI_MSZ_OF_LD
502+
#define ILI_MSZ_OF_LD GetILI_MSZ_OF_Load
503+
inline MSZ GetILI_MSZ_OF_Store(int ilix) {
504+
return static_cast<MSZ>(ILI_MSZ_OF_ST(ilix));
505+
}
506+
#undef ILI_MSZ_OF_ST
507+
#define ILI_MSZ_OF_ST GetILI_MSZ_OF_Store
508+
#endif
509+
530510
#endif /* !ILITP_UTIL */
531511

532512
#endif /* ILI_H_ */

0 commit comments

Comments
 (0)