Skip to content

Commit e71f80e

Browse files
Remove COB_NON_ALIGNED and related code (#511)
* [Fix]: remove COB_NON_ALIGNED and related code * [Refactor]: refactor C files to resolve cpp-check warnings * [Refactor]: refactor codegen.c * [Update]: run static analysis on Ubuntu 22.04 * [Update]: `runs-on: ubuntu-22.04`
1 parent 996f66f commit e71f80e

File tree

4 files changed

+18
-280
lines changed

4 files changed

+18
-280
lines changed

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permissions:
88

99
jobs:
1010
static_analysis:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212
steps:
1313
# Checkout opensource COBOL
1414
- name: Checkout opensource COBOL 4J

cobj/cobj.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@
3636
#include "lib/gettext.h"
3737
#endif
3838

39-
#if !defined(__i386__) && !defined(__x86_64__) && !defined(__powerpc__) && \
40-
!defined(__powerpc64__) && !defined(__ppc__) && !defined(__amd64__)
41-
#define COB_NON_ALIGNED
42-
/* Some DEC Alphas can only directly load shorts at 4-byte aligned addresses */
43-
#ifdef __alpha
44-
#define COB_SHORT_BORK
45-
#endif
46-
#endif
47-
4839
#define ABORT() cobc_abort(__FILE__, __LINE__)
4940

5041
#define CB_FORMAT_FIXED 0

cobj/codegen.c

Lines changed: 4 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,25 +1288,13 @@ static void joutput_integer(cb_tree x) {
12881288
return;
12891289

12901290
case CB_USAGE_POINTER:
1291-
#ifdef COB_NON_ALIGNED
1292-
joutput("(cob_get_pointer (");
1293-
joutput_data(x);
1294-
joutput("))");
1295-
#else
12961291
joutput("(*(unsigned char **) (");
12971292
joutput_data(x);
12981293
joutput("))");
1299-
#endif
13001294
return;
13011295

13021296
case CB_USAGE_PROGRAM_POINTER:
1303-
#ifdef COB_NON_ALIGNED
1304-
joutput("(cob_get_prog_pointer (");
13051297
joutput_data(x);
1306-
joutput("))");
1307-
#else
1308-
joutput_data(x);
1309-
#endif
13101298
return;
13111299

13121300
case CB_USAGE_DISPLAY:
@@ -1337,19 +1325,7 @@ static void joutput_integer(cb_tree x) {
13371325
}
13381326
return;
13391327
}
1340-
#ifdef COB_NON_ALIGNED
1341-
if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 &&
1342-
(
1343-
#ifdef COB_SHORT_BORK
1344-
(f->size == 2 && (f->offset % 4 == 0)) ||
1345-
#else
1346-
(f->size == 2 && (f->offset % 2 == 0)) ||
1347-
#endif
1348-
(f->size == 4 && (f->offset % 4 == 0)) ||
1349-
(f->size == 8 && (f->offset % 8 == 0)))) {
1350-
#else
13511328
if (f->size == 2 || f->size == 4 || f->size == 8) {
1352-
#endif
13531329
if (f->flag_binary_swap) {
13541330
joutput_data(x);
13551331
if (!integer_reference_flag) {
@@ -1998,13 +1974,6 @@ static void joutput_cond(cb_tree x, int save_flag) {
19981974
if (save_flag) {
19991975
joutput("(ret = ");
20001976
}
2001-
//#ifdef __GNUC__
2002-
// joutput_indent ("({");
2003-
//#else
2004-
// inside_stack[inside_check] = 0;
2005-
// ++inside_check;
2006-
// joutput ("(\n");
2007-
//#endif
20081977
joutput_indent("(new GetInt() {");
20091978
joutput_indent_level += 2;
20101979
joutput_indent("public int run(){");
@@ -2016,12 +1985,6 @@ static void joutput_cond(cb_tree x, int save_flag) {
20161985
}
20171986
joutput_stmt(CB_VALUE(x), JOUTPUT_STMT_DEFAULT);
20181987
}
2019-
//#ifdef __GNUC__
2020-
// joutput_indent ("})");
2021-
//#else
2022-
// --inside_check;
2023-
// joutput (")");
2024-
//#endif
20251988
joutput_indent_level -= 2;
20261989
joutput_indent("}");
20271990
joutput_indent_level -= 2;
@@ -2777,11 +2740,8 @@ static void joutput_search(struct cb_search *p) {
27772740
static void joutput_call(struct cb_call *p) {
27782741
cb_tree x;
27792742
cb_tree l;
2780-
struct cb_literal *lp;
2781-
char *callp;
27822743
struct cb_field *f;
27832744
char *system_call = NULL;
2784-
struct system_table *psyst;
27852745
size_t n;
27862746
size_t retptr;
27872747
int dynamic_link = 1;
@@ -2793,8 +2753,9 @@ static void joutput_call(struct cb_call *p) {
27932753
}
27942754
/* System routine entry points */
27952755
if (p->is_system) {
2796-
lp = CB_LITERAL(p->name);
2797-
psyst = (struct system_table *)&system_tab[0];
2756+
struct cb_literal *lp = CB_LITERAL(p->name);
2757+
2758+
struct system_table *psyst = (struct system_table *)&system_tab[0];
27982759
for (; psyst->syst_name; psyst++) {
27992760
if (!strcmp((const char *)lp->data, (const char *)psyst->syst_name)) {
28002761
system_call = (char *)psyst->syst_call;
@@ -2809,12 +2770,6 @@ static void joutput_call(struct cb_call *p) {
28092770
}
28102771

28112772
/* Local variables */
2812-
#ifdef COB_NON_ALIGNED
2813-
if (dynamic_link && retptr) {
2814-
// output_line ("void *temptr;");
2815-
}
2816-
#endif
2817-
28182773
if (CB_REFERENCE_P(p->name) && CB_FIELD_P(CB_REFERENCE(p->name)->value) &&
28192774
CB_FIELD(CB_REFERENCE(p->name)->value)->usage ==
28202775
CB_USAGE_PROGRAM_POINTER) {
@@ -2984,6 +2939,7 @@ static void joutput_call(struct cb_call *p) {
29842939
}
29852940
}
29862941
} else {
2942+
char *callp;
29872943
/* Dynamic link */
29882944
if (CB_LITERAL_P(p->name)) {
29892945
callp = cb_encode_program_id((char *)(CB_LITERAL(p->name)->data));
@@ -3205,13 +3161,6 @@ static void joutput_call(struct cb_call *p) {
32053161
joutput_stmt(cb_build_move(current_prog->cb_return_code, p->returning),
32063162
JOUTPUT_STMT_DEFAULT);
32073163
suppress_warn = 0;
3208-
#ifdef COB_NON_ALIGNED
3209-
} else {
3210-
// output_prefix ();
3211-
// output ("memcpy (");
3212-
// output_data (p->returning);
3213-
// output (", &temptr, %d);\n", sizeof (void *));
3214-
#endif
32153164
}
32163165
}
32173166
if (p->stmt2) {
@@ -3595,9 +3544,6 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) {
35953544
struct cb_label *lp;
35963545
struct cb_assign *ap;
35973546
struct cb_if *ip;
3598-
#ifdef COB_NON_ALIGNED
3599-
struct cb_cast *cp;
3600-
#endif
36013547
int code;
36023548
int putParen = 0;
36033549

@@ -3818,80 +3764,7 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) {
38183764
break;
38193765
case CB_TAG_ASSIGN:
38203766
ap = CB_ASSIGN(x);
3821-
#ifdef COB_NON_ALIGNED
3822-
/* Nonaligned */
3823-
if (CB_TREE_CLASS(ap->var) == CB_CLASS_POINTER ||
3824-
CB_TREE_CLASS(ap->val) == CB_CLASS_POINTER) {
3825-
/* Pointer assignment */
3826-
joutput_indent("{");
3827-
joutput_line("void *temp_ptr;");
38283767

3829-
/* temp_ptr = source address; */
3830-
joutput_prefix();
3831-
if (ap->val == cb_null || ap->val == cb_zero) {
3832-
/* MOVE NULL ... */
3833-
joutput("temp_ptr = 0;\n");
3834-
} else if (CB_TREE_TAG(ap->val) == CB_TAG_CAST) {
3835-
/* MOVE ADDRESS OF val ... */
3836-
cp = CB_CAST(ap->val);
3837-
joutput("temp_ptr = ");
3838-
switch (cp->type) {
3839-
case CB_CAST_ADDRESS:
3840-
joutput_data(cp->val);
3841-
break;
3842-
case CB_CAST_PROGRAM_POINTER:
3843-
joutput_func_1("CobolResolve.resolveToPointer", ap->val);
3844-
break;
3845-
default:
3846-
fprintf(stderr, "Unexpected cast type %d\n", cp->type);
3847-
ABORT();
3848-
}
3849-
joutput(";\n");
3850-
} else {
3851-
/* MOVE val ... */
3852-
joutput("LIBCOB.memcpy(&temp_ptr, ");
3853-
joutput_data(ap->val);
3854-
joutput(", sizeof(temp_ptr));\n");
3855-
}
3856-
3857-
/* destination address = temp_ptr; */
3858-
joutput_prefix();
3859-
if (CB_TREE_TAG(ap->var) == CB_TAG_CAST) {
3860-
/* SET ADDRESS OF var ... */
3861-
cp = CB_CAST(ap->var);
3862-
if (cp->type != CB_CAST_ADDRESS) {
3863-
fprintf(stderr, "Unexpected tree type %d\n", cp->type);
3864-
ABORT();
3865-
}
3866-
joutput_data(cp->val);
3867-
joutput(" = temp_ptr;\n");
3868-
} else {
3869-
/* MOVE ... TO var */
3870-
joutput("LIBCOB.memcpy(");
3871-
joutput_data(ap->var);
3872-
joutput(", &temp_ptr, sizeof(temp_ptr));\n");
3873-
}
3874-
3875-
joutput_indent("}");
3876-
} else {
3877-
/* Numeric assignment */
3878-
joutput_prefix();
3879-
3880-
int tmp_flag = integer_reference_flag;
3881-
integer_reference_flag = 1;
3882-
joutput_integer(ap->var);
3883-
integer_reference_flag = tmp_flag;
3884-
joutput(".set(");
3885-
++index_read_flag;
3886-
joutput_integer(ap->val);
3887-
--index_read_flag;
3888-
if (output_type == JOUTPUT_STMT_TRIM) {
3889-
joutput(")\n");
3890-
} else {
3891-
joutput(");\n");
3892-
}
3893-
}
3894-
#else /* Nonaligned */
38953768
joutput_prefix();
38963769

38973770
int tmp_flag = integer_reference_flag;
@@ -3923,7 +3796,6 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) {
39233796
} else {
39243797
joutput(");\n");
39253798
}
3926-
#endif /* Nonaligned */
39273799
break;
39283800
case CB_TAG_INITIALIZE:
39293801
joutput_initialize(CB_INITIALIZE(x));

0 commit comments

Comments
 (0)