From e7b64338af91a4fd279d5d4e47d3ddf00635dc97 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Wed, 16 Oct 2024 16:27:53 +0900 Subject: [PATCH 1/5] [Fix]: remove COB_NON_ALIGNED and related code --- cobj/cobj.h | 9 ---- cobj/codegen.c | 114 ------------------------------------------------- cobj/typeck.c | 114 ------------------------------------------------- 3 files changed, 237 deletions(-) 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..581e8bc5 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) { @@ -2809,12 +2785,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) { @@ -3205,13 +3175,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 +3558,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 +3778,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 +3810,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..1452d0f5 100644 --- a/cobj/typeck.c +++ b/cobj/typeck.c @@ -2293,29 +2293,7 @@ static cb_tree cb_build_optim_cond(struct cb_binary_op *p) { 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 if (s) { return cb_build_method_call_2(s, cb_build_cast_address(p->x), cb_build_cast_integer(p->y)); @@ -2573,27 +2551,6 @@ static cb_tree cb_build_optim_add(cb_tree v, cb_tree n) { 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 if (f->usage == CB_USAGE_COMP_5) { switch (f->size) { case 1: @@ -2604,7 +2561,6 @@ static cb_tree cb_build_optim_add(cb_tree v, cb_tree n) { } } s = bin_add_funcs[z]; -#endif if (s) { return cb_build_method_call_2(s, cb_build_cast_address(v), cb_build_cast_integer(n)); @@ -2630,27 +2586,6 @@ static cb_tree cb_build_optim_sub(cb_tree v, cb_tree n) { 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 if (f->usage == CB_USAGE_COMP_5) { switch (f->size) { case 1: @@ -2661,7 +2596,6 @@ static cb_tree cb_build_optim_sub(cb_tree v, cb_tree n) { } } s = bin_sub_funcs[z]; -#endif if (s) { return cb_build_method_call_2(s, cb_build_cast_address(v), cb_build_cast_integer(n)); @@ -2675,19 +2609,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 +2639,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 +5037,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 +5414,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) { From bc594a6a0f566ddcca43abd49baeb7e5b514fdc9 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Wed, 16 Oct 2024 16:54:08 +0900 Subject: [PATCH 2/5] [Refactor]: refactor C files to resolve cpp-check warnings --- cobj/codegen.c | 9 ++++----- cobj/typeck.c | 37 +++++++++++++------------------------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index 581e8bc5..dbea409a 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -2753,11 +2753,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; @@ -2769,8 +2766,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; @@ -2954,6 +2952,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)); diff --git a/cobj/typeck.c b/cobj/typeck.c index 1452d0f5..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,9 +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)); - s = bin_compare_funcs[n]; + 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)); @@ -2540,17 +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)); + 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: @@ -2560,7 +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]; + 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)); @@ -2575,17 +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)); + 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: @@ -2595,7 +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]; + 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)); From 4ac70bb86f05f3901415878277c4c33f4f328272 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Wed, 16 Oct 2024 17:27:29 +0900 Subject: [PATCH 3/5] [Refactor]: refactor codegen.c --- cobj/codegen.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index dbea409a..b580fd58 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -1974,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(){"); @@ -1992,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; From d26556bf6bb4484c318dca7f37fd31ba9bb99234 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Wed, 16 Oct 2024 18:03:00 +0900 Subject: [PATCH 4/5] [Update]: run static analysis on Ubuntu 22.04 --- .github/workflows/static-analysis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 23b6c0f9..74c85ff2 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -9,6 +9,8 @@ permissions: jobs: static_analysis: runs-on: ubuntu-latest + container: + image: "ubuntu:22.04" steps: # Checkout opensource COBOL - name: Checkout opensource COBOL 4J @@ -21,15 +23,15 @@ jobs: - name: Install static analysis tools run: | - sudo apt-get update -y - sudo apt-get install -y clang-format cppcheck + apt-get update -y + apt-get install -y clang-format cppcheck - name: Install opensource COBOL 4J run: | - sudo apt-get install -y build-essential bison flex gettext texinfo autoconf + apt-get install -y build-essential bison flex gettext texinfo autoconf ./configure --prefix=/usr/ make - sudo make install + make install - name: Check format with google-java-format and clang-format run: | From a9cc3e6486659b399cbf24819089126a1cd451f1 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Wed, 16 Oct 2024 18:07:19 +0900 Subject: [PATCH 5/5] [Update]: `runs-on: ubuntu-22.04` --- .github/workflows/static-analysis.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 74c85ff2..36280658 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -8,9 +8,7 @@ permissions: jobs: static_analysis: - runs-on: ubuntu-latest - container: - image: "ubuntu:22.04" + runs-on: ubuntu-22.04 steps: # Checkout opensource COBOL - name: Checkout opensource COBOL 4J @@ -23,15 +21,15 @@ jobs: - name: Install static analysis tools run: | - apt-get update -y - apt-get install -y clang-format cppcheck + sudo apt-get update -y + sudo apt-get install -y clang-format cppcheck - name: Install opensource COBOL 4J run: | - apt-get install -y build-essential bison flex gettext texinfo autoconf + sudo apt-get install -y build-essential bison flex gettext texinfo autoconf ./configure --prefix=/usr/ make - make install + sudo make install - name: Check format with google-java-format and clang-format run: |