https://gcc.gnu.org/g:81d6e077884f43398cb144bd231bc8c43ace9e17
commit r17-4819-g81d6e077884f43398cb144bd231bc8c43ace9e17 Author: Xavier Del Campo Romero <[email protected]> Date: Wed Sep 30 23:44:15 2026 +0200 cobol: Isolate source format for included files When a file was included via the -include command-line option, the heuristic that determines whether fixed or free format must be applied was applied first and only on the included file, thus affecting the rest of the compilation unit. This could potentially break the compilation of the main source file because the heuristic would not be applied again, and therefore the assigned format could differ. For example, an included file with fixed format could break the compilation of a main source file written in free format. Therefore, this commit aims to isolate included files from affecting the rest of the compilation unit by allocating a source_format_stack_t object to every included file, and then a separate source_format_stack_t object for the main source file. gcc/cobol/ChangeLog: * lexio.cc (cdftext::lex_open): Split objects for included files and main source file. Diff: --- gcc/cobol/lexio.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gcc/cobol/lexio.cc b/gcc/cobol/lexio.cc index 8b7f6e3692ef..4c18736eefe4 100644 --- a/gcc/cobol/lexio.cc +++ b/gcc/cobol/lexio.cc @@ -1507,13 +1507,6 @@ cdftext::lex_open( const char filename[] ) { * redundant. */ - source_format_stack_t source_format; - source_format_t format; // free-form by default - if( command_line_indicator_column || explicit_format ) { - format.indicator_column_set(command_line_indicator_column); - } - source_format.push(format); - int input = open_input( filename ); if( input == -1 ) return NULL; @@ -1522,6 +1515,13 @@ cdftext::lex_open( const char filename[] ) { // Process any files supplied by the -include command-line option. for( auto name : included_files ) { + source_format_stack_t source_format; + source_format_t format; // free-form by default + if( command_line_indicator_column || explicit_format ) { + format.indicator_column_set(command_line_indicator_column); + } + source_format.push(format); + int input; // cppcheck-suppress shadowVariable if( -1 == (input = open(name, O_RDONLY)) ) { cbl_message(LexIncludeE, "cannot open %<-include%> file %qs", name); @@ -1537,6 +1537,13 @@ cdftext::lex_open( const char filename[] ) { dbgmsg("lex_open: processed %zu of %zu: '%s'", n, included_files.size(), name); cobol_filename_restore(); // process_file restores only for COPY } + source_format_stack_t source_format; + source_format_t format; // free-form by default + if( command_line_indicator_column || explicit_format ) { + format.indicator_column_set(command_line_indicator_column); + } + source_format.push(format); + included_files.clear(); dbgmsg("lex_open: '%s'", filename);
