From 8261f3171c32b875cd887bf76643ad98423dbdc1 Mon Sep 17 00:00:00 2001 From: sf-mensch Date: Fri, 6 Jan 2023 00:15:53 +0000 Subject: [PATCH] adding --coverage to cobc cobc: * cobc.c, flag.def, help.c: added option --coverage internally setting -fgen-c-line-directive, ensuring to write object file with original name, passing appropriate flags to C compiler (GCC, LLVM, MSVC, Sun Solaris) * codegen.c (output_initialize_uniform): switched to take an unsigned char * tree.c: minor refactoring additional for tests: * Makefile.am (CODE_COVERAGE_IGNORE_PATTERN): add some .def files that have shown to be not useful for GnuCOBOL's own code coverage * tests/cobol85/Makefile.am: pass appropriate flags to cobc for compiling --- ChangeLog | 7 ++++- Makefile.am | 7 +++-- cobc/ChangeLog | 8 ++++++ cobc/cobc.c | 58 +++++++++++++++++++++++++++++---------- cobc/codegen.c | 12 ++++---- cobc/flag.def | 4 +-- cobc/help.c | 7 +++-- cobc/tree.c | 24 ++++++++-------- cobc/typeck.c | 2 +- configure.ac | 20 +++++++++----- tests/cobol85/ChangeLog | 6 +++- tests/cobol85/Makefile.am | 7 +++-- 12 files changed, 108 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3fb4fa974..a206fb6f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ +2023-01-05 Simon Sobisch + + * Makefile.am (CODE_COVERAGE_IGNORE_PATTERN): add some .def files + that have shown to be not useful for code coverage + 2022-12-12 Simon Sobisch * configure.ac: check for and substitute PERL/perl @@ -1481,7 +1486,7 @@ * Version 0.9 released. -Copyright 2002-2022 Free Software Foundation, Inc. +Copyright 2002-2023 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/Makefile.am b/Makefile.am index fcf0bf35a..5e0001e75 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ # # Makefile gnucobol # -# Copyright (C) 2003-2012, 2014-2020, 2022 Free Software Foundation, Inc. +# Copyright (C) 2003-2012, 2014-2020, 2023 Free Software Foundation, Inc. # Written by Keisuke Nishida, Roger While, Simon Sobisch # # This file is part of GnuCOBOL. @@ -41,7 +41,10 @@ clean-local: code-coverage-clean dist-clean-local: code-coverage-dist-clean CODE_COVERAGE_BRANCH_COVERAGE=1 -CODE_COVERAGE_IGNORE_PATTERN="*/cobc/pplex.c" "*/cobc/ppparse.c" "*/cobc/scanner.c" "*/cobc/parser.c" +CODE_COVERAGE_IGNORE_PATTERN= \ + "*/cobc/pplex.c" "*/cobc/ppparse.c" "*/cobc/scanner.c" "*/cobc/parser.c" \ + "*/cobc/config.def" "*/cobc/warning.def" \ + "*/libcob/statement.def" # files shipped with the package that should be 755'ed: FILES_TO_BE_EXECUTABLE = $(dist_noinst_SCRIPTS) \ diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 45e8f6e24..40212df96 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -1,4 +1,12 @@ +2023-01-05 Simon Sobisch + + * cobc.c, flag.def, help.c: added option --coverage internally setting + -fgen-c-line-directive, ensuring to write object file with original name, + passing appropriate flags to C compiler (GCC, LLVM, MSVC, Sun Solaris) + * codegen.c (output_initialize_uniform): siwtched to take an unsigned char + * tree.c: minor refactoring + 2023-01-02 Simon Sobisch * cobc.c, field.c, parser.y, reserved.c: adjustment for FLOAT-EXTENDED / diff --git a/cobc/cobc.c b/cobc/cobc.c index c73c5011a..da4d181f7 100644 --- a/cobc/cobc.c +++ b/cobc/cobc.c @@ -411,15 +411,17 @@ static enum compile_level cb_compile_level = 0; static int iargs; -static size_t cobc_flag_module = 0; -static size_t cobc_flag_library = 0; -static size_t cobc_flag_run = 0; +static int cobc_flag_module = 0; +static int cobc_flag_library = 0; +static int cobc_flag_run = 0; static char *cobc_run_args = NULL; -static size_t save_temps = 0; -static size_t save_all_src = 0; -static size_t save_c_src = 0; +static int save_temps = 0; +static int save_all_src = 0; +static signed int save_c_src = 0; static signed int verbose_output = 0; -static size_t cob_optimize = 0; +static int cb_coverage_enabled = 0; +static int cob_optimize = 0; + static unsigned int cb_listing_linecount; static int cb_listing_eject = 0; @@ -580,6 +582,7 @@ static const struct option long_options[] = { {"A", CB_RQ_ARG, NULL, 'A'}, {"MT", CB_RQ_ARG, NULL, '!'}, {"MF", CB_RQ_ARG, NULL, '@'}, + {"coverage", CB_NO_ARG, &cb_coverage_enabled, 1}, {"P", CB_OP_ARG, NULL, 'P'}, {"Xref", CB_NO_ARG, NULL, 'X'}, {"use-extfh", CB_RQ_ARG, NULL, 9}, /* this is used by COBOL-IT; Same is -fcallfh= */ @@ -2077,9 +2080,13 @@ clean_up_intermediates (struct filename *fn, const int status) || (cb_compile_level == CB_LEVEL_PREPROCESS && save_temps))) { cobc_check_action (fn->preprocess); } + /* CHECKME: we had reports of unexpected intermediate + files on the dist - it is very likely rooted in this + early exit --> recheck its use */ if (save_c_src) { return; } + if (fn->need_translate && (status || cb_compile_level > CB_LEVEL_TRANSLATE @@ -3204,6 +3211,12 @@ process_command_line (const int argc, char **argv) } } + /* enabled coverage includes specifying COBOL source lines, + may be disabled manually if needed */ + if (cb_coverage_enabled) { + cb_flag_c_line_directives = 1; + } + /* dump implies extra information (may still be disabled later) */ if (cb_flag_dump != COB_DUMP_NONE) { cb_flag_source_location = 1; @@ -4282,7 +4295,7 @@ process_filename (const char *filename) if (output_name && cb_compile_level == CB_LEVEL_ASSEMBLE) { fn->object = cobc_main_strdup (output_name); } else - if (save_temps + if (save_temps || cb_coverage_enabled || cb_compile_level == CB_LEVEL_ASSEMBLE) { fn->object = cobc_main_stradd_dup (fbasename, "." COB_OBJECT_EXT); } else @@ -8088,10 +8101,18 @@ process_module_direct (struct filename *fn) #endif ret = process (cobc_buffer); #ifdef COB_STRIP_CMD - if (strip_output && ret == 0) { - cobc_chk_buff_size (strlen (COB_STRIP_CMD) + 4 + strlen (name)); - sprintf (cobc_buffer, "%s \"%s\"", COB_STRIP_CMD, name); - ret = process (cobc_buffer); + if (ret == 0) { +#ifdef __SUNPRO_C + if (cb_coverage_enabled) { + sprintf (cobc_buffer, "uncover \"%s\"", name); + ret = process (cobc_buffer); + } +#endif + if (strip_output) { + cobc_chk_buff_size (strlen (COB_STRIP_CMD) + 4 + strlen (name)); + sprintf (cobc_buffer, "%s \"%s\"", COB_STRIP_CMD, name); + ret = process (cobc_buffer); + } } #endif #else /* _MSC_VER */ @@ -8612,7 +8633,14 @@ finish_setup_compiler_env (void) } #endif } + if (cb_coverage_enabled) { + COBC_ADD_STR (cobc_cflags, " --coverage", NULL, NULL); + COBC_ADD_STR (cobc_ldflags, " --coverage", NULL, NULL); + } #elif defined(_MSC_VER) + if (cb_coverage_enabled) { + COBC_ADD_STR (cobc_cflags, " /Zi", NULL, NULL); + } /* MSC stuff reliant upon verbose option */ switch (verbose_output) { case 0: @@ -8735,8 +8763,8 @@ begin_setup_internal_and_compiler_env (void) /* Initialize variables */ begin_setup_compiler_env (); - set_const_cobc_build_stamp(); - set_cobc_defaults(); + set_const_cobc_build_stamp (); + set_cobc_defaults (); output_name = NULL; @@ -8746,7 +8774,7 @@ begin_setup_internal_and_compiler_env (void) #endif /* Enable default I/O exceptions without source locations */ - cobc_deciph_ec("EC-I-O", 1U); + cobc_deciph_ec ("EC-I-O", 1U); cb_flag_source_location = 0; #ifndef HAVE_DESIGNATED_INITS diff --git a/cobc/codegen.c b/cobc/codegen.c index 2af02a7ac..1382b7a3d 100644 --- a/cobc/codegen.c +++ b/cobc/codegen.c @@ -4741,14 +4741,13 @@ output_initialize_fp (cb_tree x, struct cb_field *f) } static void -output_initialize_uniform (cb_tree x, const int c, const int size) +output_initialize_uniform (cb_tree x, const unsigned char cc, const int size) { struct cb_field *f = cb_code_field (x); - const unsigned char cc = c; /* REPORT lines are cleared to SPACES */ if (f->storage == CB_STORAGE_REPORT - && c == ' ') { + && cc == ' ') { return; } @@ -5347,7 +5346,7 @@ output_initialize_compound (struct cb_initialize *p, cb_tree x) } else { size = ff->offset + ff->size - last_field->offset; } - output_initialize_uniform (c, last_char, size); + output_initialize_uniform (c, (unsigned char)last_char, size); } break; } @@ -5401,7 +5400,6 @@ output_initialize_compound (struct cb_initialize *p, cb_tree x) init = ' '; } if (init != -1) { - cb_tree c = cb_build_field_reference (f, NULL); cb_tree stmt = CB_BUILD_FUNCALL_3 ("memset", CB_BUILD_CAST_ADDRESS (c), cb_int (init), cb_int (f->size * f->occurs_max)); @@ -5539,7 +5537,7 @@ output_initialize (struct cb_initialize *p) case INITIALIZE_DEFAULT: c = initialize_uniform_char (f, p); if (c != -1) { - output_initialize_uniform (p->var, c, f->occurs_max); + output_initialize_uniform (p->var, (unsigned char)c, f->occurs_max); output_initialize_chaining (f, p); return; } @@ -5584,7 +5582,7 @@ output_initialize (struct cb_initialize *p) case INITIALIZE_DEFAULT: c = initialize_uniform_char (f, p); if (c != -1) { - output_initialize_uniform (p->var, c, f->size); + output_initialize_uniform (p->var, (unsigned char)c, f->size); output_initialize_chaining (f, p); return; } diff --git a/cobc/flag.def b/cobc/flag.def index 1afdb48e9..5f1bdaf7f 100644 --- a/cobc/flag.def +++ b/cobc/flag.def @@ -1,5 +1,5 @@ /* - Copyright (C) 2003-2012, 2014-2022 Free Software Foundation, Inc. + Copyright (C) 2003-2012, 2014-2023 Free Software Foundation, Inc. Written by Keisuke Nishida, Roger While, Simon Sobisch, Ron Norman, Edward Hart @@ -212,7 +212,7 @@ CB_FLAG_ON (cb_flag_c_decl_for_static_call, 1, "gen-c-decl-static-call", CB_FLAG (cb_flag_c_line_directives, 1, "gen-c-line-directives", _(" -fgen-c-line-directives\tgenerate source location directives in C code;\n" - " * turned on by -g")) + " * turned on by -g/--coverage")) CB_FLAG (cb_flag_c_labels, 1, "gen-c-labels", _(" -fgen-c-labels generate extra labels in C sources;\n" diff --git a/cobc/help.c b/cobc/help.c index fdf6544fb..5480b3117 100644 --- a/cobc/help.c +++ b/cobc/help.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2001-2022 Free Software Foundation, Inc. + Copyright (C) 2001-2023 Free Software Foundation, Inc. Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Brian Tiffin, Edward Hart, Dave Pitts @@ -115,10 +115,11 @@ cobc_print_usage_common_options (void) puts (_(" -I add to copy/include search path")); puts (_(" -L add to library search path")); puts (_(" -l link the library ")); + puts (_(" -D define for COBOL compilation")); puts (_(" -A add to the C compile phase")); puts (_(" -Q add to the C link phase")); - puts (_(" -D define for COBOL compilation")); - puts (_(" -K generate CALL to as static")); + puts (_(" -Q add to the C link phase")); + puts (_(" --coverage instrument generated binaries for coverage")); puts (_(" --conf= user-defined dialect configuration; see -std")); puts (_(" --list-reserved display reserved words")); puts (_(" --list-intrinsics display intrinsic functions")); diff --git a/cobc/tree.c b/cobc/tree.c index 232ef2664..c7f13b73a 100644 --- a/cobc/tree.c +++ b/cobc/tree.c @@ -1442,10 +1442,6 @@ cb_tree_category (cb_tree x) if (f->children) { /* CHECKME: may should be alphabetic/national/... depending on the content */ x->category = CB_CATEGORY_ALPHANUMERIC; - } else if (f->usage == CB_USAGE_POINTER && f->level != 88) { - x->category = CB_CATEGORY_DATA_POINTER; - } else if (f->usage == CB_USAGE_PROGRAM_POINTER && f->level != 88) { - x->category = CB_CATEGORY_PROGRAM_POINTER; } else { switch (f->level) { case 66: @@ -1460,7 +1456,11 @@ cb_tree_category (cb_tree x) x->category = CB_CATEGORY_BOOLEAN; break; default: - if (f->pic) { + if (f->usage == CB_USAGE_POINTER) { + x->category = CB_CATEGORY_DATA_POINTER; + } else if (f->usage == CB_USAGE_PROGRAM_POINTER) { + x->category = CB_CATEGORY_PROGRAM_POINTER; + } else if (f->pic) { x->category = f->pic->category; /* FIXME: Hack for CGI to not abort */ } else if (f->flag_is_external_form) { @@ -1636,7 +1636,7 @@ cb_fits_int (const cb_tree x) } else { s = "2147483647"; } - if (memcmp (p, s, (size_t)10) > 0) { + if (memcmp (p, s, 10U) > 0) { return 0; } return 1; @@ -1725,7 +1725,7 @@ cb_fits_long_long (const cb_tree x) } else { s = "9223372036854775807"; } - if (memcmp (p, s, (size_t)19) > 0) { + if (memcmp (p, s, 19U) > 0) { return 0; } return 1; @@ -1841,7 +1841,7 @@ cb_get_int (const cb_tree x) if (l->scale < 0) { size = size - l->scale; } - check_lit_length(size, (const char *)l->data + i); + check_lit_length (size, (const char *)l->data + i); /* Check numeric literal length matching requested output type */ #if INT_MAX >= 9223372036854775807 @@ -1851,7 +1851,7 @@ cb_get_int (const cb_tree x) } else { s = "9223372036854775807"; } - if (size > 19U || memcmp (&l->data[i], s, (size_t)19) > 0) { + if (size > 19U || memcmp (&l->data[i], s, 19U) > 0) { cb_error (_("numeric literal '%s' exceeds limit '%s'"), &l->data[i], s); return INT_MAX; } @@ -1863,7 +1863,7 @@ cb_get_int (const cb_tree x) } else { s = "2147483647"; } - if (size > 10U || memcmp (&l->data[i], s, (size_t)10) > 0) { + if (size > 10U || memcmp (&l->data[i], s, 10U) > 0) { cb_error (_("numeric literal '%s' exceeds limit '%s'"), &l->data[i], s); return INT_MAX; } @@ -1920,7 +1920,7 @@ cb_get_long_long (const cb_tree x) } else { s = "9223372036854775807"; } - if (size > 19U || memcmp (&(l->data[i]), s, (size_t)19) > 0) { + if (size > 19U || memcmp (&(l->data[i]), s, 19U) > 0) { cb_error (_("numeric literal '%s' exceeds limit '%s'"), &l->data[i], s); return LLONG_MAX; } @@ -1970,7 +1970,7 @@ cb_get_u_long_long (const cb_tree x) /* Check numeric literal length matching requested output type */ if (unlikely(size >= 20U)) { s = "18446744073709551615"; - if (size > 20U || memcmp (&(l->data[i]), s, (size_t)20) > 0) { + if (size > 20U || memcmp (&(l->data[i]), s, 20U) > 0) { cb_error (_("numeric literal '%s' exceeds limit '%s'"), &l->data[i], s); return ULLONG_MAX; } diff --git a/cobc/typeck.c b/cobc/typeck.c index ba8cf270e..ac33d4115 100644 --- a/cobc/typeck.c +++ b/cobc/typeck.c @@ -10409,7 +10409,7 @@ cb_check_overlapping (struct cb_field *src_f, struct cb_field *dst_f, /* Check for same parent field */ #ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable: 6011) // cb_field_founder always returns a valid pointer +#pragma warning(disable: 6011) /* cb_field_founder always returns a valid pointer */ #endif ff1 = cb_field_founder (src_f); ff2 = cb_field_founder (dst_f); diff --git a/configure.ac b/configure.ac index e75e92f91..8c883c5f3 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl dnl Configure template for GnuCOBOL dnl Process this file with autoconf to produce a configure script. dnl -dnl Copyright (C) 2001-2012, 2014-2022 Free Software Foundation, Inc. +dnl Copyright (C) 2001-2012, 2014-2023 Free Software Foundation, Inc. dnl Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, dnl Edward Hart dnl @@ -32,7 +32,7 @@ AC_INIT([GnuCOBOL], AC_REVISION([GnuCOBOL snapshot $Revision$]) AC_COPYRIGHT([This file is part of GnuCOBOL. -Copyright (C) 2001-2012, 2014-2022 Free Software Foundation, Inc. +Copyright (C) 2001-2012, 2014-2023 Free Software Foundation, Inc. Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart ]) @@ -603,15 +603,13 @@ if test "x$LDFLAGS" != x; then fi fi - -# some math functions (fabs, isnan, isinf) are used in libcob -# where math.h is included (especially numeric.c) +# some math functions (fabs, isnan, isinf) are used in numeric.c # (all other computations are used from GMP) # AC_MSG_NOTICE([Checks for math library ...]) # FIXME - Check for necessary math lib - in most cases they are part of the C library # for now: explicit pass them to configure via MATH_LIBS -dnl if test "x$MATH_LIBS" = x; then +dnl if test "x$MATH_LIBS" = "x"; then dnl if test "$COB_USES_ICC_ONLY" = "yes"; then dnl MATH_LIBS="-limf -lm" dnl else @@ -853,6 +851,9 @@ AS_IF([test "$with_xml2" = "yes" -o "$with_xml2" = "check"], [ XML2_LIBS="-lxml2" fi LIBS="$LIBS $XML2_LIBS" + # note: the include part is likely wrong, as PKG_CONFIG and xml2_config + # normally include _with_ "libxml", so only the header name should be + # used then - needs adjustments in both configure and libcob! for header in xmlversion uri xmlwriter do AC_CHECK_HEADER([libxml/$header.h], [], @@ -1868,7 +1869,11 @@ AS_IF([test "$COB_USES_GCC" = "yes"], [ ]) if test "$enable_debug" = "yes"; then - CFLAGS="$curr_cflags $COB_DEBUG_FLAGS" + if test "x$curr_cflags" != "x"; then + CFLAGS="$curr_cflags $COB_DEBUG_FLAGS" + else + CFLAGS="$COB_DEBUG_FLAGS" + fi else CFLAGS="$curr_cflags" fi @@ -2288,6 +2293,7 @@ AC_MSG_NOTICE([GnuCOBOL Configuration:]) AC_MSG_NOTICE([ CC ${CC}]) AC_MSG_NOTICE([ CFLAGS ${CFLAGS}]) AC_MSG_NOTICE([ LDFLAGS ${LDFLAGS}]) +AC_MSG_NOTICE([ LIBCOB_LIBS ${LIBCOB_LIBS}]) if test "x$PROGRAMS_LIBS" != x; then AC_MSG_NOTICE([ PROGRAMS_LIBS ${PROGRAMS_LIBS}]) fi diff --git a/tests/cobol85/ChangeLog b/tests/cobol85/ChangeLog index a7ce8532a..1849887c6 100644 --- a/tests/cobol85/ChangeLog +++ b/tests/cobol85/ChangeLog @@ -1,4 +1,8 @@ +2023-01-05 Simon Sobisch + + * Makefile.am: pass appropriate flags to cobc for compiling + 2022-12-22 Simon Sobisch * Makefile.am: ensure to not create half-baked module directories, @@ -379,7 +383,7 @@ * SQ.txt, summary.txt : We now pass the LINAGE tests -Copyright 2005-2010,2015-2020,2022 Free Software Foundation, Inc. +Copyright 2005-2010,2015-2020,2022-2023 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/tests/cobol85/Makefile.am b/tests/cobol85/Makefile.am index 4064532d0..07f02fbe3 100644 --- a/tests/cobol85/Makefile.am +++ b/tests/cobol85/Makefile.am @@ -1,7 +1,7 @@ # # Makefile gnucobol/tests/cobol85 # -# Copyright (C) 2002-2012, 2015-2022 Free Software Foundation, Inc. +# Copyright (C) 2002-2012, 2015-2023 Free Software Foundation, Inc. # Written by Keisuke Nishida, Roger While, Simon Sobisch # # This file is part of GnuCOBOL. @@ -49,10 +49,11 @@ EXTRA_DIST = EXEC85.conf.in expand.pl report.pl summary.pl summary.txt \ #CLEANFILES = EXEC85$(EXEEXT) summary.log COBC = $(PRE_INST_ENV) cobc$(EXEEXT) +COBC_FLAGS = -std=cobol85 -debug $(COBOL_FLAGS) + CURL_FLAGS = WGET_FLAGS = -t1 -T5 DIFF_FLAGS = @DIFF_FLAGS@ -COBC_FLAGS = -std=cobol85 -debug PRE_INST_ENV = "$(abs_top_builddir)/pre-inst-env" @@ -266,4 +267,4 @@ EXEC85.cob: newcob.val EXEC85$(EXEEXT): EXEC85.cob @echo "Compiling EXEC85 program" @if test -f "EXEC85.cob"; then EXEC_SRC="EXEC85.cob"; else EXEC_SRC="$(srcdir)/EXEC85.cob"; fi; \ - $(COBC) $(COBOL_FLAGS) -x "$$EXEC_SRC" + $(COBC) $(COBC_FLAGS) -x "$$EXEC_SRC"