diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 23b6c0f9..36280658 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -8,7 +8,7 @@ permissions: jobs: static_analysis: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: # Checkout opensource COBOL - name: Checkout opensource COBOL 4J diff --git a/cobj/cobj.h b/cobj/cobj.h index 21456ca1..792f8b52 100644 --- a/cobj/cobj.h +++ b/cobj/cobj.h @@ -36,15 +36,6 @@ #include "lib/gettext.h" #endif -#if !defined(__i386__) && !defined(__x86_64__) && !defined(__powerpc__) && \ - !defined(__powerpc64__) && !defined(__ppc__) && !defined(__amd64__) -#define COB_NON_ALIGNED -/* Some DEC Alphas can only directly load shorts at 4-byte aligned addresses */ -#ifdef __alpha -#define COB_SHORT_BORK -#endif -#endif - #define ABORT() cobc_abort(__FILE__, __LINE__) #define CB_FORMAT_FIXED 0 diff --git a/cobj/codegen.c b/cobj/codegen.c index cbafab1b..b580fd58 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -1288,25 +1288,13 @@ static void joutput_integer(cb_tree x) { return; case CB_USAGE_POINTER: -#ifdef COB_NON_ALIGNED - joutput("(cob_get_pointer ("); - joutput_data(x); - joutput("))"); -#else joutput("(*(unsigned char **) ("); joutput_data(x); joutput("))"); -#endif return; case CB_USAGE_PROGRAM_POINTER: -#ifdef COB_NON_ALIGNED - joutput("(cob_get_prog_pointer ("); joutput_data(x); - joutput("))"); -#else - joutput_data(x); -#endif return; case CB_USAGE_DISPLAY: @@ -1337,19 +1325,7 @@ static void joutput_integer(cb_tree x) { } return; } -#ifdef COB_NON_ALIGNED - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - ( -#ifdef COB_SHORT_BORK - (f->size == 2 && (f->offset % 4 == 0)) || -#else - (f->size == 2 && (f->offset % 2 == 0)) || -#endif - (f->size == 4 && (f->offset % 4 == 0)) || - (f->size == 8 && (f->offset % 8 == 0)))) { -#else if (f->size == 2 || f->size == 4 || f->size == 8) { -#endif if (f->flag_binary_swap) { joutput_data(x); if (!integer_reference_flag) { @@ -1998,13 +1974,6 @@ static void joutput_cond(cb_tree x, int save_flag) { if (save_flag) { joutput("(ret = "); } - //#ifdef __GNUC__ - // joutput_indent ("({"); - //#else - // inside_stack[inside_check] = 0; - // ++inside_check; - // joutput ("(\n"); - //#endif joutput_indent("(new GetInt() {"); joutput_indent_level += 2; joutput_indent("public int run(){"); @@ -2016,12 +1985,6 @@ static void joutput_cond(cb_tree x, int save_flag) { } joutput_stmt(CB_VALUE(x), JOUTPUT_STMT_DEFAULT); } - //#ifdef __GNUC__ - // joutput_indent ("})"); - //#else - // --inside_check; - // joutput (")"); - //#endif joutput_indent_level -= 2; joutput_indent("}"); joutput_indent_level -= 2; @@ -2777,11 +2740,8 @@ static void joutput_search(struct cb_search *p) { static void joutput_call(struct cb_call *p) { cb_tree x; cb_tree l; - struct cb_literal *lp; - char *callp; struct cb_field *f; char *system_call = NULL; - struct system_table *psyst; size_t n; size_t retptr; int dynamic_link = 1; @@ -2793,8 +2753,9 @@ static void joutput_call(struct cb_call *p) { } /* System routine entry points */ if (p->is_system) { - lp = CB_LITERAL(p->name); - psyst = (struct system_table *)&system_tab[0]; + struct cb_literal *lp = CB_LITERAL(p->name); + + struct system_table *psyst = (struct system_table *)&system_tab[0]; for (; psyst->syst_name; psyst++) { if (!strcmp((const char *)lp->data, (const char *)psyst->syst_name)) { system_call = (char *)psyst->syst_call; @@ -2809,12 +2770,6 @@ static void joutput_call(struct cb_call *p) { } /* Local variables */ -#ifdef COB_NON_ALIGNED - if (dynamic_link && retptr) { - // output_line ("void *temptr;"); - } -#endif - if (CB_REFERENCE_P(p->name) && CB_FIELD_P(CB_REFERENCE(p->name)->value) && CB_FIELD(CB_REFERENCE(p->name)->value)->usage == CB_USAGE_PROGRAM_POINTER) { @@ -2984,6 +2939,7 @@ static void joutput_call(struct cb_call *p) { } } } else { + char *callp; /* Dynamic link */ if (CB_LITERAL_P(p->name)) { callp = cb_encode_program_id((char *)(CB_LITERAL(p->name)->data)); @@ -3205,13 +3161,6 @@ static void joutput_call(struct cb_call *p) { joutput_stmt(cb_build_move(current_prog->cb_return_code, p->returning), JOUTPUT_STMT_DEFAULT); suppress_warn = 0; -#ifdef COB_NON_ALIGNED - } else { - // output_prefix (); - // output ("memcpy ("); - // output_data (p->returning); - // output (", &temptr, %d);\n", sizeof (void *)); -#endif } } if (p->stmt2) { @@ -3595,9 +3544,6 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { struct cb_label *lp; struct cb_assign *ap; struct cb_if *ip; -#ifdef COB_NON_ALIGNED - struct cb_cast *cp; -#endif int code; int putParen = 0; @@ -3818,80 +3764,7 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { break; case CB_TAG_ASSIGN: ap = CB_ASSIGN(x); -#ifdef COB_NON_ALIGNED - /* Nonaligned */ - if (CB_TREE_CLASS(ap->var) == CB_CLASS_POINTER || - CB_TREE_CLASS(ap->val) == CB_CLASS_POINTER) { - /* Pointer assignment */ - joutput_indent("{"); - joutput_line("void *temp_ptr;"); - /* temp_ptr = source address; */ - joutput_prefix(); - if (ap->val == cb_null || ap->val == cb_zero) { - /* MOVE NULL ... */ - joutput("temp_ptr = 0;\n"); - } else if (CB_TREE_TAG(ap->val) == CB_TAG_CAST) { - /* MOVE ADDRESS OF val ... */ - cp = CB_CAST(ap->val); - joutput("temp_ptr = "); - switch (cp->type) { - case CB_CAST_ADDRESS: - joutput_data(cp->val); - break; - case CB_CAST_PROGRAM_POINTER: - joutput_func_1("CobolResolve.resolveToPointer", ap->val); - break; - default: - fprintf(stderr, "Unexpected cast type %d\n", cp->type); - ABORT(); - } - joutput(";\n"); - } else { - /* MOVE val ... */ - joutput("LIBCOB.memcpy(&temp_ptr, "); - joutput_data(ap->val); - joutput(", sizeof(temp_ptr));\n"); - } - - /* destination address = temp_ptr; */ - joutput_prefix(); - if (CB_TREE_TAG(ap->var) == CB_TAG_CAST) { - /* SET ADDRESS OF var ... */ - cp = CB_CAST(ap->var); - if (cp->type != CB_CAST_ADDRESS) { - fprintf(stderr, "Unexpected tree type %d\n", cp->type); - ABORT(); - } - joutput_data(cp->val); - joutput(" = temp_ptr;\n"); - } else { - /* MOVE ... TO var */ - joutput("LIBCOB.memcpy("); - joutput_data(ap->var); - joutput(", &temp_ptr, sizeof(temp_ptr));\n"); - } - - joutput_indent("}"); - } else { - /* Numeric assignment */ - joutput_prefix(); - - int tmp_flag = integer_reference_flag; - integer_reference_flag = 1; - joutput_integer(ap->var); - integer_reference_flag = tmp_flag; - joutput(".set("); - ++index_read_flag; - joutput_integer(ap->val); - --index_read_flag; - if (output_type == JOUTPUT_STMT_TRIM) { - joutput(")\n"); - } else { - joutput(");\n"); - } - } -#else /* Nonaligned */ joutput_prefix(); int tmp_flag = integer_reference_flag; @@ -3923,7 +3796,6 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { } else { joutput(");\n"); } -#endif /* Nonaligned */ break; case CB_TAG_INITIALIZE: joutput_initialize(CB_INITIALIZE(x)); diff --git a/cobj/typeck.c b/cobj/typeck.c index e94577ea..0de8269d 100644 --- a/cobj/typeck.c +++ b/cobj/typeck.c @@ -2239,13 +2239,9 @@ static cb_tree build_cond_88(cb_tree x) { } static cb_tree cb_build_optim_cond(struct cb_binary_op *p) { - struct cb_field *f; - struct cb_field *fy; - const char *s; - size_t n; if (CB_REF_OR_FIELD_P(p->y)) { - fy = cb_field(p->y); + struct cb_field *fy = cb_field(p->y); if (!fy->pic->have_sign && (fy->usage == CB_USAGE_BINARY || fy->usage == CB_USAGE_COMP_5 || fy->usage == CB_USAGE_COMP_X)) { @@ -2254,7 +2250,7 @@ static cb_tree cb_build_optim_cond(struct cb_binary_op *p) { } } if (CB_REF_OR_FIELD_P(p->x)) { - f = cb_field(p->x); + struct cb_field *f = cb_field(p->x); if (!f->pic->scale && f->usage == CB_USAGE_PACKED) { if (f->pic->digits < 10) { return cb_build_method_call_2("cmpInt", p->x, @@ -2291,31 +2287,9 @@ static cb_tree cb_build_optim_cond(struct cb_binary_op *p) { if (!f->pic->scale && (f->usage == CB_USAGE_BINARY || f->usage == CB_USAGE_COMP_5 || f->usage == CB_USAGE_INDEX || f->usage == CB_USAGE_COMP_X)) { - n = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + - (16 * (f->flag_binary_swap ? 1 : 0)); -#if defined(COB_NON_ALIGNED) && !defined(_MSC_VER) - switch (f->size) { - case 2: -#ifdef COB_SHORT_BORK - s = bin_compare_funcs[n]; - break; -#endif - case 4: - case 8: - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size) == 0) { - s = align_bin_compare_funcs[n]; - } else { - s = bin_compare_funcs[n]; - } - break; - default: - s = bin_compare_funcs[n]; - break; - } -#else - s = bin_compare_funcs[n]; -#endif + size_t n = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + + (16 * (f->flag_binary_swap ? 1 : 0)); + const char *s = bin_compare_funcs[n]; if (s) { return cb_build_method_call_2(s, cb_build_cast_address(p->x), cb_build_cast_integer(p->y)); @@ -2562,38 +2536,13 @@ cb_tree cb_build_cond(cb_tree x) { */ static cb_tree cb_build_optim_add(cb_tree v, cb_tree n) { - size_t z; - const char *s; - struct cb_field *f; - if (CB_REF_OR_FIELD_P(v)) { - f = cb_field(v); + struct cb_field *f = cb_field(v); if (!f->pic->scale && (f->usage == CB_USAGE_BINARY || f->usage == CB_USAGE_COMP_5 || f->usage == CB_USAGE_COMP_X)) { - z = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + - (16 * (f->flag_binary_swap ? 1 : 0)); -#if defined(COB_NON_ALIGNED) && !defined(_MSC_VER) - switch (f->size) { - case 2: -#ifdef COB_SHORT_BORK - s = bin_add_funcs[z]; - break; -#endif - case 4: - case 8: - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size) == 0) { - s = align_bin_add_funcs[z]; - } else { - s = bin_add_funcs[z]; - } - break; - default: - s = bin_add_funcs[z]; - break; - } -#else + size_t z = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + + (16 * (f->flag_binary_swap ? 1 : 0)); if (f->usage == CB_USAGE_COMP_5) { switch (f->size) { case 1: @@ -2603,8 +2552,7 @@ static cb_tree cb_build_optim_add(cb_tree v, cb_tree n) { return cb_build_assign(v, cb_build_binary_op(v, '+', n)); } } - s = bin_add_funcs[z]; -#endif + const char *s = bin_add_funcs[z]; if (s) { return cb_build_method_call_2(s, cb_build_cast_address(v), cb_build_cast_integer(n)); @@ -2619,38 +2567,14 @@ static cb_tree cb_build_optim_add(cb_tree v, cb_tree n) { } static cb_tree cb_build_optim_sub(cb_tree v, cb_tree n) { - size_t z; - const char *s; - struct cb_field *f; if (CB_REF_OR_FIELD_P(v)) { - f = cb_field(v); + struct cb_field *f = cb_field(v); if (!f->pic->scale && (f->usage == CB_USAGE_BINARY || f->usage == CB_USAGE_COMP_5 || f->usage == CB_USAGE_COMP_X)) { - z = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + - (16 * (f->flag_binary_swap ? 1 : 0)); -#if defined(COB_NON_ALIGNED) && !defined(_MSC_VER) - switch (f->size) { - case 2: -#ifdef COB_SHORT_BORK - s = bin_sub_funcs[z]; - break; -#endif - case 4: - case 8: - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size) == 0) { - s = align_bin_sub_funcs[z]; - } else { - s = bin_sub_funcs[z]; - } - break; - default: - s = bin_sub_funcs[z]; - break; - } -#else + size_t z = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + + (16 * (f->flag_binary_swap ? 1 : 0)); if (f->usage == CB_USAGE_COMP_5) { switch (f->size) { case 1: @@ -2660,8 +2584,7 @@ static cb_tree cb_build_optim_sub(cb_tree v, cb_tree n) { return cb_build_assign(v, cb_build_binary_op(v, '-', n)); } } - s = bin_sub_funcs[z]; -#endif + const char *s = bin_sub_funcs[z]; if (s) { return cb_build_method_call_2(s, cb_build_cast_address(v), cb_build_cast_integer(n)); @@ -2675,19 +2598,9 @@ cb_tree cb_build_add(cb_tree v, cb_tree n, cb_tree round_opt) { cb_tree opt; struct cb_field *f; -#ifdef COB_NON_ALIGNED - if (CB_INDEX_P(v)) { - return cb_build_move(cb_build_binary_op(v, '+', n), v); - } - if (CB_TREE_CLASS(v) == CB_CLASS_POINTER) { - current_program->gen_ptrmanip = 1; - return cb_build_funcall_3("cob_pointer_manip", v, n, cb_int0); - } -#else if (CB_INDEX_P(v) || CB_TREE_CLASS(v) == CB_CLASS_POINTER) { return cb_build_move(cb_build_binary_op(v, '+', n), v); } -#endif if (CB_REF_OR_FIELD_P(v)) { f = cb_field(v); @@ -2715,19 +2628,9 @@ cb_tree cb_build_sub(cb_tree v, cb_tree n, cb_tree round_opt) { cb_tree opt; struct cb_field *f; -#ifdef COB_NON_ALIGNED - if (CB_INDEX_P(v)) { - return cb_build_move(cb_build_binary_op(v, '-', n), v); - } - if (CB_TREE_CLASS(v) == CB_CLASS_POINTER) { - current_program->gen_ptrmanip = 1; - return cb_build_funcall_3("cob_pointer_manip", v, n, cb_int1); - } -#else if (CB_INDEX_P(v) || CB_TREE_CLASS(v) == CB_CLASS_POINTER) { return cb_build_move(cb_build_binary_op(v, '-', n), v); } -#endif if (CB_REF_OR_FIELD_P(v)) { f = cb_field(v); @@ -5123,31 +5026,11 @@ static cb_tree cb_build_move_num_zero(cb_tree x) { return cb_build_memset(x, 0); } switch (f->size) { -#ifdef COB_NON_ALIGNED - case 1: - return cb_build_assign(x, cb_int0); - case 2: -#ifdef COB_SHORT_BORK - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % 4 == 0)) { - return cb_build_assign(x, cb_int0); - } - break; -#endif - case 4: - case 8: - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size == 0)) { - return cb_build_assign(x, cb_int0); - } - break; -#else case 1: case 2: case 4: case 8: return cb_build_assign(x, cb_int0); -#endif } return cb_build_memset(x, 0); case CB_USAGE_DISPLAY: @@ -5520,15 +5403,7 @@ static cb_tree cb_build_move_literal(cb_tree src, cb_tree dst) { #endif case 4: case 8: -#ifdef COB_NON_ALIGNED - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size == 0)) { - return cb_build_assign(dst, cb_int(val)); - } - break; -#else return cb_build_assign(dst, cb_int(val)); -#endif } return cb_build_move_call(src, dst); } else if (cb_fits_int(src) && f->usage == CB_USAGE_PACKED) {