[committed] cobol: Honor explicit -ffree-form

Message ID 04cf01dd51bf$4f2c7560$ed856020$@symas.com
State Committed
Commit f55108a98825c8338b5718004344af02f79353be
Headers
Series [committed] cobol: Honor explicit -ffree-form |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap fail Patch failed to apply

Commit Message

Robert Dubner Oct. 1, 2026, 4:09 p.m. UTC
  From: Xavier Del Campo Romero <xdelcampo@symas.com>
Date: Wed, 30 Sep 2026 22:54:57 +0200
Subject: [PATCH] cobol: Honor explicit -ffree-form

Previously, an explicit format was only determined as long as
command_line_indicator_column did not equal 0. However, OPT_ffree_form
assigns it to 0 via cobol_set_indicator_column, and therefore the
explicit user setting was being ignored, falling back to the default
behaviour, a heuristic where the first {PROGRAM,FUNCTION}-ID is
examined to determine whether either fixed or free format should be
applied.

Since comparing against 0 is not enough to determine whether a given
format was explicitly requested, a boolean flag has been added to
force a call to source_format_t::indicator_column_set whenever
-ffree-form is requested.

gcc/cobol/ChangeLog:

	* lexio.cc (cdftext::lex_open): Add explicit_format condition.
	(cobol_set_indicator_column): Use cdftext::explicit_format.
	* lexio.h (class cdftext): Add cdftext::explicit_format.
---
 gcc/cobol/lexio.cc | 4 +++-
 gcc/cobol/lexio.h  | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/cobol/lexio.cc b/gcc/cobol/lexio.cc
index 71bc21edefa..8b7f6e3692e 100644
--- a/gcc/cobol/lexio.cc
+++ b/gcc/cobol/lexio.cc
@@ -1509,7 +1509,7 @@  cdftext::lex_open( const char filename[] ) {
 
   source_format_stack_t source_format;
   source_format_t format;  // free-form by default
-  if( command_line_indicator_column ) {
+  if( command_line_indicator_column || explicit_format ) {
     format.indicator_column_set(command_line_indicator_column);
   }
   source_format.push(format);
@@ -1867,10 +1867,12 @@  cdftext::free_form_reference_format( int input,
 
 bool cdftext::please_push_filename = false;
 int cdftext::command_line_indicator_column = 0;
+bool cdftext::explicit_format = false;
 
 void
 cobol_set_indicator_column( int column ) {
   cdftext::command_line_indicator_column = column;
+  cdftext::explicit_format = true;
   source_format_t local;
   local.indicator_column_set(column);
   dbgmsg("%s: format now %s", __func__, local.description());
diff --git a/gcc/cobol/lexio.h b/gcc/cobol/lexio.h
index 76af58d9602..742e28eb18d 100644
--- a/gcc/cobol/lexio.h
+++ b/gcc/cobol/lexio.h
@@ -353,6 +353,7 @@  typedef std::stack<source_format_t>
source_format_stack_t;
 class cdftext {
   static bool please_push_filename;
   static int command_line_indicator_column;
+  static bool explicit_format;
 
   friend void cobol_set_indicator_column( int column );