From 9261f40968684c3f642b7795011992ddf43badba Mon Sep 17 00:00:00 2001 From: sf-mensch Date: Tue, 14 May 2024 19:03:47 +0000 Subject: [PATCH 1/4] minor cleanups and warning fixes --- libcob/ChangeLog | 6 ++-- libcob/common.h | 28 ++++++++--------- libcob/fileio.c | 14 +++++---- libcob/profiling.c | 45 +++++++++++++++------------- tests/testsuite.src/used_binaries.at | 2 +- 5 files changed, 51 insertions(+), 44 deletions(-) diff --git a/libcob/ChangeLog b/libcob/ChangeLog index 905a2ef2c..e9d19f0e6 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -18,11 +18,11 @@ 2024-03-17 Fabrice Le Fessant Emilien Lemaire - * Makefile.am: add `profiling.c` to sources * profiling.c: implement profiling functions (time spent in each procedure of the program) - * common.c: add 4 environments variables COB_PROF_FILE, - COB_PROF_MAX_DEPTH,COB_PROF_ENABLE and COB_PROF_FORMAT + * Makefile.am: add profiling.c to sources + * common.c: add runtime settings COB_PROF_FILE, COB_PROF_MAX_DEPTH, + COB_PROF_ENABLE and COB_PROF_FORMAT * common.c (cob_expand_env_string): add $b (executable basename), $f (executable filename), $d (date in yyyymmdd) and $t (time in hhmmss) diff --git a/libcob/common.h b/libcob/common.h index 691c846ee..eb7ed2e88 100644 --- a/libcob/common.h +++ b/libcob/common.h @@ -2966,30 +2966,30 @@ enum cob_prof_procedure_kind { struct cob_prof_procedure { /* Name of the module or section or paragraph or entry */ - const char *text; + const char *text; /* File Location */ - const char *file; - int line; + const char *file; + int line; /* Index of the section record of this procedure. In the case of COB_PROF_PROCEDURE_ENTRY, the "section" field is in fact the paragraph, not the section */ - int section; + int section; /* Kind of procedure. */ - enum cob_prof_procedure_kind kind; + enum cob_prof_procedure_kind kind; }; /* Structure storing profiling information about each COBOL module */ struct cob_prof_module { /* Array of execution times */ - cob_ns_time *total_times; + cob_ns_time *total_times; /* Array of execution counts */ - unsigned int *called_count; + unsigned int *called_count; /* Array of current recursions per procedure */ - unsigned int *procedure_recursions; + unsigned int *procedure_recursions; /* Array of procedure descriptions */ - struct cob_prof_procedure *procedures ; + struct cob_prof_procedure *procedures ; /* Number of procedures */ - size_t procedure_count; + size_t procedure_count; }; /* Function called to start profiling a COBOL module. Allocates the @@ -2997,13 +2997,13 @@ struct cob_prof_module { times. */ COB_EXPIMP struct cob_prof_module *cob_prof_init_module ( cob_module *module, - struct cob_prof_procedure *procedure_names, - size_t procedure_count); + struct cob_prof_procedure *procedure_names, + size_t procedure_count); /* Functions used to instrument the generated C code and measure * counters and times */ -COB_EXPIMP void cob_prof_enter_procedure (struct cob_prof_module *, int); -COB_EXPIMP void cob_prof_exit_procedure (struct cob_prof_module *, int); +COB_EXPIMP void cob_prof_enter_procedure (struct cob_prof_module *, int); +COB_EXPIMP void cob_prof_exit_procedure (struct cob_prof_module *, int); COB_EXPIMP void cob_prof_enter_section (struct cob_prof_module *, int); COB_EXPIMP void cob_prof_exit_section (struct cob_prof_module *, int); diff --git a/libcob/fileio.c b/libcob/fileio.c index d4c900f88..ec8dcb88e 100644 --- a/libcob/fileio.c +++ b/libcob/fileio.c @@ -918,7 +918,9 @@ bdb_bt_compare (DB *db, const DBT *k1, const DBT *k2 #endif ) { - const unsigned char *col = (unsigned char *)DBT_GET_APP_DATA(k1); + const unsigned char *col = (unsigned char *)DBT_GET_APP_DATA (k1); + COB_UNUSED (db); + /* LCOV_EXCL_START */ if (col == NULL) { cob_runtime_error ("bdb_bt_compare was set but no collating sequence was stored in DBT"); @@ -2639,14 +2641,16 @@ lineseq_read (cob_file *f, const int read_opts) && (cobsetptr->cob_ls_split)) { /* If record is too long, then simulate end * so balance becomes the next record read */ - off_t k = 1; + long k; n = getc (fp); if (n == '\r') { n = getc (fp); - k++; + k = -2; + } else { + k = -1; } if (n != '\n') { - fseek (fp, -k, SEEK_CUR); + fseek (fp, k, SEEK_CUR); sts = COB_STATUS_06_READ_TRUNCATE; } break; @@ -7396,7 +7400,7 @@ cob_sys_copy_file (unsigned char *fname1, unsigned char *fname2) flag |= O_CREAT | O_TRUNC | O_WRONLY; fd2 = open (file_open_name, flag, COB_FILE_MODE); if (fd2 == -1) { - int ret = errno_cob_sts (COB_STATUS_35_NOT_EXISTS); + ret = errno_cob_sts (COB_STATUS_35_NOT_EXISTS); close (fd1); return ret; } diff --git a/libcob/profiling.c b/libcob/profiling.c index 7f6285301..94d2f6f08 100644 --- a/libcob/profiling.c +++ b/libcob/profiling.c @@ -1,6 +1,7 @@ /* Copyright (C) 2023-2024 Free Software Foundation, Inc. - Written by Emilien Lemaire and Fabrice Le Fessant. + Written by Emilien Lemaire, Fabrice Le Fessant, David Declerck, + Simon Sobisch. This file is part of GnuCOBOL. @@ -38,7 +39,7 @@ #include #endif -#ifdef _WIN32 +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include #endif @@ -54,29 +55,29 @@ static struct cob_prof_module_list *prof_info_list ; /* We maintain a stack of the procedures entered as 3 different * arrays, with "current_idx" being the stack pointer. */ -static cob_ns_time *start_times; -static int *called_procedures; -static struct cob_prof_module* *called_runtimes; +static cob_ns_time *start_times; +static int *called_procedures; +static struct cob_prof_module **called_runtimes; /* Current size of previous arrays */ static int max_prof_depth; static int current_idx = -1; /* Whether profiling is active or not. */ -static int is_active = 0; +static int is_active = -1; /* Which clock to use for clock_gettime (if available) */ #ifdef HAVE_CLOCK_GETTIME -static clockid_t clockid = CLOCK_REALTIME; +static clockid_t clockid = CLOCK_REALTIME; #endif /* Cached clock frequency on Windows */ #ifdef _WIN32 -static LONGLONG qpc_freq = 0; +static LONGLONG qpc_freq = 0; #endif /* Remember static and dynamic configuration */ -static cob_global *cobglobptr = NULL; -static cob_settings *cobsetptr = NULL; +static cob_global *cobglobptr = NULL; +static cob_settings *cobsetptr = NULL; @@ -148,12 +149,9 @@ prof_setup_clock () static void prof_init_static () { - static int init_done = 0; - - if (!init_done && cobsetptr) { + if (is_active == -1 && cobsetptr) { prof_setup_clock (); is_active = cobsetptr->cob_prof_enable; - init_done = 1; } } @@ -161,7 +159,7 @@ void cob_init_prof (cob_global *lptr, cob_settings *sptr) { cobglobptr = lptr; - cobsetptr = sptr; + cobsetptr = sptr; } struct cob_prof_module * @@ -169,7 +167,9 @@ cob_prof_init_module (cob_module *module, struct cob_prof_procedure *procedures, size_t procedure_count) { - prof_init_static(); + COB_UNUSED (module); + + prof_init_static (); if (is_active){ struct cob_prof_module *info; struct cob_prof_module_list *item; @@ -200,7 +200,8 @@ cob_prof_realloc_arrays (void) if (max_prof_depth >= new_size){ int i; - cob_runtime_warning (_("[cob_prof] Profiling overflow at %d calls, aborting profiling."), current_idx); + cob_runtime_warning (_("[cob_prof] Profiling overflow at %d calls, aborting profiling."), + current_idx); cob_runtime_warning (_(" Last 10 calls on stack:")); for (i = 0; i < cob_min_int(10, current_idx); i++){ struct cob_prof_module *info = called_runtimes[current_idx-1-i]; @@ -307,6 +308,8 @@ void cob_prof_exit_section (struct cob_prof_module *info, int proc_idx) { /* For now, nothing to do */ + COB_UNUSED (info); + COB_UNUSED (proc_idx); } void @@ -330,13 +333,13 @@ print_monotonic_time (FILE *file, cob_ns_time t) { cob_ns_time nanoseconds = t ; cob_ns_time milliseconds = nanoseconds / 1000000; - unsigned int seconds = milliseconds / 1000; - milliseconds = milliseconds - 1000 * seconds; + unsigned int seconds = (unsigned int)(milliseconds / 1000); if (seconds > 1000) { - fprintf (file, "%d s", seconds); + fprintf (file, "%u s", seconds); } else { - fprintf (file, "%d.%03Ld s", seconds, milliseconds); + milliseconds = milliseconds - 1000 * seconds; + fprintf (file, "%u.%03u s", seconds, (unsigned int)milliseconds); } } diff --git a/tests/testsuite.src/used_binaries.at b/tests/testsuite.src/used_binaries.at index 118c45b85..3a1096374 100644 --- a/tests/testsuite.src/used_binaries.at +++ b/tests/testsuite.src/used_binaries.at @@ -1120,7 +1120,7 @@ AT_DATA([prog2.cob], [ AT_DATA([filec.c], [ /* for COB_EXT_EXPORT */ #include -COB_EXT_IMPORT void f (char *str, long num) {}; +COB_EXT_EXPORT void f (char *str, long num) {}; ]) AT_CHECK([$COMPILE_MODULE --save-temps filec.c -o libfilec.$COB_MODULE_EXT], [0], [], []) From 63cb06ce7b87d75a46e7533c0fb7f375bef90960 Mon Sep 17 00:00:00 2001 From: sf-mensch Date: Wed, 15 May 2024 11:09:38 +0000 Subject: [PATCH 2/4] more compiler warnings fixed --- cobc/ChangeLog | 4 + cobc/codegen.c | 2 +- cobc/field.c | 3 +- cobc/replace.c | 209 ++++++++++++++------------- libcob/ChangeLog | 4 + libcob/profiling.c | 26 ++-- tests/testsuite.src/used_binaries.at | 8 +- 7 files changed, 137 insertions(+), 119 deletions(-) diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 4dfc86336..7b55fddf3 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -1,4 +1,8 @@ +2024-05-15 Simon Sobisch + + * replace.c: fix compile warnings and formatting + 2024-05-14 David Declerck * flag.def: fix macro usage for MSVC diff --git a/cobc/codegen.c b/cobc/codegen.c index 400048926..f6bdfd72b 100644 --- a/cobc/codegen.c +++ b/cobc/codegen.c @@ -5558,7 +5558,7 @@ output_initialize_record_one (struct cb_initialize *p, cb_tree c, multi VALUES */ if (p->val && f->values && CB_LIST_P (f->values)) { const cb_tree save_val = p->val; - const int save_default = p->flag_default; + const unsigned char save_default = p->flag_default; p->val = NULL; p->flag_default = 1; output_initialize_one (p, c); diff --git a/cobc/field.c b/cobc/field.c index 0e3ee32c1..bc1f458cf 100644 --- a/cobc/field.c +++ b/cobc/field.c @@ -2924,7 +2924,8 @@ compute_size (struct cb_field *f) p_fld = p_fld->parent; } /* calculated size */ - c->occurs_max = ( (COB_MAX_UNBOUNDED_SIZE - size_above) + c->occurs_max = (int)( + (COB_MAX_UNBOUNDED_SIZE - size_above) / (c->size * unbounded_parts) ) - 1; /* maximum possible in ODO field */ diff --git a/cobc/replace.c b/cobc/replace.c index 914565d9a..982f3e302 100644 --- a/cobc/replace.c +++ b/cobc/replace.c @@ -29,7 +29,7 @@ #include #include #include -#ifdef HAVE_STRINGS_H +#ifdef HAVE_STRINGS_H #include #endif #include @@ -85,6 +85,10 @@ #define DEBUG_REPLACE #endif +#ifdef DEBUG_REPLACE +#define DEBUG_REPLACE +#endif + /* BEGIN implementation of a queue of text and token pairs. The implementation could easily be translated to any other type of data. @@ -96,7 +100,7 @@ struct cb_token_queue { int maxsize; - int pos; + int pos; int length; const char **texts; const char **tokens; @@ -106,55 +110,52 @@ static struct cb_token_queue *token_queue_new(int initial_size) { struct cb_token_queue *q; - /* assert (initial_size>0); */ + /* assert (initial_size > 0); */ q = cobc_malloc (sizeof (struct cb_token_queue)); - q->maxsize = initial_size; - q->pos = 0; - q->length = 0; + q->maxsize = initial_size; + q->pos = 0; + q->length = 0; q->texts = cobc_malloc (sizeof(char*) * initial_size * 2); - q->tokens = q->texts + initial_size; + q->tokens = q->texts + initial_size; return q; } static void token_queue_put(struct cb_token_queue *q, int strdup, - const char *text, - const char *token) + const char *text, + const char *token) { int pos; - if (q->length == q->maxsize) { + if (q->length == q->maxsize) { int maxsize = q->maxsize * 2; int n = q->maxsize - q->pos; - const char **p = - cobc_malloc (sizeof(char *) * maxsize * 2); - const char **old_text = q->texts; - - memcpy (p, q->texts + q->pos, - sizeof(char *) * n); - if (q->pos > 0) { - memcpy(p + n, q->texts, - sizeof(char *) * ( q->maxsize - n ) ); - } - q->texts = p; - - p += maxsize; - - memcpy (p, q->tokens + q->pos, - sizeof(char *) * n); - if (q->pos > 0) { - memcpy(p + n, q->tokens, - sizeof(char *) * ( q->maxsize - n ) ); - } - q->tokens = p; + const char **p = cobc_malloc (sizeof(char *) * maxsize * 2); + const char **old_text = q->texts; + + memcpy (p, q->texts + q->pos, sizeof(char *) * n); + if (q->pos > 0) { + memcpy (p + n, q->texts, + sizeof(char *) * ( q->maxsize - n ) ); + } + q->texts = p; + + p += maxsize; + + memcpy (p, q->tokens + q->pos, sizeof(char *) * n); + if (q->pos > 0) { + memcpy (p + n, q->tokens, + sizeof(char *) * ( q->maxsize - n ) ); + } + q->tokens = p; cobc_free (old_text); - q->pos = 0; + q->pos = 0; q->maxsize = maxsize; } pos = (q->pos+q->length) % q->maxsize ; - q->texts[pos] = strdup ? cobc_plex_strdup(text) : text; + q->texts[pos] = strdup ? cobc_plex_strdup(text) : text; if (token != NULL && strdup){ - token = cobc_plex_strdup(token); - } + token = cobc_plex_strdup (token); + } q->tokens[pos] = token; q->length++; } @@ -175,34 +176,34 @@ static void token_queue_peek (struct cb_token_queue *q, const char **text, const char **token) { /* assert (q->length > 0); */ - if (text) + if (text) *text = q->texts[q->pos]; - if (token) + if (token) *token = q->tokens[q->pos]; } static void token_queue_get(struct cb_token_queue *q, int index, - const char **text, + const char **text, const char **token) { - /* assert (q->length - index > 0); */ + /* assert (q->length - index > 0); */ int pos = ( q->pos + index ) % q->maxsize; - if (text) + if (text) *text = q->texts[pos]; - if (token) + if (token) *token = q->tokens[pos]; } static void token_queue_take (struct cb_token_queue *q, const char **text, - const char **token) { + const char **token) { /* assert (q->length > 0); */ - if (text) + if (text) *text = q->texts[q->pos]; - if (token) + if (token) *token = q->tokens[q->pos]; - q->length--; + q->length--; q->pos = (q->pos+1) % q->maxsize; } @@ -210,7 +211,7 @@ static void token_queue_remove (struct cb_token_queue *q, int n) { /* assert (q->length >= n); */ - q->length -= n; + q->length -= n; q->pos = ( q->pos + n ) % q->maxsize; } @@ -218,14 +219,14 @@ static void token_queue_empty (struct cb_token_queue *q) { /* assert (q->length >= n); */ - q->length = 0; - q->pos = 0; + q->length = 0; + q->pos = 0; } static void token_queue_free(struct cb_token_queue *q) { if (q){ cobc_free (q->texts); - cobc_free(q); + cobc_free (q); } } @@ -265,7 +266,7 @@ struct cb_replacement_state { * preprocessing could create larger words. Instead, we buffer * WORD tokens (and merge them) until another kind of token * (SPACE,DELIM,etc.) is received. */ - const char *text_prequeue ; + const char *text_prequeue ; /* Current list of replacements specified in COPY-REPLACING or * REPLACE */ @@ -277,7 +278,7 @@ struct cb_replacement_state { /* The next pass to which generated tokens should be passed * (either REPLACE pass or direct output */ - enum cb_ppecho ppecho ; + enum cb_ppecho ppecho ; #ifdef DEBUG_REPLACE const char* name ; @@ -313,7 +314,7 @@ char text_list_string[MAX_TEXT_LIST_STRING]; /* In debugging mode only, stores a list of text/tokens into a preallocated string for easy display */ #define STRING_OF_LIST(kind) \ -static \ +static \ char * string_of_##kind##_list(const struct cb_##kind##_list *list) \ { \ int pos = 1; \ @@ -345,7 +346,7 @@ char * string_of_token_queue_after(struct cb_token_queue *q, int index) for(; index < token_queue_length (q); index++){ size_t len; - const char *text; + const char *text; token_queue_get (q,index, &text, NULL); len = strlen (text); @@ -401,9 +402,11 @@ ppecho_switch (WITH_DEPTH struct cb_replacement_state *repls, #ifdef DEBUG_REPLACE fprintf (stderr, "%s ppecho_direct('%s')\n", DEPTH, text); #endif - return cb_ppecho_direct (text, token); + cb_ppecho_direct (text, token); + return; case CB_PPECHO_REPLACE: - return ppecho_replace (MORE_DEPTH text, token); + ppecho_replace (MORE_DEPTH text, token); + return; } } @@ -431,8 +434,8 @@ ppecho_switch_token_queue (WITH_DEPTH struct cb_replacement_state *repls, DEPTH, repls->name, string_of_token_queue_after(q,0)); #endif int n; - const char *text; - const char *token; + const char *text; + const char *token; for ( n = token_queue_length (q); n>0 ; --n){ token_queue_take (q, &text, &token); ppecho_switch (MORE_DEPTH repls, text, token); @@ -550,12 +553,12 @@ check_replace (WITH_DEPTH struct cb_replacement_state* repls, int leading = (src->lead_trail == CB_REPLACE_LEADING); unsigned int strict = src->strict; const char *src_text = src->text_list->text; - const char *text; + const char *text; - token_queue_peek (repls->token_queue, &text, NULL); + token_queue_peek (repls->token_queue, &text, NULL); if (is_leading_or_trailing (MORE_DEPTH leading, - src_text,text,strict)){ + src_text,text,strict)){ /* MATCH */ /* remove the text from the current stream */ @@ -564,9 +567,9 @@ check_replace (WITH_DEPTH struct cb_replacement_state* repls, /* perform a partial replacement on the text, and pass it to the next stream */ ppecho_leading_or_trailing (MORE_DEPTH repls, - leading, - src_text,text, - new_text) ; + leading, + src_text,text, + new_text) ; /* restart replacements on this stream */ check_replace_after_match (MORE_DEPTH repls); @@ -577,8 +580,8 @@ check_replace (WITH_DEPTH struct cb_replacement_state* repls, /* we need to compare a list of texts from * this stream with a list of texts from the * replacement */ - check_replace_all(MORE_DEPTH repls, - new_text, + check_replace_all (MORE_DEPTH repls, + new_text, src->text_list, replace_list); } @@ -608,9 +611,9 @@ check_replace_all (WITH_DEPTH { int matched = 0; - while (1){ + for (;;) { const char* src_text; - const char *text; + const char *text; #ifdef DEBUG_REPLACE_TRACE fprintf (stderr, "%scheck_replace_all(%s,", @@ -624,7 +627,7 @@ check_replace_all (WITH_DEPTH fprintf (stderr, "%s)\n", DEPTH); #endif - if (src==NULL){ + if (!src){ /* MATCH */ /* pass the new text to the next stream */ ppecho_switch_text_list (MORE_DEPTH repls, new_text) ; @@ -632,19 +635,19 @@ check_replace_all (WITH_DEPTH * been matched */ token_queue_remove (repls->token_queue, matched); /* restart replacements on the stream */ - check_replace_after_match(MORE_DEPTH repls); + check_replace_after_match (MORE_DEPTH repls); break; - } + } - src_text = src->text; + src_text = src->text; if (is_space_or_nl(src_text[0])) { /* skip spaces in replacement */ - src = src->next; + src = src->next; continue; } - if ( token_queue_length (repls->token_queue) == matched){ + if ( token_queue_length (repls->token_queue) == matched){ /* PARTIAL MATCH, we have emptied the * list of texts, but there are still * texts in the replacement, so wait @@ -654,29 +657,30 @@ check_replace_all (WITH_DEPTH fprintf (stderr, "%s check_replace_all --> PARTIAL MATCH\n", DEPTH); #endif return; - } + } token_queue_get(repls->token_queue, matched, &text, NULL); - matched++; + matched++; - if (is_space_or_nl(text[0])) { + if (is_space_or_nl(*text)) { /* skip spaces in texts */ continue; - } + } - if (!strcasecmp (src_text,text)){ + if (!strcasecmp (src_text, text)){ /* We could match one text from the stream * with a text from the replacement, so move * on to the next text */ src = src->next; continue; - } + } - /* match failed, move on to the next potential + /* match failed, move on to the next potential * replacement */ - return check_replace ( + check_replace ( MORE_DEPTH repls, replace_list); + return; } } @@ -688,7 +692,7 @@ check_replace_after_match (WITH_DEPTH struct cb_replacement_state *repls) DEPTH, repls->name); #endif repls->current_list = NULL; - while (!token_queue_is_empty(repls->token_queue)) { + while (!token_queue_is_empty(repls->token_queue)) { const char *text; const char *token; token_queue_peek (repls->token_queue, &text, &token); @@ -696,7 +700,8 @@ check_replace_after_match (WITH_DEPTH struct cb_replacement_state *repls) ppecho_switch(MORE_DEPTH repls, text, token); token_queue_remove (repls->token_queue, 1); } else { - return do_replace(MORE_DEPTH repls); + do_replace(MORE_DEPTH repls); + return; } } } @@ -716,7 +721,7 @@ do_replace (WITH_DEPTH struct cb_replacement_state* repls) * substitution. */ ppecho_switch_token_queue (MORE_DEPTH repls, repls->token_queue); - token_queue_empty (repls->token_queue); + token_queue_empty (repls->token_queue); } else { check_replace (MORE_DEPTH repls, repls->replace_list); } @@ -803,7 +808,7 @@ add_text_to_replace (WITH_DEPTH struct cb_replacement_state *repls, if ( token_queue_is_empty (repls->token_queue) && is_space_or_nl (text[0]) ) { ppecho_switch (MORE_DEPTH repls, text, token); - } else { + } else { /* use strdup if we are in the COPY phase */ int strdup = repls->ppecho == CB_PPECHO_REPLACE ? 1 : 0; #ifdef DEBUG_REPLACE_TRACE @@ -811,7 +816,7 @@ add_text_to_replace (WITH_DEPTH struct cb_replacement_state *repls, "%s add_text_to_replace () -> push_text()\n", DEPTH); #endif - token_queue_put (repls->token_queue, + token_queue_put (repls->token_queue, strdup, text, token); do_replace (MORE_DEPTH repls); @@ -867,20 +872,20 @@ cb_ppecho_copy_replace (const char *text, const char *token) fprintf (stderr, "cb_ppecho_copy_replace('%s')\n", text); #endif - /* two fast path to avoid the streams if no replacements are + /* two fast path to avoid the streams if no replacements are * active */ - if (is_space_or_nl(text[0]) && - token_queue_is_empty(copy_repls->token_queue) && - replace_repls->text_prequeue == NULL && - token_queue_is_empty(replace_repls->token_queue)) { + if (is_space_or_nl(text[0]) + && token_queue_is_empty(copy_repls->token_queue) + && replace_repls->text_prequeue == NULL + && token_queue_is_empty(replace_repls->token_queue)) { return cb_ppecho_direct (text, token); } - if (copy_repls->replace_list == NULL - && copy_repls->current_list == NULL - && replace_repls->replace_list == NULL - && replace_repls->current_list == NULL) { + if (copy_repls->replace_list == NULL + && copy_repls->current_list == NULL + && replace_repls->replace_list == NULL + && replace_repls->current_list == NULL) { return cb_ppecho_direct (text, token); } @@ -931,7 +936,7 @@ cb_set_copy_replacing_list (struct cb_replace_list *list) copy_repls->replace_list = list; #ifdef DEBUG_REPLACE fprintf (stderr, "set_copy_replacing_list(\n"); - for(;list != NULL; list=list->next){ + for (;list != NULL; list=list->next){ fprintf (stderr, " repl = {\n"); fprintf (stderr, " src = %s\n", string_of_text_list(list->src->text_list)); @@ -939,7 +944,7 @@ cb_set_copy_replacing_list (struct cb_replace_list *list) list->src->lead_trail); fprintf (stderr, " new_text = %s\n", string_of_text_list(list->new_text)); - fprintf (stderr, " };\n"); + fprintf (stderr, " };\n"); } fprintf (stderr, " )\n"); #endif @@ -947,11 +952,11 @@ cb_set_copy_replacing_list (struct cb_replace_list *list) /* Called by pplex.l from pp_set_replace_list() after a REPLACE statement: - list is_pushpop - REPLACE . <> NULL false - REPLACE ALSO . <> NULL true - REPLACE LAST OFF. NULL true - REPLACE OFF. NULL false + list is_pushpop + REPLACE . <> NULL false + REPLACE ALSO . <> NULL true + REPLACE LAST OFF. NULL true + REPLACE OFF. NULL false */ void cb_set_replace_list (struct cb_replace_list *list, const int is_pushpop) diff --git a/libcob/ChangeLog b/libcob/ChangeLog index e9d19f0e6..00cd916fe 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -1,4 +1,8 @@ +2024-05-15 Simon Sobisch + + * profiling.c: fix compile warnings + 2024-05-14 Simon Sobisch * numeric.c (cob_numeric_display_cmp_zero): fixed overflow compare diff --git a/libcob/profiling.c b/libcob/profiling.c index 94d2f6f08..0ce3b888d 100644 --- a/libcob/profiling.c +++ b/libcob/profiling.c @@ -318,6 +318,8 @@ cob_prof_goto (struct cob_prof_module *info) int curr_proc; struct cob_prof_module *curr_info; + COB_UNUSED (info); + if (!is_active) return; curr_proc = called_procedures[current_idx]; @@ -350,17 +352,17 @@ cob_prof_print_line ( struct cob_prof_module *info, int proc_idx) { - int i; - const char *module = NULL; - const char *section = NULL; - const char *paragraph = NULL; - const char *entry = NULL; - const char *kind = NULL; - const char *source_file; - int line; - int ncalls; - cob_ns_time time = 0; - struct cob_prof_procedure *proc; + int i; + const char *module = NULL; + const char *section = NULL; + const char *paragraph = NULL; + const char *entry = NULL; + const char *kind = NULL; + const char *source_file; + int line; + int ncalls; + cob_ns_time time = 0; + struct cob_prof_procedure *proc; if (info){ time = info->total_times[proc_idx]; @@ -419,7 +421,7 @@ cob_prof_print_line ( entry = "entry"; kind = "kind"; source_file = "file"; - ncalls = 0; + ncalls = line = 0; } for (i = 0; cobsetptr->cob_prof_format[i] != 0; i++) { diff --git a/tests/testsuite.src/used_binaries.at b/tests/testsuite.src/used_binaries.at index 3a1096374..585394d85 100644 --- a/tests/testsuite.src/used_binaries.at +++ b/tests/testsuite.src/used_binaries.at @@ -1102,9 +1102,9 @@ AT_DATA([prog.cob], [ # dynamic call - program seems correct AT_CHECK([$COMPILE_MODULE prog.cob], [0], [], []) -# mismatch in function signature - we ignore the error output, -# as it depends on the C compiler in use -AT_CHECK([$COMPILE_MODULE --include $(_return_path "$(pwd)/filec.h") -fstatic-call prog.cob], [1], [], [ignore]) +# mismatch in function signature - we ignore the error output, as it depends +# on the C compiler in use (and also stdout as some [MSVC] put errors there...) +AT_CHECK([$COMPILE_MODULE --include $(_return_path "$(pwd)/filec.h") -fstatic-call prog.cob], [1], ignore, ignore) AT_DATA([prog2.cob], [ IDENTIFICATION DIVISION. @@ -1123,6 +1123,8 @@ AT_DATA([filec.c], [ COB_EXT_EXPORT void f (char *str, long num) {}; ]) AT_CHECK([$COMPILE_MODULE --save-temps filec.c -o libfilec.$COB_MODULE_EXT], [0], [], []) +# cater for environments that do not use a lib prefix +AT_CHECK([$COMPILE_MODULE --save-temps filec.c -o filec.$COB_MODULE_EXT], [0], [], []) # static build with correct function signature From d671493076c3c041d6139cd04034566d7266482d Mon Sep 17 00:00:00 2001 From: sf-mensch Date: Wed, 15 May 2024 11:44:27 +0000 Subject: [PATCH 3/4] improving cobc handling with MSVC assembler --- cobc/cobc.c | 4 ++++ tests/testsuite.src/used_binaries.at | 27 ++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/cobc/cobc.c b/cobc/cobc.c index fa64d58b5..b9aa4174d 100644 --- a/cobc/cobc.c +++ b/cobc/cobc.c @@ -8193,6 +8193,9 @@ process_compile (struct filename *fn) name = file_basename (fn->source, NULL); #ifndef _MSC_VER strcat (name, ".s"); +#else + /* earlier versions of msbuild don't recognize .s */ + strcat (name, ".asm"); #endif } size = strlen (name); @@ -8207,6 +8210,7 @@ process_compile (struct filename *fn) cobc_chk_buff_size (bufflen); #ifdef _MSC_VER + /* TODO: we likely need to call ml.exe / ml64.exe */ sprintf (cobc_buffer, cb_source_debugging ? "%s /c %s %s /Od /MDd /Zi /FR /c /Fa\"%s\" /Fo\"%s\" \"%s\"" : "%s /c %s %s /MD /c /Fa\"%s\" /Fo\"%s\" \"%s\"", diff --git a/tests/testsuite.src/used_binaries.at b/tests/testsuite.src/used_binaries.at index 585394d85..50d8a1867 100644 --- a/tests/testsuite.src/used_binaries.at +++ b/tests/testsuite.src/used_binaries.at @@ -434,7 +434,7 @@ AT_CLEANUP AT_SETUP([save-temps in sub-directory]) -AT_KEYWORDS([runmisc]) +AT_KEYWORDS([runmisc cobc]) AT_DATA([prog.cob], [ IDENTIFICATION DIVISION. @@ -452,6 +452,7 @@ AT_CHECK([$COBCRUN_DIRECT ./prog.exe], [0], [OK]) AT_CHECK([test -f debug/prog.$COB_OBJECT_EXT]) AT_CHECK([test -f debug/prog.c]) AT_CHECK([test -f debug/prog.s], [1]) +AT_CHECK([test -f debug/prog.asm], [1]) AT_CHECK([test -f debug/prog.i]) AT_CHECK([test -f debug/prog.c.h]) AT_CHECK([test -f debug/prog.c.l.h]) @@ -464,14 +465,6 @@ AT_CHECK([test -f prog.$COB_OBJECT_EXT]) AT_CHECK([$COMPILE -save-temps=debug -c -o program.$COB_OBJECT_EXT prog.cob]) AT_CHECK([test -f program.$COB_OBJECT_EXT]) -# Check with -S - -AT_CHECK([test -f prog.s], [1]) -AT_CHECK([$COMPILE -save-temps=debug -S prog.cob]) -AT_CHECK([test -f prog.s]) -AT_CHECK([$COMPILE -save-temps=debug -S -o program.s prog.cob]) -AT_CHECK([test -f program.s]) - # Check with -C AT_CHECK([test -f prog.c], [1]) @@ -492,6 +485,22 @@ AT_CHECK([test -f prog.i]) AT_CHECK([$COMPILE -save-temps=debug -E -o program.i prog.cob]) AT_CHECK([test -f program.i]) +# Check with -S (last as we skip the testsuite entry for some compilers by returning 77) + +AT_CHECK([test -f prog.s], [1]) +AT_CHECK([test -f prog.asm], [1]) +AT_CHECK([$COMPILE -save-temps=debug -S prog.cob]) +AT_CHECK([test -f prog.s], [0], [], [], +# Previous test "failed" --> prog.s not available --> likely a VS build +[AT_CHECK([test -f prog.asm], [0], [], []) + AT_CHECK([$COMPILE -save-temps=debug -S -o program.asm prog.cob]) + AT_CHECK([test -f program.asm]) +], +# Previous test "passed" - .s is the extension to be used +[AT_CHECK([$COMPILE -save-temps=debug -S -o program.s prog.cob]) + AT_CHECK([test -f program.s]) +]) + AT_CLEANUP From a4971637900ed693ade051aa20a9a5422b20366d Mon Sep 17 00:00:00 2001 From: sf-mensch Date: Wed, 15 May 2024 20:22:44 +0000 Subject: [PATCH 4/4] more warning fixes, additional improvement to build_windopws * makedist.cmd: cater for new different library names * version_cobc.rc, version_libcob.rc: updated date + rev --- build_windows/ChangeLog.txt | 7 ++- build_windows/makedist.cmd | 13 +++-- build_windows/version_cobc.rc | 6 +-- build_windows/version_libcob.rc | 6 +-- cobc/cobc.c | 88 +++++++++++++++++---------------- cobc/codegen.c | 4 +- cobc/error.c | 9 ++-- cobc/replace.c | 6 ++- cobc/typeck.c | 40 +++++++-------- 9 files changed, 92 insertions(+), 87 deletions(-) diff --git a/build_windows/ChangeLog.txt b/build_windows/ChangeLog.txt index d5ed12ec0..a4b7b78dc 100644 --- a/build_windows/ChangeLog.txt +++ b/build_windows/ChangeLog.txt @@ -1,4 +1,9 @@ +2024-05-15 Simon Sobisch + + * makedist.cmd: cater for new different library names + * version_cobc.rc, version_libcob.rc: updated date + rev + 2024-05-14 David Declerck * general for libcob: add missing profiling.c @@ -328,7 +333,7 @@ version_libcob.rc, version_cobcrun.rc provided by Simon) -Copyright 2014-2023 Free Software Foundation, Inc. +Copyright 2014-2024 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted provided the copyright notice and this notice are preserved. diff --git a/build_windows/makedist.cmd b/build_windows/makedist.cmd index 3f0fcb962..65a9c0282 100644 --- a/build_windows/makedist.cmd +++ b/build_windows/makedist.cmd @@ -1,4 +1,4 @@ -:: Copyright (C) 2014-2023 Free Software Foundation, Inc. +:: Copyright (C) 2014-2024 Free Software Foundation, Inc. :: Written by Simon Sobisch, Edward Hart :: :: This file is part of GnuCOBOL. @@ -347,13 +347,12 @@ if exist "%copy_from%\libvbisam.dll" ( echo No ISAM handler found. ) -:: Copy the intl libraries. +:: Copy the intl library. call :copy_lib_if_exists "intl" %copy_to_bin% "libintl.dll" -call :copy_lib_if_exists "intl" %copy_to_bin% "libiconv.dll" :: Copy the cJSON library. -call :copy_lib_if_exists "cJSON" %copy_to_bin% "cjson.dll" -call :copy_lib_if_exists "cJSON" %copy_to_bin% "json-c.dll" +call :copy_lib_if_exists "cJSON" %copy_to_bin% "*cjson.dll" +call :copy_lib_if_exists "JSON-c" %copy_to_bin% "*json-c.dll" :: Copy the curses library. call :copy_lib_if_exists "curses" %copy_to_bin% "pdcurses*.dll" @@ -362,10 +361,10 @@ call :copy_lib_if_exists "curses" %copy_to_bin% "pdcurses*.dll" call :copy_lib_if_exists "XML" %copy_to_bin% "libxml2.dll" call :copy_lib_if_exists "zlib" %copy_to_bin% "zlib*.dll" call :copy_lib_if_exists "charset" %copy_to_bin% "libcharset.dll" -call :copy_lib_if_exists "lzma" %copy_to_bin% "lzma*.dll" +call :copy_lib_if_exists "lzma" %copy_to_bin% "*lzma*.dll" :: Copy the iconv library. -call :copy_lib_if_exists "libiconv.dll" %copy_to_bin% "iconv" +call :copy_lib_if_exists "iconv" %copy_to_bin% "libiconv.dll" goto :eof diff --git a/build_windows/version_cobc.rc b/build_windows/version_cobc.rc index ecef7b3f0..11a77fddb 100644 --- a/build_windows/version_cobc.rc +++ b/build_windows/version_cobc.rc @@ -4,7 +4,7 @@ #include "config.h" #include "../libcob/version.h" -#define VCS_REF 5112 +#define VCS_REF 5257 #define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) @@ -44,7 +44,7 @@ VS_VERSION_INFO VERSIONINFO VALUE "FileDescription", PACKAGE_NAME " compiler, supporting most COBOL dialects with lots of extensions" VALUE "FileVersion", STRINGIZE(__LIBCOB_VERSION)"."STRINGIZE(__LIBCOB_VERSION_MINOR)"."STRINGIZE(__LIBCOB_VERSION_PATCHLEVEL)"."STRINGIZE(VCS_REF) VALUE "InternalName", "cobc" - VALUE "LegalCopyright", "Copyright (C) 2001-2023 Free Software Foundation, Inc." + VALUE "LegalCopyright", "Copyright (C) 2001-2024 Free Software Foundation, Inc." VALUE "LegalTrademarks", "Compiler: GNU General Public License v3 - see COPYING,\x0ADocumentation: GNU Free Documentation License." VALUE "OriginalFilename", "cobc.exe" VALUE "ProductName", PACKAGE_NAME " compiler" @@ -55,7 +55,7 @@ VS_VERSION_INFO VERSIONINFO VALUE "SpecialBuild", "" /* Non-Standard entries */ - VALUE "Build", "July 2023" + VALUE "Build", "May 2024" VALUE "Developer", "Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart and many others (see AUTHORS and THANKS)" VALUE "Support", "https://www.gnu.org/software/gnucobol/" VALUE "Users", "Unlimited." diff --git a/build_windows/version_libcob.rc b/build_windows/version_libcob.rc index 29baa915b..dcc5cf227 100644 --- a/build_windows/version_libcob.rc +++ b/build_windows/version_libcob.rc @@ -4,7 +4,7 @@ #include "config.h" #include "../libcob/version.h" -#define VCS_REF 5059 +#define VCS_REF 5257 #define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) @@ -44,7 +44,7 @@ VS_VERSION_INFO VERSIONINFO VALUE "FileDescription", PACKAGE_NAME " runtime, supporting most COBOL dialects with lots of extensions" VALUE "FileVersion", STRINGIZE(__LIBCOB_VERSION)"."STRINGIZE(__LIBCOB_VERSION_MINOR)"."STRINGIZE(__LIBCOB_VERSION_PATCHLEVEL)"."STRINGIZE(VCS_REF) VALUE "InternalName", "libcob" - VALUE "LegalCopyright", "Copyright (C) 2001-2023 Free Software Foundation, Inc." + VALUE "LegalCopyright", "Copyright (C) 2001-2024 Free Software Foundation, Inc." VALUE "LegalTrademarks", "Runtime: GNU Lesser General Public License v3 - see COPYING.LESSER,\x0ADocumentation: GNU Free Documentation License." VALUE "OriginalFilename", "libcob.dll" VALUE "ProductName", PACKAGE_NAME " runtime library" @@ -55,7 +55,7 @@ VS_VERSION_INFO VERSIONINFO VALUE "SpecialBuild", "" /* Non-Standard entries */ - VALUE "Build", "May 2023" + VALUE "Build", "May 2024" VALUE "Developer", "Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart and many others (see AUTHORS and THANKS)" VALUE "Support", "https://www.gnu.org/software/gnucobol/" VALUE "Users", "Unlimited." diff --git a/cobc/cobc.c b/cobc/cobc.c index b9aa4174d..43140878c 100644 --- a/cobc/cobc.c +++ b/cobc/cobc.c @@ -3006,10 +3006,8 @@ static int process_command_line (const int argc, char **argv) { struct cb_define_struct *p; - size_t osize; int c; int idx; - int n; int exit_option = 0; int list_reserved = 0; int list_registers = 0; @@ -3017,7 +3015,6 @@ process_command_line (const int argc, char **argv) int list_system_names = 0; int list_exceptions = 0; int list_system_routines = 0; - enum cob_exception_id i; char ext[COB_MINI_BUFF]; char *conf_label; /* we want a dynamic address for error.c, not a static one */ char *conf_entry; @@ -3197,7 +3194,7 @@ process_command_line (const int argc, char **argv) /* output version information when running very verbose -vv */ /* pass verbose switch to invoked commands when running very very verbose -vvv */ if (cob_optarg) { - n = cobc_deciph_optarg (cob_optarg, 0); + const int n = cobc_deciph_optarg (cob_optarg, 0); if (n == -1) { cobc_err_exit (COBC_INV_PAR, "--verbose"); } @@ -3289,12 +3286,12 @@ process_command_line (const int argc, char **argv) cobc_wants_debug = 1; break; - case CB_FLAG_GETOPT_DUMP: /* 8 */ + case CB_FLAG_GETOPT_DUMP: /* -fdump= : Add sections for dump code generation */ cobc_def_dump_opts (cob_optarg, 1); break; - case CB_FLAG_GETOPT_NO_DUMP: /* 13 */ + case CB_FLAG_GETOPT_NO_DUMP: /* -fno-dump= : Suppress sections in dump code generation */ if (cob_optarg) { cobc_def_dump_opts (cob_optarg, 0); @@ -3329,6 +3326,7 @@ process_command_line (const int argc, char **argv) /* debug: Turn on all exception conditions */ if (cobc_wants_debug) { + enum cob_exception_id i; for (i = (enum cob_exception_id)1; i < COB_EC_MAX; ++i) { CB_EXCEPTION_ENABLE (i) = 1; } @@ -3481,9 +3479,9 @@ process_command_line (const int argc, char **argv) /* these options were processed in the first getopt-run */ break; - case 'o': + case 'o': { /* -o : Output file */ - osize = strlen (cob_optarg); + const size_t osize = strlen (cob_optarg); if (osize > COB_SMALL_MAX) { cobc_err_exit (_("invalid output file name")); } @@ -3495,6 +3493,7 @@ process_command_line (const int argc, char **argv) /* Allocate buffer plus extension reserve */ output_name_buff = cobc_main_malloc (osize + 32U); break; + } case '0': /* -O0 : disable optimizations (or at least minimize them) */ @@ -3778,27 +3777,29 @@ process_command_line (const int argc, char **argv) CB_TEXT_LIST_ADD (cb_early_exit_list, cob_optarg); break; - case CB_FLAG_GETOPT_STACK_SIZE: /* 1 */ + case CB_FLAG_GETOPT_STACK_SIZE: { /* -fstack-size= : Specify stack (perform) size */ - n = cobc_deciph_optarg (cob_optarg, 0); + const int n = cobc_deciph_optarg (cob_optarg, 0); if (n < 16 || n > 512) { cobc_err_exit (COBC_INV_PAR, "-fstack-size"); } cb_stack_size = n; break; + } #ifdef COBC_HAS_CUTOFF_FLAG /* CHECKME: to be removed in 4.0 */ - case CB_FLAG_GETOPT_IF_CUTOFF: /* 2 */ + case CB_FLAG_GETOPT_IF_CUTOFF: { /* -fif-cutoff= : Specify IF cutoff level */ - n = cobc_deciph_optarg (cob_optarg, 0); + const int n = cobc_deciph_optarg (cob_optarg, 0); if (n < 1 || n > 512) { cobc_err_exit (COBC_INV_PAR, "-fif-cutoff"); } cb_if_cutoff = n; break; + } #endif - case CB_FLAG_GETOPT_SIGN: /* 3 */ + case CB_FLAG_GETOPT_SIGN: /* -fsign= : Specify display sign */ if (!cb_strcasecmp (cob_optarg, "EBCDIC")) { cb_ebcdic_sign = 1; @@ -3809,25 +3810,25 @@ process_command_line (const int argc, char **argv) } break; - case CB_FLAG_GETOPT_EBCDIC_TABLE: /* 14 */ + case CB_FLAG_GETOPT_EBCDIC_TABLE: cb_ebcdic_table = cobc_main_strdup (cob_optarg); break; - case CB_FLAG_GETOPT_DEFAULT_COLSEQ: /* 15 */ + case CB_FLAG_GETOPT_DEFAULT_COLSEQ: /* -fdefault-colseq= */ if (cb_deciph_default_colseq_name (cob_optarg)) { cobc_err_exit (COBC_INV_PAR, "-fdefault-colseq"); } break; - case CB_FLAG_GETOPT_DEFAULT_FILE_COLSEQ: /* 16 */ + case CB_FLAG_GETOPT_DEFAULT_FILE_COLSEQ: /* -fdefault-file-colseq= */ if (cb_deciph_default_file_colseq_name (cob_optarg)) { cobc_err_exit (COBC_INV_PAR, "-fdefault-file-colseq"); } break; - case CB_FLAG_GETOPT_FOLD_COPY: /* 4 */ + case CB_FLAG_GETOPT_FOLD_COPY: /* -ffold-copy= : COPY fold case */ if (!cb_strcasecmp (cob_optarg, "UPPER")) { cb_fold_copy = COB_FOLD_UPPER; @@ -3838,7 +3839,7 @@ process_command_line (const int argc, char **argv) } break; - case CB_FLAG_GETOPT_FOLD_CALL: /* 5 */ + case CB_FLAG_GETOPT_FOLD_CALL: /* -ffold-call= : CALL/PROG-ID fold case */ if (!cb_strcasecmp (cob_optarg, "UPPER")) { cb_fold_call = COB_FOLD_UPPER; @@ -3849,48 +3850,48 @@ process_command_line (const int argc, char **argv) } break; - case CB_FLAG_GETOPT_TTITLE: /* 6 */ + case CB_FLAG_GETOPT_TTITLE: { /* -fttitle= : Title for listing */ - { - const size_t len = strlen (cob_optarg); - size_t i; - if (cb_listing_with_title) - cobc_main_free (cb_listing_with_title); - cb_listing_with_title = cobc_main_strdup (cob_optarg); - for (i = 0; i < len; i++) { - if (cb_listing_with_title[i] == '_') - cb_listing_with_title[i] = ' '; - } + const size_t len = strlen (cob_optarg); + size_t i; + if (cb_listing_with_title) + cobc_main_free (cb_listing_with_title); + cb_listing_with_title = cobc_main_strdup (cob_optarg); + for (i = 0; i < len; i++) { + if (cb_listing_with_title[i] == '_') + cb_listing_with_title[i] = ' '; } break; + } - case CB_FLAG_GETOPT_MAX_ERRORS: /* 7 */ + case CB_FLAG_GETOPT_MAX_ERRORS: { /* -fmax-errors=<xx> : Maximum errors until abort */ - n = cobc_deciph_optarg (cob_optarg, 0); + const int n = cobc_deciph_optarg (cob_optarg, 0); if (n < 0) { cobc_err_exit (COBC_INV_PAR, "-fmax-errors"); } cb_max_errors = n; break; + } - case CB_FLAG_GETOPT_DUMP: /* 8 */ + case CB_FLAG_GETOPT_DUMP: /* -fdump=<scope> : Add sections for dump code generation */ - case CB_FLAG_GETOPT_NO_DUMP: /* 13 */ + case CB_FLAG_GETOPT_NO_DUMP: /* -fno-dump=<scope> : Suppress sections in dump code generation */ /* These options were all processed in the first getopt-run */ break; - case CB_FLAG_GETOPT_CALLFH: /* 9 */ + case CB_FLAG_GETOPT_CALLFH: /* -fcallfh=<func> : Function-name for EXTFH */ cb_call_extfh = cobc_main_strdup (cob_optarg); break; - case CB_FLAG_GETOPT_INTRINSICS: /* 10 */ + case CB_FLAG_GETOPT_INTRINSICS: /* -fintrinsics=<xx> : Intrinsic name or ALL */ cobc_deciph_funcs (cob_optarg); break; - case CB_FLAG_GETOPT_EC: /* 11 */ + case CB_FLAG_GETOPT_EC: /* -fec=<xx> : COBOL exception-name, e.g. EC-BOUND-OVERFLOW, also allows to skip the prefix e.g. BOUND-OVERFLOW */ if (cobc_deciph_ec (cob_optarg, 1U)) { @@ -3898,15 +3899,15 @@ process_command_line (const int argc, char **argv) } break; - case CB_FLAG_GETOPT_NO_EC: /* 12 */ + case CB_FLAG_GETOPT_NO_EC: /* -fno-ec=<xx> : COBOL exception-name, e.g. EC-BOUND-OVERFLOW */ if (cobc_deciph_ec (cob_optarg, 0)) { cobc_err_exit (COBC_INV_PAR, "-fno-ec"); } break; - case CB_FLAG_GETOPT_MEMORY_CHECK: /* 17 */ - /* -fmemory-check=<scope> : */ + case CB_FLAG_GETOPT_MEMORY_CHECK: + /* -fmemory-check=<scope> : extra memcmp for memory-guard */ if (!cob_optarg) { cb_flag_memory_check = CB_MEMCHK_ALL; } else if (cobc_deciph_memory_check (cob_optarg)) { @@ -3914,7 +3915,7 @@ process_command_line (const int argc, char **argv) } break; - case CB_FLAG_GETOPT_COPY_FILE: /* 18 */ + case CB_FLAG_GETOPT_COPY_FILE: /* --copy=<file> : COPY file at beginning */ if (strlen (cob_optarg) > (COB_MINI_MAX)) { cobc_err_exit (COBC_INV_PAR, "--copy"); @@ -3922,8 +3923,8 @@ process_command_line (const int argc, char **argv) CB_TEXT_LIST_ADD (cb_copy_list, cobc_strdup (cob_optarg)); break; - case CB_FLAG_GETOPT_INCLUDE_FILE: /* 19 */ - /* -include=<file.h> : add #include "file.h" to + case CB_FLAG_GETOPT_INCLUDE_FILE: + /* -include=<file.h> : add #include "file.h" to generated C file */ if (strlen (cob_optarg) > (COB_MINI_MAX)) { cobc_err_exit (COBC_INV_PAR, "--include"); @@ -4048,7 +4049,8 @@ process_command_line (const int argc, char **argv) /* LCOV_EXCL_START */ default: - cobc_err_msg ("missing evaluation of command line option '%c'", c); /* not translated as unlikely */ + /* not translated as unlikely */ + cobc_err_msg ("missing evaluation of command line option '%c'", c); COBC_ABORT (); /* LCOV_EXCL_STOP */ diff --git a/cobc/codegen.c b/cobc/codegen.c index f6bdfd72b..a9ba045b0 100644 --- a/cobc/codegen.c +++ b/cobc/codegen.c @@ -13936,8 +13936,6 @@ codegen_internal (struct cb_program *prog, const int subsequent_call) cb_tree l; int i; - int comment_gen; - struct cb_report *rep; /* skip prototypes */ @@ -14076,7 +14074,7 @@ codegen_internal (struct cb_program *prog, const int subsequent_call) /* Report data fields */ if (prog->report_storage) { - comment_gen = 0; + int comment_gen = 0; for (l = prog->report_list; l; l = CB_CHAIN (l)) { if (!CB_VALUE (l)) { continue; diff --git a/cobc/error.c b/cobc/error.c index 5e26c6634..97a57cd96 100644 --- a/cobc/error.c +++ b/cobc/error.c @@ -120,12 +120,13 @@ diagnostics_show_caret (FILE *fd, const int line) const int line_start = line > CARET_CONTEXT_LINES ? line - CARET_CONTEXT_LINES : 1; const int line_end = line + CARET_CONTEXT_LINES; const int max_pos = cb_diagnostics_show_line_numbers ? CARET_MAX_COLS - 5 : CARET_MAX_COLS; - char buffer[ CARET_MAX_COLS + 1 ]; + unsigned char buffer[ CARET_MAX_COLS + 1 ]; int line_pos = 1; int char_pos = 0; int c = 0; while (c != EOF) { - buffer[char_pos] = c = fgetc (fd);; + c = fgetc (fd); + buffer[char_pos] = c; if (c == '\n' || c == EOF || char_pos == max_pos) { if (line_pos >= line_start) { /* prefix */ @@ -142,8 +143,8 @@ diagnostics_show_caret (FILE *fd, const int line) || buffer[char_pos] == '\t' || buffer[char_pos] == '\r' || buffer[char_pos] == '\n' - || buffer[char_pos] == EOF - || char_pos == max_pos)) { + || buffer[char_pos] == (unsigned char)EOF + || char_pos == max_pos)) { buffer[char_pos--] = 0; } /* print it */ diff --git a/cobc/replace.c b/cobc/replace.c index 982f3e302..4e03a8d64 100644 --- a/cobc/replace.c +++ b/cobc/replace.c @@ -879,14 +879,16 @@ cb_ppecho_copy_replace (const char *text, const char *token) && token_queue_is_empty(copy_repls->token_queue) && replace_repls->text_prequeue == NULL && token_queue_is_empty(replace_repls->token_queue)) { - return cb_ppecho_direct (text, token); + cb_ppecho_direct (text, token); + return; } if (copy_repls->replace_list == NULL && copy_repls->current_list == NULL && replace_repls->replace_list == NULL && replace_repls->current_list == NULL) { - return cb_ppecho_direct (text, token); + cb_ppecho_direct (text, token); + return; } add_text_to_replace (INIT_DEPTH copy_repls, 0, text, token); diff --git a/cobc/typeck.c b/cobc/typeck.c index 2f4204146..3a086add4 100644 --- a/cobc/typeck.c +++ b/cobc/typeck.c @@ -4707,11 +4707,7 @@ validate_assign_name (struct cb_file * const f, void cb_validate_program_data (struct cb_program *prog) { - cb_tree l, x; - struct cb_field *p; - struct cb_field *q; - struct cb_field *field; - char buff[COB_MINI_BUFF]; + cb_tree l, x; prog->report_list = cb_list_reverse (prog->report_list); @@ -4719,6 +4715,7 @@ cb_validate_program_data (struct cb_program *prog) /* Set up LINE-COUNTER / PAGE-COUNTER */ struct cb_report *rep = CB_REPORT (CB_VALUE (l)); if (rep->line_counter == NULL) { + char buff[COB_MINI_BUFF]; snprintf (buff, (size_t)COB_MINI_MAX, "LINE-COUNTER %s", rep->cname); x = cb_build_field (cb_build_reference (buff)); @@ -4730,6 +4727,7 @@ cb_validate_program_data (struct cb_program *prog) CB_FIELD_ADD (prog->working_storage, CB_FIELD (x)); } if (rep->page_counter == NULL) { + char buff[COB_MINI_BUFF]; snprintf (buff, (size_t)COB_MINI_MAX, "PAGE-COUNTER %s", rep->cname); x = cb_build_field (cb_build_reference (buff)); @@ -4777,7 +4775,7 @@ cb_validate_program_data (struct cb_program *prog) l = cb_build_reference ("COB-CRT-STATUS"); x = cb_try_ref (l); if (x == cb_error_node) { - p = CB_FIELD (cb_build_field (l)); + struct cb_field *p = CB_FIELD (cb_build_field (l)); p->usage = CB_USAGE_DISPLAY; p->pic = cb_build_picture ("9(4)"); cb_validate_field (p); @@ -4803,6 +4801,7 @@ cb_validate_program_data (struct cb_program *prog) /* Check ODO items */ for (l = cb_depend_check; l; l = CB_CHAIN (l)) { struct cb_field *depfld = NULL; + struct cb_field *p, *q; unsigned int odo_level = 0, parent_is_pic_l; cb_tree xerr = NULL; x = CB_VALUE (l); @@ -4901,11 +4900,11 @@ cb_validate_program_data (struct cb_program *prog) } /* check alphabets */ - for (l = current_program->alphabet_name_list; l; l = CB_CHAIN(l)) { - struct cb_alphabet_name *alphabet = CB_ALPHABET_NAME (CB_VALUE(l)); + for (l = current_program->alphabet_name_list; l; l = CB_CHAIN (l)) { + struct cb_alphabet_name *alphabet = CB_ALPHABET_NAME (CB_VALUE (l)); if (alphabet->alphabet_type == CB_ALPHABET_LOCALE) { x = cb_ref (alphabet->custom_list); - if (x != cb_error_node && !CB_LOCALE_NAME_P(x)) { + if (x != cb_error_node && !CB_LOCALE_NAME_P (x)) { cb_error_x (alphabet->custom_list, _("'%s' is not a locale-name"), cb_name(x)); alphabet->custom_list = cb_error_node; @@ -4913,13 +4912,13 @@ cb_validate_program_data (struct cb_program *prog) } } - /* Resolve APPLY COMMIT */ - if (CB_VALID_TREE(prog->apply_commit)) { - for (l = prog->apply_commit; l; l = CB_CHAIN(l)) { + /* Resolve APPLY COMMIT */ + if (CB_VALID_TREE (prog->apply_commit)) { + for (l = prog->apply_commit; l; l = CB_CHAIN (l)) { cb_tree l2 = CB_VALUE (l); x = cb_ref (l2); if (x != cb_error_node) { - for (l2 = prog->apply_commit; l2 != l; l2 = CB_CHAIN(l2)) { + for (l2 = prog->apply_commit; l2 != l; l2 = CB_CHAIN (l2)) { if (cb_ref (CB_VALUE (l2)) == x) { cb_error_x (l, _("duplicate APPLY COMMIT target: '%s'"), @@ -4942,7 +4941,7 @@ cb_validate_program_data (struct cb_program *prog) _("APPLY COMMIT statement invalid for REPORT file")); } } else if (CB_FIELD_P (x)) { - field = CB_FIELD (x); + struct cb_field *field = CB_FIELD (x); if (field->storage != CB_STORAGE_WORKING && field->storage != CB_STORAGE_LOCAL) { cb_error_x (l, @@ -12339,7 +12338,7 @@ cb_build_move_literal (cb_tree src, cb_tree dst) p = buff + f->size - 1; } #if 0 /* Simon: negative zero back by disabling the following code -ยด included without documentation by Roger in 2.0 */ + included without documentation by Roger in 2.0 */ if (!n) { /* Zeros */ /* EBCDIC - store sign otherwise nothing */ @@ -12476,7 +12475,6 @@ cb_build_move_literal (cb_tree src, cb_tree dst) /* early check for unsigned zero or non-signed field */ if (l->sign == 0 || !f->pic->have_sign) { - int i; for (i = 0; i < l->size; i++) { if (l->data[i] != '0') { break; @@ -12530,8 +12528,8 @@ cb_build_move_field (cb_tree src, cb_tree dst) { const struct cb_field *src_f = CB_FIELD_PTR (src); const struct cb_field *dst_f = CB_FIELD_PTR (dst); - int src_size; - int dst_size; + int src_size; + int dst_size; if (dst_f->flag_any_length || src_f->flag_any_length) { return CB_BUILD_FUNCALL_2 ("cob_move", src, dst); @@ -12616,9 +12614,9 @@ cb_tree cb_build_move (cb_tree src, cb_tree dst) { struct cb_reference *src_ref, *dst_ref, *x; - cb_tree chks = NULL; - cb_tree ret; - int move_zero; + cb_tree chks = NULL; + cb_tree ret; + int move_zero; if (CB_INVALID_TREE (src) || CB_INVALID_TREE (dst)) {