cobol: Correct diagnostic strings to rectify bootstrap build

Apply patch from Jakub to enable diagnostics. Use %<%> and %qs liberally.

	PR cobol/120621

gcc/cobol/ChangeLog:

	* cbldiag.h (yyerror): Add diagnostic attributes.
	(yywarn): Same.
	(error_msg): Same.
	(yyerrorvl): Same.
	(cbl_unimplementedw): Same.
	(cbl_unimplemented): Same.
	(cbl_unimplemented_at): Same.
	* cdf-copy.cc (copybook_elem_t::open_file): Supply string argument.
	* cdf.y: Use %<%>.
	* cobol-system.h (if): Check GCC_VERSION.
	(ATTRIBUTE_GCOBOL_DIAG): Define.
	* except.cc (cbl_enabled_exception_t::dump): Remove extra %s.
	* genapi.cc (get_class_condition_string): Use acceptable message.
	(get_bytes_needed): Same.
	(move_tree): Same.
	(get_string_from): Same.
	(internal_perform_through): Same.
	(tree_type_from_field_type): Same.
	(is_valuable): Same.
	(parser_logop): Same.
	(parser_relop): Same.
	(parser_relop_long): Same.
	(parser_if): Same.
	(parser_setop): Same.
	(parser_perform_conditional): Same.
	(parser_file_add): Same.
	(parser_file_open): Same.
	(parser_file_close): Same.
	(parser_file_read): Same.
	(parser_file_write): Same.
	(inspect_replacing): Same.
	(parser_sort): Same.
	(parser_file_sort): Same.
	(parser_file_merge): Same.
	(create_and_call): Same.
	(parser_bitop): Same.
	(parser_bitwise_op): Same.
	(hijack_for_development): Same.
	(mh_source_is_literalN): Same.
	(mh_dest_is_float): Same.
	(parser_symbol_add): Same.
	* gengen.cc (show_type): Use acceptable message.
	(gg_find_field_in_struct): Same.
	(gg_declare_variable): Same.
	(gg_printf): Same.
	(gg_fprintf): Same.
	(gg_tack_on_function_parameters): Same.
	(gg_define_function): Same.
	(gg_get_function_decl): Same.
	(gg_finalize_function): Same.
	(gg_call_expr): Same.
	(gg_call): Same.
	(gg_insert_into_assembler): Define new function.
	(gg_insert_into_assemblerf): Use gg_insert_into_assembler().
	* gengen.h (gg_insert_into_assembler): Simpler function declaration.
	(gg_insert_into_assemblerf): Declare new function.
	* genmath.cc (parser_op): Use acceptable message.
	* genutil.cc (get_binary_value): Use acceptable message.
	* lexio.cc (parse_replacing_pair): Correct diagnostic arguments.
	(preprocess_filter_add): Same.
	(cdftext::open_input): Same.
	* parse.y: Use acceptable messages.
	* parse_ante.h (struct evaluate_elem_t): Use %<%>.
	(is_callable): Same.
	* parse_util.h (intrinsic_invalid_parameter): Use %qs.
	* scan.l: Use dialect_error().
	* scan_ante.h (numstr_of): Use %qs.
	(scanner_token): Quote COBOL tokens in messages.
	(scanner_parsing): Correct diagnostic message.
	(scanner_parsing_toggle): Quote COBOL tokens in messages.
	(scanner_parsing_pop): Same.
	(typed_name): Use %qs.
	* scan_post.h (prelex): Quote COBOL tokens in message.
	* show_parse.h (CHECK_FIELD): Use acceptable message format.
	(CHECK_LABEL): Same.
	* symbols.cc (symbol_field_same_as): Remove extra spaces.
	(cbl_alphabet_t::assign): Use %<%>.
	(cbl_field_t::internalize): Quote library name in message.
	* symbols.h (struct os_locale_t): Constify codeset.
	(class temporaries_t): Add copy constructor.
	(struct cbl_alphabet_t): Use acceptable message.
	* util.cc (symbol_type_str): Use cbl_internal_error.
	(cbl_field_type_str): Same.
	(is_elementary): Same.
	(cbl_field_t::report_invalid_initial_value): Use %qs.
	(class unique_stack): Avoid %m.
	(ydferror): Declare function with attributes.
	(error_msg): Same.
	(cobol_fileline_set): Use %<%>.
	(os_locale_t): Remove use of xstrdup.
	(cobol_parse_files): Quote C names in message.
	(dialect_error): Use %<%>.
	* util.h (cbl_message): Add attributes.
	(cbl_internal_error): Same.
	(cbl_err): Same.
	(cbl_errx): Same.

(cherry picked from commit 14b8f077e4409ca0d188f0ed55891a18ba2ecd7d)
diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h
index 6b371eb..548b0f2 100644
--- a/gcc/cobol/cbldiag.h
+++ b/gcc/cobol/cbldiag.h
@@ -45,8 +45,8 @@
  *  These are user-facing messages.  They go through the gcc
  *  diagnostic framework and use text that can be localized.
  */
-void yyerror( const char fmt[], ... );
-bool yywarn( const char fmt[], ... );
+void yyerror( const char fmt[], ... ) ATTRIBUTE_GCOBOL_DIAG(1, 2);
+bool yywarn( const char fmt[], ... ) ATTRIBUTE_GCOBOL_DIAG(1, 2);
 
 /* Location type.  Borrowed from parse.h as generated by Bison. */
 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
@@ -79,18 +79,21 @@
 #endif
 
 // an error at a location, called from the parser for semantic errors
-void error_msg( const YYLTYPE& loc, const char gmsgid[], ... );
+void error_msg( const YYLTYPE& loc, const char gmsgid[], ... )
+  ATTRIBUTE_GCOBOL_DIAG(2, 3);
 
 void dialect_error( const YYLTYPE& loc, const char term[], const char dialect[] );
 
 
 // for CDF and other warnings that refer back to an earlier line
 // (not in diagnostic framework yet)
-void yyerrorvl( int line, const char *filename, const char fmt[], ... );
+void yyerrorvl( int line, const char *filename, const char fmt[], ... )
+  ATTRIBUTE_PRINTF_3;
 
-void cbl_unimplementedw(const char *gmsgid, ...); // warning
-void cbl_unimplemented(const char *gmsgid, ...);  // error
-void cbl_unimplemented_at( const  YYLTYPE& loc, const char *gmsgid, ... );
+void cbl_unimplementedw(const char *gmsgid, ...) ATTRIBUTE_GCOBOL_DIAG(1, 2); // warning
+void cbl_unimplemented(const char *gmsgid, ...) ATTRIBUTE_GCOBOL_DIAG(1, 2);  // error
+void cbl_unimplemented_at( const  YYLTYPE& loc, const char *gmsgid, ... )
+  ATTRIBUTE_GCOBOL_DIAG(2, 3);
 
 /*
  * dbgmsg produce messages not intended for the user.  They cannot be localized
diff --git a/gcc/cobol/cdf-copy.cc b/gcc/cobol/cdf-copy.cc
index f45c466..11be9b8 100644
--- a/gcc/cobol/cdf-copy.cc
+++ b/gcc/cobol/cdf-copy.cc
@@ -304,7 +304,8 @@
       dbgmsg("found copybook file %s", filename);
       this->source.name = xstrdup(filename);
       if( ! cobol_filename(this->source.name, inode_of(fd)) ) {
-        error_msg(source.loc, "recursive copybook: '%s' includes itself", this->source);
+        error_msg(source.loc, "recursive copybook: '%s' includes itself",
+                  this->source.name);
         (void)! close(fd);
         fd = -1;
       }
diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y
index 7e7d226..3344271 100644
--- a/gcc/cobol/cdf.y
+++ b/gcc/cobol/cdf.y
@@ -263,7 +263,7 @@
 		  YYACCEPT;
 		}
 	|	copy error {
-		  error_msg(@error, "COPY directive must end in a '.'");
+		  error_msg(@error, "COPY directive must end in a %<.%>");
 		  YYABORT;
 		}
 	|	completes { YYACCEPT; }
@@ -365,13 +365,15 @@
 	|	CDF_DEFINE FEATURE as ON {
 		  auto feature = cbl_gcobol_feature_t($2);
 		  if( ! cobol_gcobol_feature_set(feature, true) ) {
-		    error_msg(@FEATURE, ">>DEFINE %EBCDIC-MODE is invalid within program body");
+		    error_msg(@FEATURE,
+                              "%<>>DEFINE %%EBCDIC-MODE%> is invalid within program body");
 		  }
 		}
 	|	CDF_DEFINE FEATURE as OFF {
 		  auto feature = cbl_gcobol_feature_t($2);
 		  if( ! cobol_gcobol_feature_set(feature, false) ) {
-		    error_msg(@FEATURE, ">>DEFINE %EBCDIC-MODE is invalid within program body");
+		    error_msg(@FEATURE,
+                              "%<>>DEFINE %%EBCDIC-MODE%> is invalid within program body");
 		  }
 		}
 		;
@@ -430,7 +432,7 @@
 		  auto inserted = $$->insert(symbol_index(symbol_elem_of($2)));
 		  if( ! inserted.second ) {
 		    error_msg(@2, "%s: No file-name shall be specified more than "
-			      " once for one exception condition", $filename->name);
+			      "once for one exception condition", $filename->name);
 		  }
 		}
                 ;
@@ -517,7 +519,7 @@
 		    const char *msg = $1.string?
 		      "incommensurate comparison is FALSE: '%s' = %ld" :
 		      "incommensurate comparison is FALSE: %ld = '%s'" ;
-		    error_msg(@1, msg);
+		    error_msg(@1, "%s", msg);
 		  }
 		}
 	|	cdf_relexpr NE cdf_expr
@@ -531,7 +533,7 @@
 		    const char *msg = $1.string?
 		      "incommensurate comparison is FALSE: '%s' = %ld" :
 		      "incommensurate comparison is FALSE: %ld = '%s'" ;
-		    error_msg(@1, msg);
+		    error_msg(@1, "%s", msg);
 		  }
 		}
 	|	cdf_relexpr GE  cdf_expr { $$ = $1(@1) >= $3(@3); }
@@ -567,7 +569,7 @@
 	| 	NUMSTR {
 		  auto value = integer_literal($NUMSTR);
 		  if( !value.second ) {
-		    error_msg(@1, "CDF error: parsed %s as %ld",
+		    error_msg(@1, "CDF error: parsed %qs as %lld",
 		             $NUMSTR, value.first);
 		    YYERROR;
 		  }
@@ -593,7 +595,7 @@
 		  copybook.library(@lib, $lib.string);
 		  if( -1 == copybook.open(@src, $src.string) ) {
 		    error_msg(@src, "could not open copybook file "
-		             "for '%s' in '%'s'", $src.string, $lib.string);
+		             "for %<%s%> in %<%s%>", $src.string, $lib.string);
 		    YYABORT;
 		  }
 		}
diff --git a/gcc/cobol/cobol-system.h b/gcc/cobol/cobol-system.h
index ff95835..828f4f5 100644
--- a/gcc/cobol/cobol-system.h
+++ b/gcc/cobol/cobol-system.h
@@ -60,4 +60,10 @@
 // The following "local" #include is part of the GCC core code
 #include "system.h"
 
+#if (CHECKING_P && GCC_VERSION >= 4001) || GCC_VERSION == BUILDING_GCC_VERSION
+#define ATTRIBUTE_GCOBOL_DIAG(m, n) __attribute__ ((__format__ (__gcc_tdiag__, m, n))) ATTRIBUTE_NONNULL(m)
+#else
+#define ATTRIBUTE_GCOBOL_DIAG(m, n) ATTRIBUTE_NONNULL(m)
+#endif
+
 #endif
diff --git a/gcc/cobol/except.cc b/gcc/cobol/except.cc
index e50fa61..3e073e2 100644
--- a/gcc/cobol/except.cc
+++ b/gcc/cobol/except.cc
@@ -77,7 +77,7 @@
 
 void
 cbl_enabled_exception_t::dump( int i ) const {
-  cbl_message(2, "cbl_enabled_exception_t: %2d  {%s, %s, %s, %zu}",
+  cbl_message(2, "cbl_enabled_exception_t: %2d  {%s, %s, %zu}",
               i,
               location? "location" : "    none",
               ec_type_str(ec),
diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
index f2a5d0e..0ea41f1 100644
--- a/gcc/cobol/genapi.cc
+++ b/gcc/cobol/genapi.cc
@@ -571,7 +571,7 @@
       {
       if( strlen(ach) > sizeof(ach) - 1000  )
         {
-        cbl_internal_error("Nice try, but you can't fire me. I quit!");
+        cbl_internal_error("Nice try, but you cannot fire me.");
         }
 
       // We are working with unquoted strings that contain the values 1 through
@@ -1756,7 +1756,7 @@
       }
 
     default:
-      cbl_internal_error("%s(): Knows not the variable type %s for %s",
+      cbl_internal_error("%s: Knows not the variable type %s for %s",
               __func__,
               cbl_field_type_str(field->type),
               field->name );
@@ -2445,10 +2445,10 @@
 
   if( !moved )
     {
-    dbgmsg("###### %10s in %s:%d\n", __func__, __FILE__, __LINE__ );
-    cbl_internal_error( "I don't know how to MOVE an alphabetical string to %s(%s) \n",
-           cbl_field_type_str(dest->type),
-           dest->name
+    dbgmsg("%10s in %s:%d", __func__, __FILE__, __LINE__ );
+    cbl_internal_error( "I don%'t know how to MOVE an alphabetical string to %s(%s)",
+                        cbl_field_type_str(dest->type),
+                        dest->name
          );
     return;
     }
@@ -2514,7 +2514,7 @@
 
       default:
         cbl_internal_error(
-                "%s(): field->type %s must be literal or alphanumeric",
+                "%s: %<field->type%> %s must be literal or alphanumeric",
                 __func__, cbl_field_type_str(field->type));
       break;
       }
@@ -3449,7 +3449,7 @@
   pseudo_return_push(proc2, return_addr);
 
   // Create the code that will launch the first procedure
-  gg_insert_into_assembler("%s PERFORM %s THROUGH %s",
+  gg_insert_into_assemblerf("%s PERFORM %s THROUGH %s",
                         ASM_COMMENT_START, proc_1->name, proc_2->name);
 
   if( !suppress_nexting )
@@ -6026,7 +6026,7 @@
         break;
 
       default:
-        cbl_internal_error(  "%s(): Invalid field type %s:",
+        cbl_internal_error(  "%s: Invalid field type %s:",
                 __func__,
                 cbl_field_type_str(field->type));
         break;
@@ -6082,7 +6082,7 @@
   case FldPointer:
     return true;
   }
-  cbl_internal_error( "%s:%d: invalid symbol_type_t %d", __func__, __LINE__, type );
+  cbl_internal_error( "%s:%d: invalid %<symbol_type_t%> %d", __func__, __LINE__, type );
   return false;
 }
 
@@ -7228,20 +7228,20 @@
 
   if( tgt->type != FldConditional )
     {
-    cbl_internal_error("parser_logop() was called with variable %s on line %d"
-          ", which is not a FldConditional\n",
+    cbl_internal_error("%<parser_logop()%> was called with variable %s on line %d"
+          ", which is not a FldConditional",
           tgt->name, cobol_location().first_line);
     }
   if( a && a->type != FldConditional )
     {
-    cbl_internal_error("parser_logop() was called with variable %s on line %d"
-          ", which is not a FldConditional\n",
+    cbl_internal_error("%<parser_logop()%> was called with variable %s on line %d"
+          ", which is not a FldConditional",
           a->name, cobol_location().first_line);
     }
   if( b && b->type != FldConditional )
     {
-    cbl_internal_error("parser_logop() was called with variable %s on line %d"
-          ", which is not a FldConditional\n",
+    cbl_internal_error("%<parser_logop()%> was called with variable %s on line %d"
+          ", which is not a FldConditional",
           b->name, cobol_location().first_line);
     }
 
@@ -7347,9 +7347,9 @@
 
   if( tgt->type != FldConditional )
     {
-    cbl_internal_error("parser_relop() was called with variable %s, "
-          "which is not a FldConditional\n",
-          tgt->name);
+    cbl_internal_error("%<parser_relop%> was called with variable %qs, "
+                       "which is not a FldConditional",
+                       tgt->name);
     }
 
   static tree comp_res = gg_define_variable(INT, "..pr_comp_res", vs_file_static);
@@ -7411,8 +7411,8 @@
 
   if( tgt->type != FldConditional )
     {
-    cbl_internal_error("parser_relop() was called with variable %s, "
-          "which is not a FldConditional\n",
+    cbl_internal_error("%<parser_relop()%> was called with variable %s, "
+          "which is not a FldConditional",
           tgt->name);
     }
 
@@ -7457,8 +7457,8 @@
 
   if( conditional->type != FldConditional )
     {
-    cbl_internal_error("parser_if() was called with variable %s, "
-          "which is not a FldConditional\n",
+    cbl_internal_error("%<parser_if()%> was called with variable %s, "
+          "which is not a FldConditional",
           conditional->name);
     }
 
@@ -7708,20 +7708,19 @@
                       integer_zero_node));
           break;
         default:
-          dbgmsg("###### %10s in %s:%d\n", __func__, __FILE__, __LINE__ );
-          cbl_internal_error(
-                "###### candidate %s has unimplemented CVT_type %d(%s)\n",
-                candidate->name,
-                candidate->type,
-                cbl_field_type_str(candidate->type));
+          dbgmsg("%10s in %s:%d", __func__, __FILE__, __LINE__ );
+          cbl_internal_error("candidate %s has unimplemented %<CVT_type%> %d(%s)",
+                             candidate->name,
+                             candidate->type,
+                             cbl_field_type_str(candidate->type));
           gcc_unreachable();
           break;
         }
       break;
 
     default:
-      dbgmsg("###### %10s in %s:%d\n", __func__, __FILE__, __LINE__ );
-      cbl_internal_error("###### unknown setop_t code %d\n", op);
+      dbgmsg("%10s in %s:%d", __func__, __FILE__, __LINE__ );
+      cbl_internal_error("unknown %<setop_t%> code %d", op);
       gcc_unreachable();
       break;
     }
@@ -7917,7 +7916,7 @@
 
   if( !(i < MAXIMUM_UNTILS) )
     {
-    cbl_internal_error("%s:%d: %u exceeds MAXIMUM_UNTILS of %d, line %d",
+    cbl_internal_error("%s:%d: %u exceeds %<MAXIMUM_UNTILS%> of %d, line %d",
                        __func__, __LINE__,
                        i, MAXIMUM_UNTILS, CURRENT_LINE_NUMBER);
     }
@@ -9151,7 +9150,7 @@
 
   if( !file )
     {
-    cbl_internal_error("%s(): called with NULL *file", __func__);
+    cbl_internal_error("%s: called with NULL *file", __func__);
     gcc_assert(file);
     }
 
@@ -9276,7 +9275,7 @@
   if(file->access == file_inaccessible_e)
     {
     cbl_internal_error(
-          "%s:%d file %s access mode is 'file_inaccessible_e' in %s",
+          "%s:%d file %s access mode is %<file_inaccessible_e%> in %s",
           current_filename.back().c_str(),
           CURRENT_LINE_NUMBER,
           file->name,
@@ -9350,12 +9349,13 @@
 
   if( !file )
     {
-    cbl_internal_error("parser_file_open called with NULL *file");
+    cbl_internal_error("%<parser_file_open%> called with NULL *file");
     }
 
   if( !file->var_decl_node )
     {
-    cbl_internal_error("parser_file_open for %s called with NULL var_decl_node", file->name);
+    cbl_internal_error("%<parser_file_open%> for %s called with NULL "
+                       "%<var_decl_node%>", file->name);
     }
 
   if( mode_char == 'a' && (file->access != file_access_seq_e) )
@@ -9429,12 +9429,13 @@
 
   if( !file )
     {
-    cbl_internal_error("parser_file_close called with NULL *file");
+    cbl_internal_error("%<parser_file_close%> called with NULL *file");
     }
 
   if( !file->var_decl_node )
     {
-    cbl_internal_error("parser_file_close for %s called with NULL file->var_decl_node", file->name);
+    cbl_internal_error("%<parser_file_close%> for %s called with "
+                       "NULL %<file->var_decl_node%>", file->name);
     }
 
   TRACE1
@@ -9498,27 +9499,29 @@
 
   if( !file )
     {
-    cbl_internal_error("parser_file_read called with NULL *file");
+    cbl_internal_error("%<parser_file_read%> called with NULL *file");
     }
 
   if( !file->var_decl_node )
     {
-    cbl_internal_error("parser_file_read for %s called with NULL file->var_decl_node", file->name);
+    cbl_internal_error("%<parser_file_read%> for %s called with "
+                       "NULL %<file->var_decl_node%>", file->name);
     }
 
   if( !file )
     {
-    cbl_internal_error("parser_file_read called with NULL *field");
+    cbl_internal_error("%<parser_file_read%> called with NULL *field");
     }
 
   if( !file->var_decl_node )
     {
-    cbl_internal_error("parser_file_read for %s called with NULL field->var_decl_node", file->name);
+    cbl_internal_error("%<parser_file_read%> for %s called with "
+                       "NULL %<field->var_decl_node%>", file->name);
     }
 
   if( file->access == file_access_seq_e && where >= 0)
     {
-    cbl_internal_error("%s:%d file %s is RELATIVE/SEQUENTIAL, but 'where' >= 0",
+    cbl_internal_error("%s:%d file %s is RELATIVE/SEQUENTIAL, but %<where >= 0%>",
           current_filename.back().c_str(),
           CURRENT_LINE_NUMBER,
           file->name);
@@ -9527,7 +9530,7 @@
 
   if( file->access == file_access_rnd_e && where < 0)
     {
-    cbl_internal_error("%s:%d file %s is RELATIVE/RANDOM, but 'where' < 0",
+    cbl_internal_error("%s:%d file %s is RELATIVE/RANDOM, but %<where < 0%>",
           current_filename.back().c_str(),
           CURRENT_LINE_NUMBER,
           file->name);
@@ -9615,23 +9618,23 @@
 
   if( !file )
     {
-    cbl_internal_error("%s(): called with NULL *file", __func__);
+    cbl_internal_error("%s: called with NULL *file", __func__);
     }
 
   if( !file->var_decl_node )
     {
-    cbl_internal_error("%s(): for %s called with NULL file->var_decl_node",
+    cbl_internal_error("%s: for %s called with NULL %<file->var_decl_node%>",
                         __func__, file->name);
     }
 
   if( !file )
     {
-    cbl_internal_error("%s(): called with NULL *field", __func__);
+    cbl_internal_error("%s: called with NULL *field", __func__);
     }
 
   if( !file->var_decl_node )
     {
-    cbl_internal_error( "%s(): for %s called with NULL field->var_decl_node",
+    cbl_internal_error( "%s: for %s called with NULL %<field->var_decl_node%>",
                         __func__,
                         file->name);
     }
@@ -10292,9 +10295,9 @@
       }
     }
 
-  //fprintf(stderr, "%s(): %ld %ld\n", __func__, int_index, n_integers);
+  //fprintf(stderr, "%s: %ld %ld\n", __func__, int_index, n_integers);
   gcc_assert(int_index  == n_integers);
-  //fprintf(stderr, "%s(): %ld %ld\n", __func__, pcbl_index, n_resolveds);
+  //fprintf(stderr, "%s: %ld %ld\n", __func__, pcbl_index, n_resolveds);
   gcc_assert(pcbl_index == n_resolveds);
 
   // We have built up an array of integers, and an array of cbl_refer_t.
@@ -11477,7 +11480,7 @@
   gcc_assert(table->var_decl_node);
   if( !is_table(table) )
     {
-    cbl_internal_error(  "%s(): asked to sort %s, but it's not a table",
+    cbl_internal_error(  "%s: asked to sort %s, which is not a table",
             __func__,
             tableref.field->name);
     }
@@ -11605,7 +11608,7 @@
   else
     {
     // Having both or neither violates SORT syntax
-    cbl_internal_error("%s(): syntax error -- both (or neither) USING "
+    cbl_internal_error("%s: syntax error: both (or neither) USING "
           "and input-proc are specified",
           __func__);
     }
@@ -11735,7 +11738,7 @@
     }
   else
     {
-    cbl_internal_error("%s(): syntax error -- both (or neither) GIVING "
+    cbl_internal_error("%s: syntax error: both (or neither) GIVING "
           "and output-proc are specified", __func__);
     }
   }
@@ -12147,7 +12150,7 @@
     }
   else
     {
-    cbl_internal_error("%s(): syntax error -- both (or neither) "
+    cbl_internal_error("%s: syntax error: both (or neither) "
           "files and output-proc are specified", __func__);
     }
   }
@@ -12798,7 +12801,7 @@
     else
       {
       cbl_internal_error(
-            "%s(): What in the name of Nero's fiddle are we doing here?",
+            "%s: What in the name of Nero are we doing here?",
             __func__);
       }
     }
@@ -13038,7 +13041,7 @@
   if(tgt && tgt->type != FldConditional)
     {
     fprintf(stderr,
-            "%s(): The target %s has to be a FldConditional, not %s\n",
+            "%s: The target %s has to be a FldConditional, not %s\n",
             __func__,
             tgt->name,
             cbl_field_type_str(tgt->type));
@@ -13075,7 +13078,7 @@
     case bit_or_op:
     case bit_xor_op:
       fprintf(stderr,
-              "%s(): The %s operation is not valid\n",
+              "%s: The %s operation is not valid\n",
               __func__,
               ops[op]);
       gcc_unreachable();
@@ -13122,7 +13125,7 @@
   if( tgt && !is_valuable(tgt->type) && tgt->type != FldLiteralN)
     {
     fprintf(stderr,
-            "%s(): The target %s has to be is_valuable, not %s\n",
+            "%s: The target %s has to be is_valuable, not %s\n",
             __func__,
             tgt->name,
             cbl_field_type_str(tgt->type));
@@ -13136,7 +13139,7 @@
     case bit_on_op:
     case bit_off_op:
       fprintf(stderr,
-              "%s(): The %s operation is not valid\n",
+              "%s: The %s operation is not valid\n",
               __func__,
               ops[op]);
       gcc_unreachable();
@@ -13749,7 +13752,7 @@
   // Assume that funcname is lowercase with no hyphens
   enter_program_common(funcname, funcname);
   parser_display_literal("You have been hijacked by a program named \"dubner\"");
-  gg_insert_into_assembler("%s HIJACKED DUBNER CODE START", ASM_COMMENT_START);
+  gg_insert_into_assemblerf("%s HIJACKED DUBNER CODE START", ASM_COMMENT_START);
 
   for(int i=0; i<10; i++)
     {
@@ -13762,7 +13765,7 @@
             NULL_TREE);
     }
 
-  gg_insert_into_assembler("%s HIJACKED DUBNER CODE END", ASM_COMMENT_START);
+  gg_insert_into_assemblerf("%s HIJACKED DUBNER CODE END", ASM_COMMENT_START);
   gg_return(0);
   }
 
@@ -14083,8 +14086,8 @@
 
       default:
         cbl_internal_error(
-              "In parser_move(%s to %s), the move of FldLiteralN to %s "
-              "hasn't been implemented",
+              "In %<parser_move(%s to %s)%>, the move of FldLiteralN to %s "
+              "is unimplemented",
               sourceref.field->name,
               destref.field->name,
               cbl_field_type_str(destref.field->type));
@@ -14319,8 +14322,8 @@
         }
 
       default:
-        cbl_internal_error("In mh_dest_is_float(%s to %s), the "
-                           "move of %s to %s hasn't been implemented",
+        cbl_internal_error("In %<mh_dest_is_float%>(%s to %s), the "
+                           "move of %s to %s is unimplemented",
               sourceref.field->name,
               destref.field->name,
               cbl_field_type_str(sourceref.field->type),
@@ -16349,7 +16352,7 @@
     {
     do
       {
-      fprintf(stderr, "( %d ) %s():", CURRENT_LINE_NUMBER, __func__);
+      fprintf(stderr, "( %d ) %s:", CURRENT_LINE_NUMBER, __func__);
       }
     while(0);
 
@@ -16487,7 +16490,7 @@
     //  Make sure we have a new variable to work with.
     if( !new_var )
       {
-      cbl_internal_error("parser_symbol_add() was called with a NULL new_var\n");
+      cbl_internal_error("%<parser_symbol_add()%> was called with a NULL %<new_var%>");
       }
 
     TRACE1
@@ -16515,7 +16518,7 @@
     if( is_table(new_var) && new_var->data.capacity == 0)
       {
       cbl_internal_error(
-          "%s(): %2.2d %s is a table, but it improperly has a capacity of zero",
+          "%s: %d %s is a table, but it improperly has a capacity of zero",
            __func__,
            new_var->level,
            new_var->name);
@@ -16555,23 +16558,20 @@
 
     if( ancestor == new_var )
       {
-      cbl_internal_error("parser_symbol_add(): %s is its own ancestor",
-                          new_var->name);
+      cbl_internal_error("%s: %s is its own ancestor", __func__, new_var->name);
       }
 
     if( !ancestor && (new_var->level > LEVEL01 && new_var->level <= LEVEL49 ) )
       {
-      cbl_internal_error("parser_symbol_add(): %2.2d %s has null ancestor",
-            new_var->level,
-            new_var->name);
+      cbl_internal_error("%s: %d %qs has NULL ancestor", __func__, 
+                         new_var->level, new_var->name);
       }
 
     //  new_var's var_decl_node should be NULL at this point
     if( new_var->var_decl_node )
       {
-      cbl_internal_error( "parser_symbol_add( %s ) improperly has a non-null "
-             "var_decl_node\n",
-             new_var->name);
+      cbl_internal_error( "%s(%s) improperly has a non-null "
+                          "%<var_decl_node%>", __func__, new_var->name);
       }
 
     switch( new_var->type )
@@ -16765,7 +16765,7 @@
         && new_var->type  != FldLiteralN
         && new_var->type  != FldLiteralA )
       {
-      cbl_internal_error(  "%s(): %2.2d %s<%s> improperly has a data.capacity of zero",
+      cbl_internal_error(  "%s: %d %s<%s> improperly has a data.capacity of zero",
               __func__,
               new_var->level,
               new_var->name,
@@ -16832,12 +16832,10 @@
 
         if( !bytes_to_allocate )
           {
-          fprintf(stderr,
-                  "bytes_to_allocate is zero for %s (symbol number "
-                  HOST_SIZE_T_PRINT_DEC ")\n",
-                  new_var->name,
-                  (fmt_size_t)new_var->our_index);
-          gcc_assert(bytes_to_allocate);
+          cbl_internal_error( "%<bytes_to_allocate%> is zero for %s (symbol number "
+                              HOST_SIZE_T_PRINT_DEC ")",
+                              new_var->name,
+                              (fmt_size_t)new_var->our_index);
           }
 
         if( new_var->type == FldIndex && new_var->level == 0 )
diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc
index a5f143c..1098225 100644
--- a/gcc/cobol/gengen.cc
+++ b/gcc/cobol/gengen.cc
@@ -360,7 +360,7 @@
   {
   if( !type )
     {
-    cbl_internal_error("The given type is not NULL, and that's just not fair");
+    cbl_internal_error("The given type is not NULL, and that is just not fair");
     }
 
   if( DECL_P(type) )
@@ -369,7 +369,7 @@
     }
   if( !TYPE_P(type) )
     {
-    cbl_internal_error("The given type is not a DECL or a TYPE");
+    cbl_internal_error("The given type is not a declaration or a TYPE");
     }
 
   static char ach[1024];
@@ -520,8 +520,7 @@
 
   if( !field_decl )
     {
-    yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
-    yywarn("###### Somebody asked for the field %s.%s, which doesn't exist",
+    yywarn("Somebody asked for the field %s.%s, which does not exist",
           IDENTIFIER_POINTER(DECL_NAME(base)),
           field_name);
     gcc_unreachable();
@@ -933,7 +932,7 @@
   // causes the storage to be allocated.
 
   // It is routine to let the compiler assign names to stack variables.  The
-  // assembly code doesn't use names for variables on the stack; they are
+  // assembly code does not use names for variables on the stack; they are
   // referenced by offsets to the base pointer.  But static variables have to
   // have names, and there are places in my code generation -- Lord only knows
   // why -- where I didn't give the variables explicit names.  We remedy that
@@ -2161,8 +2160,7 @@
     {
     if(nargs >= ARG_LIMIT)
       {
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
-      yywarn("###### You *must* be joking!");
+      yywarn("You *must* be joking");
       gcc_unreachable();
       }
 
@@ -2170,10 +2168,8 @@
       {
       // Warning:  This test is not completely reliable, because a garbage
       // byte could have a valid TREE_CODE.  But it does help.
-      yywarn("You nitwit!");
-      yywarn("You forgot to put a NULL_TREE at the end of a "
-                  "gg_printf() again!");
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
+      yywarn("You forgot to put a %<NULL_TREE%> at the end of a "
+                  "%<gg_printf()%> again");
       gcc_unreachable();
       }
 
@@ -2219,8 +2215,7 @@
     {
     if(argc >= ARG_LIMIT)
       {
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
-      yywarn("###### You *must* be joking!");
+      yywarn("You *must* be joking");
       gcc_unreachable();
       }
 
@@ -2601,10 +2596,8 @@
       {
       // Warning:  This test is not completely reliable, because a garbage
       // byte could have a valid TREE_CODE.  But it does help.
-      yywarn("You nitwit!");
-      yywarn("You forgot to put a NULL_TREE at the end of a "
-                  "gg_define_function() again!");
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
+      yywarn("You forgot to put a %<NULL_TREE%> at the end of a "
+                  "%<gg_define_function()%> again");
       gcc_unreachable();
       }
 
@@ -2615,8 +2608,7 @@
     nparams += 1;
     if(nparams > ARG_LIMIT)
       {
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
-      yywarn("###### %d parameters?  Really?  Are you insane?",ARG_LIMIT+1);
+      yywarn("%d parameters? Really? Are you insane?",ARG_LIMIT+1);
       gcc_unreachable();
       }
     }
@@ -2657,10 +2649,8 @@
       {
       // Warning:  This test is not completely reliable, because a garbage
       // byte could have a valid TREE_CODE.  But it does help.
-      yywarn("You nitwit!");
-      yywarn("You forgot to put a NULL_TREE at the end of a "
-                  "gg_define_function() again!");
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
+      yywarn("You forgot to put a %<NULL_TREE%> at the end of a "
+                  "%<gg_define_function()%> again");
       gcc_unreachable();
       }
 
@@ -2671,9 +2661,7 @@
     nparams += 1;
     if(nparams > ARG_LIMIT)
       {
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
-      yywarn("###### %d parameters?  Really?  Are you insane?",
-                  ARG_LIMIT+1);
+      yywarn("%d parameters? Really? Are you insane?", ARG_LIMIT+1);
       gcc_unreachable();
       }
     }
@@ -2785,10 +2773,8 @@
       {
       // Warning:  This test is not completely reliable, because a garbage
       // byte could have a valid TREE_CODE.  But it does help.
-      yywarn("You nitwit!");
-      yywarn("You forgot to put a NULL_TREE at the end of a "
-            "gg_define_function() again!");
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
+      yywarn("You forgot to put a %<NULL_TREE%> at the end of a "
+            "%<gg_define_function()%> again");
       gcc_unreachable();
       }
 
@@ -2799,8 +2785,7 @@
     nparams += 1;
     if(nparams > ARG_LIMIT)
       {
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
-      yywarn("###### %d parameters?  Really?  Are you insane?",
+      yywarn("%d parameters? Really? Are you insane?",
                   ARG_LIMIT+1);
       gcc_unreachable();
       }
@@ -2909,7 +2894,7 @@
 
     /* Register this function with cgraph just far enough to get it
     added to our parent's nested function list.  Handy, since the
-    C front end doesn't have such a list.  */
+    C front end does not have such a list.  */
 
     static cgraph_node *node = cgraph_node::get_create (current_function->function_decl);
     gcc_assert(node);
@@ -2925,7 +2910,7 @@
 
   if( gg_trans_unit.function_stack.back().context_count )
     {
-    cbl_internal_error("Residual context count!");
+    cbl_internal_error("Residual context count");
     }
 
   gg_trans_unit.function_stack.pop_back();
@@ -3070,8 +3055,7 @@
     {
     if(nargs >= ARG_LIMIT)
       {
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
-      yywarn("###### You *must* be joking!");
+      yywarn("You *must* be joking");
       gcc_unreachable();
       }
 
@@ -3127,8 +3111,7 @@
     {
     if(nargs >= ARG_LIMIT)
       {
-      yywarn("###### %10s in %s:%d", __func__, __FILE__,__LINE__ );
-      yywarn("###### You *must* be joking!");
+      yywarn("You *must* be joking");
       gcc_unreachable();
       }
 
@@ -3425,7 +3408,27 @@
   }
 
 void
-gg_insert_into_assembler(const char *format, ...)
+gg_insert_into_assembler(const char ach[])
+  {
+  if( !optimize )
+    {
+    // Create the required generic tag
+    tree asm_expr = build5_loc( location_from_lineno(),
+                            ASM_EXPR,
+                            VOID,
+                            build_string(strlen(ach), ach),
+                            NULL_TREE,
+                            NULL_TREE,
+                            NULL_TREE,
+                            NULL_TREE);
+
+    // And insert it as a statement
+    gg_append_statement(asm_expr);
+    }
+  }
+
+void
+gg_insert_into_assemblerf(const char *format, ...)
   {
   // Temporarily defeat all ASM_EXPR for optimized code per PR119214
   // The correct solution using LABEL_DECL is forthcoming
@@ -3444,18 +3447,6 @@
     vsnprintf(ach, sizeof(ach), format, ap);
     va_end(ap);
 
-    // Create the required generic tag
-    tree asm_expr = build5_loc( location_from_lineno(),
-                            ASM_EXPR,
-                            VOID,
-                            build_string(strlen(ach), ach),
-                            NULL_TREE,
-                            NULL_TREE,
-                            NULL_TREE,
-                            NULL_TREE);
-    //SET_EXPR_LOCATION (asm_expr, UNKNOWN_LOCATION);
-
-    // And insert it as a statement
-    gg_append_statement(asm_expr);
+    gg_insert_into_assembler(ach);
     }
   }
diff --git a/gcc/cobol/gengen.h b/gcc/cobol/gengen.h
index 8c1bc8d..15c2a6b 100644
--- a/gcc/cobol/gengen.h
+++ b/gcc/cobol/gengen.h
@@ -539,6 +539,9 @@
 tree gg_open(tree char_star_A, tree int_B);
 tree gg_close(tree int_A);
 tree gg_get_indirect_reference(tree pointer, tree offset);
-void gg_insert_into_assembler(const char *format, ...);
+
+void gg_insert_into_assembler(const char ach[]);
+void gg_insert_into_assemblerf(const char *format, ...) ATTRIBUTE_PRINTF_1;
+
 void gg_modify_function_type(tree function_decl, tree return_type);
 #endif
diff --git a/gcc/cobol/genmath.cc b/gcc/cobol/genmath.cc
index bf3885b..0a1c12d 100644
--- a/gcc/cobol/genmath.cc
+++ b/gcc/cobol/genmath.cc
@@ -1383,12 +1383,12 @@
       break;
       }
     default:
-      cbl_internal_error( "parser_op() doesn't know how to "
-             "evaluate \"%s = %s %c %s\"\n",
-             cref.field->name,
-             aref.field->name,
-             op,
-             bref.field->name);
+      cbl_internal_error( "%<parser_op()%> doesn%'t know how to "
+                          "evaluate %<%s = %s %c %s%>",
+                          cref.field->name,
+                          aref.field->name,
+                          op,
+                          bref.field->name);
       break;
     }
   }
diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc
index 8ec7a78..1d921a3 100644
--- a/gcc/cobol/genutil.cc
+++ b/gcc/cobol/genutil.cc
@@ -737,7 +737,7 @@
       {
       if( SCALAR_FLOAT_TYPE_P(value) )
         {
-        cbl_internal_error("Can't get float value from %s", field->name);
+        cbl_internal_error("cannot get %<float%> value from %s", field->name);
         }
       else
         {
diff --git a/gcc/cobol/lexio.cc b/gcc/cobol/lexio.cc
index 888cce1..754a948 100644
--- a/gcc/cobol/lexio.cc
+++ b/gcc/cobol/lexio.cc
@@ -745,7 +745,7 @@
       }
     }
     if( pair.stmt.p ) {
-      yywarn("CDF syntax error '%*s'", (int)pair.stmt.size(), pair.stmt.p);
+      yywarn("CDF syntax error '%.*s'", (int)pair.stmt.size(), pair.stmt.p);
     }
     else {
       // This eliminated a compiler warning about "format-overflow"
@@ -1413,7 +1413,7 @@
 
   auto filename = find_filter(filter.c_str());
   if( !filename ) {
-    yywarn("preprocessor '%s/%s' not found", getcwd(NULL, 0), filter);
+    yywarn("preprocessor '%s/%s' not found", getcwd(NULL, 0), filter.c_str());
     return false;
   }
   preprocessor_filters.push_back( std::make_pair(xstrdup(filename), options) );
@@ -1546,7 +1546,7 @@
 cdftext::open_input( const char filename[] ) {
   int fd = open(filename, O_RDONLY);
   if( fd == -1 ) {
-    dbgmsg( "could not open '%s': %m", filename );
+    dbgmsg( "could not open '%s': %s", filename, xstrerror(errno) );
   }
 
   verbose_file_reader = NULL != getenv("GCOBOL_TEMPDIR");
diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index 3afa20f..99295e8 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -1482,7 +1482,7 @@
                   const char *name = string_of($name);
                   parser_enter_program( name, false, &main_error );
                   if( main_error ) {
-                    error_msg(@name, "PROGRAM-ID 'main' is invalid with -main option");
+                    error_msg(@name, "PROGRAM-ID 'main' is invalid with %<-main%> option");
                     YYERROR;
                   }
 
@@ -1518,7 +1518,8 @@
                   int main_error = 0;
                   parser_enter_program( $NAME, true, &main_error );
                   if( main_error ) {
-                    error_msg(@NAME, "FUNCTION-ID 'main' is invalid with -main option");
+                    error_msg(@NAME, "FUNCTION-ID %<main%> is invalid "
+                              "with %<-main%> option");
                     YYERROR;
                   }
                   if( symbols_begin() == symbols_end() ) {
@@ -1589,7 +1590,7 @@
 		{
 		  cbl_unimplementedw("HIGH-ORDER-LEFT was ignored");
 		  if( ! current.option_binary(cbl_options_t::high_order_left_e) ) {
-		    error_msg(@3, "unable to set HIGH_ORDER_LEFT");
+		    error_msg(@3, "unable to set %<HIGH_ORDER_LEFT%>");
 		  }
 		}
         |       FLOAT_BINARY default_kw is HIGH_ORDER_RIGHT[opt]
@@ -2520,7 +2521,7 @@
 		{
 		  auto p = cmd_or_env_special_of($device);
 		  if( !p ) {
-		    error_msg(@device, "%s is not a device name");
+		    error_msg(@device, "%s is not a device name", $device);
 		    YYERROR;
 		  }
 
@@ -2646,7 +2647,7 @@
 alphabet_etc:   alphabet_lit
                 {
                   if( $1.len > 1 ) {
-                    error_msg(@1, "'%c' can be only a single letter", $1.data);
+                    error_msg(@1, "%qs can be only a single letter", $1.data);
                     YYERROR;
                   }
                   $$ = (unsigned char)$1.data[0];
@@ -2912,7 +2913,7 @@
                   f->varying_size.explicitly = f->varies();
                   if( f->varying_size.max != 0 ) {
                     if( !(f->varying_size.min <= f->varying_size.max) ) {
-                      error_msg(@1, "%zu must be <= %zu",
+                      error_msg(@1, "%zu must be less than or equal to %zu",
                                 f->varying_size.min, f->varying_size.max);
                       YYERROR;
                     }
@@ -2988,7 +2989,7 @@
                   }
                   $$.max = n;
                   if( !($$.min < $$.max) ) {
-                    error_msg(@max, "FROM (%xz) must be less than TO (%zu)",
+                    error_msg(@max, "FROM (%zu) must be less than TO (%zu)",
                               $$.min, $$.max);
                     YYERROR;
                   }
@@ -3184,7 +3185,7 @@
                       }
                       initial = string_of(field.data.value_of());
                       if( !initial ) {
-                        error_msg(@1, xstrerror(errno));
+                        error_msg(@1, "could not convert value to string");
                         YYERROR;
                       }
                       char decimal = symbol_decimal_point();
@@ -3638,7 +3639,7 @@
                   }
                   if( field_index($thru) <= field_index($orig) ) {
                     error_msg(@orig, "cannot RENAME %s %s THRU %s %s "
-                             "because they're in the wrong order",
+                             "because they are in the wrong order",
 			      $orig->level_str(), name_of($orig),
 			      $thru->level_str(), name_of($thru));
                     YYERROR;
@@ -3680,7 +3681,7 @@
                     case FldNumericEdited:
                       if( $field->has_attr(signable_e) ) {
                         error_msg(@2,  "%s has 'S' in PICTURE, cannot be BLANK WHEN ZERO",
-                                  $field->name, cbl_field_type_str($field->type) );
+                                  $field->name );
                       }
                       break;
                     default:
@@ -3891,9 +3892,8 @@
                       auto redefined = symbol_redefines(field);
                       if( redefined && redefined->type == FldPointer ) {
                         if( yydebug ) {
-                          yywarn("expanding %s size from %u bytes to "
-				 HOST_WIDE_INT_PRINT " "
-				 "because it redefines %s with USAGE POINTER",
+                          yywarn("expanding %s size from %u bytes to %wd "
+				 "because it redefines %s with %<USAGE POINTER%>",
                                 field->name, field->size(),
                                 int_size_in_bytes(ptr_type_node),
                                 redefined->name);
@@ -3986,7 +3986,7 @@
                   field->data.capacity = type_capacity(field->type, $4);
                   field->data.digits = $4;
                   if( long(field->data.digits) != $4 ) {
-                    error_msg(@2, "indicated size would be %ld bytes, "
+                    error_msg(@2, "indicated size would be %d bytes, "
                              "maximum data item size is %u",
                              $4, UINT32_MAX);
                   }
@@ -4056,7 +4056,7 @@
 		      (dialect_gnu() || dialect_mf()) )
 		  { // PIC X COMP-X or COMP-9
 		    if( ! field->has_attr(all_x_e) ) {
-		      error_msg(@2, "COMP PICTURE requires all X's or all 9's");
+		      error_msg(@2, "COMP PICTURE requires all X%'s or all 9%'s");
                       YYERROR;
 		    }
 		  } else {
@@ -4091,7 +4091,7 @@
                   }
                   ERROR_IF_CAPACITY(@PIC, field);
                   if( !is_numeric_edited($picture) ) {
-                    error_msg(@picture, numed_message);
+                    error_msg(@picture, "%s", numed_message);
                     YYERROR;
                   }
                   field->data.picture = $picture;
@@ -4170,7 +4170,7 @@
                     $$.nbyte += count; // AX9(3) has count 5
                   }
 		  if( count < 0 ) {
-		    error_msg(@2, "PICTURE count '(%d)' is negative", count );
+		    error_msg(@2, "PICTURE count %<(%d)%> is negative", count );
 		    YYERROR;
 		  }
                 }
@@ -4189,7 +4189,7 @@
                 {
                   $$ = $1;
 		  if( $$ == 0 ) {
-		    error_msg(@1, "'(0)' invalid in PICTURE (ISO 2023 13.18.40.3)");
+		    error_msg(@1, "%<(0)%> invalid in PICTURE (ISO 2023 13.18.40.3)");
 		  }
                 }
                 ;
@@ -4203,14 +4203,14 @@
                   REAL_VALUE_TYPE rn = numstr2i($NUMSTR.string, $NUMSTR.radix);
                   $$ = real_to_integer (&rn);
 		  if( $$ == 0 ) {
-		    error_msg(@2, "'(0)' invalid in PICTURE (ISO 2023 13.18.40.3)");
+		    error_msg(@2, "%<0%> invalid in PICTURE (ISO 2023 13.18.40.3)");
 		  }
                 }
 	|	'(' NAME ')'
                 {
 		  auto value = cdf_value($NAME);
 		  if( ! (value && value->is_numeric()) ) {
-		    error_msg(@NAME, "PICTURE '(%s)' requires a CONSTANT value", $NAME );
+		    error_msg(@NAME, "PICTURE %qs requires a CONSTANT value", $NAME );
 		    YYERROR;
 		  }
 		  int nmsg = 0;
@@ -4223,13 +4223,13 @@
 		    if( !real_identical (TREE_REAL_CST_PTR (field->data.value_of()),
 				         &vi) ) {
 		      nmsg++;
-		      error_msg(@NAME, "invalid PICTURE count '(%s)'",
+		      error_msg(@NAME, "invalid PICTURE count %<(%s)%>",
 				field->data.initial );
 		    }
 		  }
 		  $$ = value->as_number();
 		  if( $$ <= 0 && !nmsg) {
-		    error_msg(@NAME, "invalid PICTURE count '(%s)'", $NAME );
+		    error_msg(@NAME, "invalid PICTURE count %<(%s)%>", $NAME );
 		  }
                 }
                 ;
@@ -4974,12 +4974,11 @@
 
 statement:      error {
                   if( current.declarative_section_name() ) {
-		    error_msg(@1, "missing END DECLARATIVES or SECTION name",
-			      nparse_error);
+		    error_msg(@1, "missing END DECLARATIVES or SECTION name");
                     YYABORT;
                   }
                   if( max_errors_exceeded(nparse_error) ) {
-                    error_msg(@1, "max errors %d reached", nparse_error);
+                    error_msg(@1, "max errors %zu reached", nparse_error);
                     YYABORT;
                   }
                 }
@@ -5692,7 +5691,8 @@
                     gcc_unreachable();
                   }
                   if( !matches ) {
-                    error_msg(@end, "END %s %s' does not match IDENTIFICATION DIVISION '%s'",
+                    error_msg(@end, "END %s %s does not match "
+                                    "%<IDENTIFICATION DIVISION %s%>",
                               token_name, name, prog->name);
                     YYERROR;
                   }
@@ -5723,9 +5723,9 @@
 		    token_name = "FUNCTION";
                     break;
                   default:
-                    cbl_internal_error( "END token invalid");
+                    cbl_internal_error( "%<END%> token invalid");
                   }
-		  error_msg(@end, "END %s requires NAME before '.'", token_name);
+		  error_msg(@end, "%<END%> %s requires %<NAME%> before %<.%>", token_name);
 		  YYERROR;
 		}
                 ;
@@ -6776,7 +6776,7 @@
                 {
                   statement_begin(@1, MOVE);
                   if( $scalar->field->type == FldIndex ) {
-                    error_msg(@1, "'%s' cannot be MOVEd because it's an INDEX",
+                    error_msg(@1, "%qs cannot be MOVEd because it is an %<INDEX%>",
 			     name_of($scalar->field) );
                     YYERROR;
                   }
@@ -7168,20 +7168,20 @@
                 {
                   if( $1 ) {
 		    if( *$1 == '-' ) {
-		      error_msg(@1, "SECTION segment %<%s%> is negative", $1);
+		      error_msg(@1, "SECTION segment %qs is negative", $1);
                     } else {
 		      if( dialect_ibm() ) {
 			int sectno;
 			sscanf($1, "%d", &sectno);
 			if( ! (0 <= sectno && sectno <= 99) ) {
-			  error_msg(@1, "SECTION segment %<%s%> must be 0-99", $1);
+			  error_msg(@1, "SECTION segment %qs must be 0-99", $1);
 			} else {
 			  if(false) { // stand-in for warning, someday.
-			    yywarn("SECTION segment %<%s%> was ignored", $1);
+			    yywarn("SECTION segment %qs was ignored", $1);
 			  }
 			}
 		      } else {
-			cbl_unimplemented("SECTION segment %<%s%> is not ISO syntax", $1);
+			cbl_unimplemented("SECTION segment %qs is not ISO syntax", $1);
 		      }
                     }
 		  }
@@ -7932,7 +7932,7 @@
 			    "EXCEPTION CONDITION: %s", $NAME);
                     YYERROR;
                   }
-                  cbl_unimplemented("RAISE <EXCEPTION OBJECT>");
+                  cbl_unimplemented("RAISE %<EXCEPTION OBJECT%>");
                   YYERROR;
                 }
                 ;
@@ -8009,7 +8009,7 @@
                     YYERROR;
                   }
                   if( $read_key->field && $read_next < 0 ) {
-                    error_msg(@1, "cannot read NEXT with KEY", $$->name);
+                    error_msg(@1, "cannot read NEXT with KEY %qs", $$->name);
                     YYERROR;
                   }
 
@@ -8803,7 +8803,7 @@
                   }
                   if( dimensions($key->field) < $key->nsubscript() ) {
                     error_msg(@1, "too many subscripts: "
-                              "%zu for table of %zu dimensions",
+                              "%u for table of %zu dimensions",
                               $key->nsubscript(), dimensions($key->field) );
                     YYERROR;
                   }
@@ -9137,7 +9137,7 @@
 		    if( is_literal(match) && is_literal(replace) ) {
 		      if( !$match->all && !$replace_oper->all) {
 			if( match->data.capacity != replace->data.capacity ) {
-			  error_msg(@match, "'%s', size %u NOT EQUAL '%s', size %u",
+			  error_msg(@match, "%qs, size %u NOT EQUAL %qs, size %u",
 				    nice_name_of(match), match->data.capacity, 
 				    nice_name_of(replace), replace->data.capacity);
 			  YYERROR;
@@ -10212,8 +10212,8 @@
 								    args.data());
                   if( p != NULL ) {
 		    auto loc = symbol_field_location(field_index(p->field));
-                    error_msg(loc, "FUNCTION %s has "
-                              "inconsistent parameter type %zu ('%s')",
+                    error_msg(loc, "FUNCTION %qs has "
+                              "inconsistent parameter type %zu (%qs)",
                               keyword_str($1), p - args.data(), name_of(p->field) );
                     YYERROR;
                   }
@@ -10290,7 +10290,7 @@
                   location_set(@1);
                   $$ = new_alphanumeric("FIND-STRING");
                   /* auto r1 = new_reference(new_literal(strlen($r1), $r1, quoted_e)); */
-		  cbl_unimplemented("FIND_STRING");
+		  cbl_unimplemented("%<FIND_STRING%>");
                   /* if( ! intrinsic_call_4($$, FIND_STRING, r1, $r2) ) YYERROR; */
                 }
 
@@ -10757,7 +10757,7 @@
                   $$.arg2 = cbl_refer_t::empty();
                 }
         |       LOCALE NAME  { $$.is_locale = true;  $$.arg2 = NULL;
-                  cbl_unimplemented("NUMVAL_C LOCALE"); YYERROR;
+                  cbl_unimplemented("%<NUMVAL_C LOCALE%>"); YYERROR;
                 }
         |       varg         { $$.is_locale = false; $$.arg2 = $1; }
                 ;
@@ -11541,7 +11541,7 @@
   case ge_op: return lt_op;
   case gt_op: return le_op;
   }
-  cbl_errx( "%s:%d: invalid relop_t %d", __func__, __LINE__, op);
+  cbl_internal_error("%s:%d: invalid %<relop_t%> %d", __func__, __LINE__, op);
 
   return relop_t(0); // not reached
 }
@@ -11834,7 +11834,7 @@
       auto tgt = cbl_field_of(symbol_at(udf.linkage_fields.at(i).isym));
       if( ! valid_move(tgt, arg.field) ) {
 	auto loc = symbol_field_location(field_index(arg.field));
-	error_msg(loc, "FUNCTION %s arg %zu, '%s' cannot be passed to %s, type %s",
+	error_msg(loc, "FUNCTION %s argument %zu, '%s' cannot be passed to %s, type %s",
 		  L->name, i, arg.field->pretty_name(),
 		  tgt->pretty_name(), 3 + cbl_field_type_str(tgt->type) );
 	return false;
@@ -12032,7 +12032,7 @@
 
  protected:
   static void dump_input( const cbl_refer_t& refer ) {
-    yywarn( "%s:\t%s", __func__, field_str(refer.field) );
+    yywarn( "%s: %s", __func__, field_str(refer.field) );
   }
 };
 
@@ -12341,7 +12341,7 @@
   case boolean_e:
     for( const char *p = input; *p != '\0'; p++ ) {
       if( ssize_t(8 * sizeof(integer) - 1) < p - input ) {
-        yywarn("'%s' was accepted as %d", input, integer);
+        yywarn("'%s' was accepted as %zu", input, integer);
         break;
       }
       switch(*p) {
@@ -12351,7 +12351,7 @@
           integer |= ((*p) == '0' ? 0 : 1);
           break;
       default:
-        yywarn("'%s' was accepted as %d", input, integer);
+        yywarn("'%s' was accepted as %zu", input, integer);
 	break;
       }
     }
@@ -12359,7 +12359,7 @@
     return output;
   }
   if( erc == -1 ) {
-    yywarn("'%s' was accepted as %lld", input, output);
+    yywarn("'%s' was accepted as %wd", input, integer);
   }
   return output;
 }
@@ -12982,7 +12982,7 @@
   }
 
   // must be [BN]X
-  cbl_internal_error("'%s': invalid literal prefix", prefix);
+  cbl_internal_error("invalid literal prefix: %qs", prefix);
   gcc_unreachable();
   return none_e;
 }
diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h
index ffb4c98..8194614 100644
--- a/gcc/cobol/parse_ante.h
+++ b/gcc/cobol/parse_ante.h
@@ -335,7 +335,7 @@
     label.line = yylineno;
     if( -1 == snprintf(label.name, sizeof(label.name),
                        "%.*s_%d", (int)sizeof(label.name)-6, skel, yylineno) ) {
-      yyerror("could not create unique label '%s_%d' because it is too long",
+      yyerror("could not create unique label %<%s_%d%> because it is too long",
               skel, yylineno);
     }
   }
@@ -2116,7 +2116,7 @@
 	  if( ! dialect_ibm() ) {
 	    error_msg(loc,
 		      "Per ISO a program with DECLARATIVES must begin with a SECTION, "
-		      "requires -dialect ibm");
+		      "requires %<-dialect ibm%>");
 	  }
 	}
       }
@@ -2558,7 +2558,8 @@
   case FldPointer:
     return true;
   }
-  cbl_internal_error( "%s:%d: invalid symbol_type_t %d", __func__, __LINE__, field->type );
+  cbl_internal_error( "%s:%d: invalid %<symbol_type_t%> %d",
+                      __func__, __LINE__, field->type );
   return false;
 }
 
diff --git a/gcc/cobol/parse_util.h b/gcc/cobol/parse_util.h
index 11b86a3..006cea7 100644
--- a/gcc/cobol/parse_util.h
+++ b/gcc/cobol/parse_util.h
@@ -348,7 +348,7 @@
                            return token == descr.token;
                          } );
   if( p == function_descrs_end ) {
-    cbl_internal_error( "%s: intrinsic function  %s not found",
+    cbl_internal_error( "%s: intrinsic function %qs not found",
                         __func__, keyword_str(token) );
   }
 
diff --git a/gcc/cobol/scan.l b/gcc/cobol/scan.l
index 52a0b94..9b586e9 100644
--- a/gcc/cobol/scan.l
+++ b/gcc/cobol/scan.l
@@ -982,7 +982,7 @@
   BINARY-LONG	   		{ return bcomputable(FldNumericBin5, 4); }
   BINARY-DOUBLE			{ return bcomputable(FldNumericBin5, 8); }
   BINARY-LONG-LONG		{ if( ! dialect_mf() ) {
-				    error_msg(yylloc, "%s requires -dialect mf", yytext);
+				    dialect_error(yylloc, yytext, "mf");
 				  }
 				  return bcomputable(FldNumericBin5, 8);
 				}
@@ -993,7 +993,7 @@
   FLOAT-BINARY-32		{ return ucomputable(FldFloat, 4); }
   FLOAT-BINARY-64		{ return ucomputable(FldFloat, 8); }
   FLOAT-BINARY-128		{ return ucomputable(FldFloat, 16); }
-  FLOAT-DECIMAL-(16|34)		{ not_implemented("USAGE type: FLOAT_DECIMAL");
+  FLOAT-DECIMAL-(16|34)		{ not_implemented("USAGE type: %<FLOAT_DECIMAL%>");
 				  return FLOAT_DECIMAL; // causes syntax error
 				}
   /* 21) The representation and length of a data item described with USAGE
@@ -1019,7 +1019,7 @@
   POINTER           	{ yylval.field_attr = none_e;     return POINTER; }
 
   PROCEDURE-POINTER    	{ if( dialect_gcc() ) {
-			    error_msg(yylloc, "%s requires -dialect ibm or mf", yytext);
+			    dialect_error(yylloc, yytext, "ibm or mf");
 			  }
 			  yylval.field_attr = prog_ptr_e;
 			  return POINTER;  // return it anyway
@@ -2482,10 +2482,9 @@
 <<EOF>>         {
 
                   if( YY_START == quoted1 || YY_START == quoted2 ) {
-		    error_msg(yylloc, "syntax error: unterminated string '%s'",
+		    error_msg(yylloc, "syntax error: unterminated string %<%s%>",
 			     tmpstring);
 		    return NO_CONDITION;
-		    cbl_internal_error("");
                   }
                   yypop_buffer_state();
 
diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h
index 21e89e4..037c929 100644
--- a/gcc/cobol/scan_ante.h
+++ b/gcc/cobol/scan_ante.h
@@ -159,11 +159,11 @@
     //  exponent is implementor-defined." (We allow 9999.)
     nx = std::count_if(p, eoinput, fisdigit);
     if( 4 < nx ) {
-      error_msg(yylloc, "exponent %s more than 4 digits", ++p);
+      error_msg(yylloc, "exponent %qs more than 4 digits", ++p);
       return NO_CONDITION;
     }
     if( eoinput != std::find(p, eoinput, symbol_decimal_point()) ) {
-      error_msg(yylloc, "exponent includes decimal point", ++p);
+      error_msg(yylloc, "exponent %qs includes decimal point", ++p);
       return NO_CONDITION;
     }
 
@@ -187,7 +187,7 @@
     }
   }
   if( 1 < std::count(input, eoinput, symbol_decimal_point()) ) {
-    error_msg(yylloc, "invalid numeric literal", ++p);
+    error_msg(yylloc, "invalid numeric literal %qs", ++p);
     return NO_CONDITION;
   }
 
@@ -295,7 +295,7 @@
   void splat() const {
     int i=0;
     for( const auto& status : c ) {
-      yywarn( "%4d\t%s", ++i, status.str() );
+      yywarn( "%d %s", ++i, status.str() );
     }
   }
 } parsing;
@@ -305,7 +305,7 @@
 
 static int scanner_token() {
   if( parsing.empty() ) {
-    error_msg(yylloc, ">>ELSE or >>END-IF without >>IF");
+    error_msg(yylloc, "%<>>ELSE%> or %<>>END-IF%> without %<>>IF%>");
     return NO_CONDITION;
   }
   return parsing.top().token;
@@ -317,33 +317,32 @@
 void scanner_parsing( int token, bool tf ) {
   parsing.push( cdf_status_t(token, tf) );
   if( yydebug ) {
-    yywarn("%10s: parsing now %5s, depth %lu",
-            keyword_str(token), boolalpha(parsing.on()),
-	   gb4(parsing.size()));
+    yywarn("%s: parsing now %s, depth %zu",
+            keyword_str(token), boolalpha(parsing.on()), parsing.size());
     parsing.splat();
   }
 }
 void scanner_parsing_toggle() {
   if( parsing.empty() ) {
-    error_msg(yylloc, ">>ELSE without >>IF");
+    error_msg(yylloc, "%<>>ELSE%> without %<>>IF%>");
     return;
   }
   parsing.top().toggle();
   if( yydebug ) {
-    yywarn("%10s: parsing now %5s",
+    yywarn("%s: parsing now %s",
             keyword_str(CDF_ELSE), boolalpha(parsing.on()));
   }
 }
 void scanner_parsing_pop() {
   if( parsing.empty() ) {
-    error_msg(yylloc, ">>END-IF without >>IF");
+    error_msg(yylloc, "%<>>END-IF%> without %<>>IF%>");
     return;
   }
   parsing.pop();
   if( yydebug ) {
-    yywarn("%10s: parsing now %5s, depth %lu",
+    yywarn("%s: parsing now %s, depth %zu",
             keyword_str(CDF_END_IF), boolalpha(parsing.on()),
-	   gb4(parsing.size()));
+	   parsing.size());
     parsing.splat();
   }
 }
@@ -792,7 +791,7 @@
     return cbl_field_of(e)->level == 88? NAME88 : CLASS_NAME;
     break;
   default:
-    yywarn("%s:%d: invalid symbol type %s for symbol \"%s\"",
+    yywarn("%s:%d: invalid symbol type %s for symbol %qs",
           __func__, __LINE__, cbl_field_type_str(type), name);
     return NAME;
   }
diff --git a/gcc/cobol/scan_post.h b/gcc/cobol/scan_post.h
index 385ea67..a273da9 100644
--- a/gcc/cobol/scan_post.h
+++ b/gcc/cobol/scan_post.h
@@ -297,7 +297,7 @@
       token = LEVEL;
       break;
     case YDF_NUMBER:
-      if( yy_flex_debug ) yywarn("final token is YDF_NUMBER");
+      if( yy_flex_debug ) yywarn("final token is %<YDF_NUMBER%>");
       yylval.number = ydflval.number;
       token = LEVEL;
       break;
diff --git a/gcc/cobol/show_parse.h b/gcc/cobol/show_parse.h
index d417af3..db24807 100644
--- a/gcc/cobol/show_parse.h
+++ b/gcc/cobol/show_parse.h
@@ -424,30 +424,31 @@
 
 // Use CHECK_FIELD when a should be non-null, and a->var_decl_node also should
 // by non-null:
-#define CHECK_FIELD(a)          \
-        do{                     \
-        if(!a)                  \
-            {                   \
-            yywarn("%s(): parameter " #a " is NULL", __func__); \
-            gcc_unreachable();  \
-            }                   \
-        if( !a->var_decl_node && a->type != FldConditional && a->type != FldLiteralA)  \
-            {                   \
-            yywarn("%s() parameter " #a " is variable %s<%s> with NULL var_decl_node", \
-                __func__,       \
-                a->name,        \
-                cbl_field_type_str(a->type) ); \
-            gcc_unreachable();  \
-            }                   \
-        }while(0);
+#define CHECK_FIELD(a)                                                  \
+        do {                                                                  \
+        if(!a)                                                          \
+            {                                                           \
+            yywarn("%s: parameter %<" #a "%> is NULL", __func__);        \
+            gcc_unreachable();                                          \
+            }                                                           \
+        if( !a->var_decl_node && a->type != FldConditional && a->type != FldLiteralA) \
+            {                                                           \
+            yywarn("%s: parameter %<" #a "%> is variable "               \
+                   "%s<%s> with NULL %<var_decl_node%>",                \
+                __func__,                                               \
+                a->name,                                                \
+                cbl_field_type_str(a->type) );                          \
+            gcc_unreachable();                                          \
+            }                                                           \
+        } while(0);
 
-#define CHECK_LABEL(a)            \
-        do{                     \
-        if(!a)                  \
-            {                   \
-            yywarn("%s(): parameter " #a " is NULL", __func__); \
-            gcc_unreachable();  \
-            }                   \
+#define CHECK_LABEL(a)                                                  \
+        do{                                                             \
+        if(!a)                                                          \
+            {                                                           \
+            yywarn("%s: parameter %<" #a "%> is NULL", __func__);       \
+            gcc_unreachable();                                          \
+            }                                                           \
         }while(0);
 
 #ifdef INCORPORATE_ANALYZER
diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc
index d75ca29..089c9c1 100644
--- a/gcc/cobol/symbols.cc
+++ b/gcc/cobol/symbols.cc
@@ -2836,7 +2836,7 @@
 struct symbol_elem_t *
 symbol_field_same_as( cbl_field_t *tgt, const cbl_field_t *src ) {
   if( target_in_src(tgt, src) ) {
-    ERROR_FIELD(tgt, "%s %s  may not reference itself as part of %s %s",
+    ERROR_FIELD(tgt, "%s %s may not reference itself as part of %s %s",
             tgt->level_str(), tgt->name, src->level_str(), src->name);
     return NULL;
   }
@@ -3088,7 +3088,7 @@
     return true;
   }
   auto taken = alphabet[ch];
-  error_msg(loc, "ALPHABET %s, character '%c' (X'%x') "
+  error_msg(loc, "ALPHABET %s, character %<%c%> (X%'%x%') "
            "in position %d already defined at position %d",
            name,
            ISPRINT(ch)? ch : '?', ch,
@@ -3493,7 +3493,7 @@
   static const size_t noconv = size_t(-1);
 
   if (cd == (iconv_t)-1) {
-    yywarn("failed iconv_open tocode = '%s' fromcode = %s", tocode, fromcode);
+    yywarn("failed %<iconv_open%> tocode = %<%s%> fromcode = %s", tocode, fromcode);
   }
 
   bool using_assumed = fromcode == os_locale.assumed;
diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h
index 84a984e..c09fbcc 100644
--- a/gcc/cobol/symbols.h
+++ b/gcc/cobol/symbols.h
@@ -131,13 +131,13 @@
   case FldIndex:
     return true;
   }
-  yywarn( "%s:%d: invalid symbol_type_t %d", __func__, __LINE__, type );
+  cbl_internal_error( "%s:%d: invalid %<symbol_type_t%> %d", __func__, __LINE__, type );
   return false;
 }
 
 struct os_locale_t {
   char assumed[16];
-  char *codeset;
+  const char *codeset;
 };
 
 const char * cbl_field_attr_str( cbl_field_attr_t attr );
@@ -1216,6 +1216,8 @@
     literal_an() : is_quoted(false), value("???") {}
     literal_an( const char value[], bool is_quoted )
       : is_quoted(is_quoted), value(value) {}
+    literal_an( const literal_an& that )
+      : is_quoted(that.is_quoted), value(that.value) {}
     literal_an& operator=( const literal_an& that ) {
       is_quoted = that.is_quoted;
       value = that.value;
@@ -1495,7 +1497,7 @@
   }
 
   void dump() const {
-    yywarn("'%s': %s, '%c' to '%c' (low 0x%02x, high 0x%02x)",
+    yywarn("%qs: %s, %<%c%> to %<%c%> (low 0x%x, high 0x%x)",
           name, encoding_str(encoding),
           low_index, last_index, low_index, high_index);
     if( encoding == custom_encoding_e ) {
diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc
index b6c9280..d8423e0 100644
--- a/gcc/cobol/util.cc
+++ b/gcc/cobol/util.cc
@@ -130,7 +130,7 @@
     case SymDataSection:
         return "SymDataSection";
     }
-    dbgmsg("%s:%d: invalid symbol_type_t %d", __func__, __LINE__, type);
+    cbl_internal_error("%s:%d: invalid %<symbol_type_t%> %d", __func__, __LINE__, type);
     return "???";
 }
 
@@ -179,7 +179,7 @@
   case FldBlob:
     return "FldBlob";
  }
-  dbgmsg("%s:%d: invalid symbol_type_t %d", __func__, __LINE__, type);
+  cbl_internal_error("%s:%d: invalid %<symbol_type_t%> %d", __func__, __LINE__, type);
   return "???";
 }
 
@@ -479,7 +479,7 @@
     case FldFloat:
       return true; // takes up space
     }
-    dbgmsg("%s:%d: invalid symbol_type_t %d", __func__, __LINE__, type);
+    cbl_internal_error("%s:%d: invalid %<symbol_type_t%> %d", __func__, __LINE__, type);
     return false;
 }
 
@@ -902,8 +902,8 @@
                                                  return TOUPPER(ch) == 'E';
                                                } );
               if( !has_exponent && data.precision() < pend - p ) {
-                error_msg(loc, "%s cannot represent  VALUE '%s' exactly (max .%zu)",
-                         name, data.initial, pend - p);
+                error_msg(loc, "%s cannot represent VALUE %qs exactly (max %c%zu)",
+                          name, data.initial, '.', pend - p);
               }
             }
           }
@@ -1805,7 +1805,7 @@
                   (fmt_size_t)(c.size() - --n), v.lineno, no_wd(wd, v.name) );
         }
       } else {
-        dbgmsg("unable to get current working directory: %m");
+        dbgmsg("unable to get current working directory: %s", xstrerror(errno));
       }
       free(wd);
     }
@@ -1953,6 +1953,8 @@
 static const diagnostic_option_id option_zero;
 size_t parse_error_inc();
 
+void ydferror( const char gmsgid[], ... ) ATTRIBUTE_GCOBOL_DIAG(1, 2);
+
 void
 ydferror( const char gmsgid[], ... ) {
   verify_format(gmsgid);
@@ -2029,6 +2031,9 @@
   ERROR_MSG_BODY
 }
 
+void error_msg( const YDFLTYPE& loc, const char gmsgid[], ... )
+  ATTRIBUTE_GCOBOL_DIAG(2, 3);
+
 void error_msg( const YDFLTYPE& loc, const char gmsgid[], ... ) {
   ERROR_MSG_BODY
 }
@@ -2119,7 +2124,7 @@
       dbgmsg( "%s:%d: could not compile regex: %s", __func__, __LINE__, regexmsg );
       return line;
     }
-    error_msg(yylloc, "invalid #line directive: %s", line );
+    error_msg(yylloc, "invalid %<#line%> directive: %s", line );
     return line;
   }
 
@@ -2129,7 +2134,7 @@
   int fileline;
 
   if( 1 != sscanf(line_str, "%d", &fileline) )
-    yywarn("could not parse line number %s from #line directive", line_str);
+    yywarn("could not parse line number %s from %<#line%> directive", line_str);
 
   input_file_t input_file( filename, ino_t(0), fileline ); // constructor sets inode
 
@@ -2216,19 +2221,9 @@
   yy_flex_debug = flex? 1 : 0;
   ydfdebug = yydebug = yacc? 1 : 0;
   f_trace_debug = parser? 1 : 0;
-
-  char *ind = getenv("INDICATOR_COLUMN");
-  if( ind ) {
-    int col;
-    if( 1 != sscanf(ind, "%d", &col) ) {
-      yywarn("ignored non-integer value for INDICATOR_COLUMN=%s", ind);
-    }
-    cobol_set_indicator_column(col);
-  }
 }
 
-os_locale_t os_locale = { "UTF-8", xstrdup("C.UTF-8") };
-
+os_locale_t os_locale = { "UTF-8", "C.UTF-8" };
 
 void
 cobol_parse_files (int nfile, const char **files)
@@ -2239,7 +2234,7 @@
   } else {
     char *codeset = nl_langinfo(CODESET);
     if( ! codeset ) {
-      yywarn("nl_langinfo failed after setlocale succeeded");
+      yywarn("%<nl_langinfo%> failed after %<setlocale()%> succeeded");
     } else {
       os_locale.codeset = codeset;
     }
@@ -2351,7 +2346,7 @@
 
 void
 dialect_error( const YYLTYPE& loc, const char term[], const char dialect[] ) {
-  error_msg(loc, "%s is not ISO syntax, requires -dialect %s",
+  error_msg(loc, "%s is not ISO syntax, requires %<-dialect %s%>",
            term, dialect);
 }
 
diff --git a/gcc/cobol/util.h b/gcc/cobol/util.h
index 54d3930..9388b50 100644
--- a/gcc/cobol/util.h
+++ b/gcc/cobol/util.h
@@ -31,11 +31,13 @@
 #ifndef _UTIL_H_
 #define _UTIL_H_
 
-void cbl_message(int fd, const char *format_string, ...);
-void cbl_internal_error(const char *format_string, ...);
+void cbl_message(int fd, const char *format_string, ...)
+  ATTRIBUTE_PRINTF_2;
+void cbl_internal_error(const char *format_string, ...)
+  ATTRIBUTE_GCOBOL_DIAG(1, 2);
 
-void cbl_err(const char *format_string, ...);
-void cbl_errx(const char *format_string, ...);
+void cbl_err(const char *format_string, ...) ATTRIBUTE_GCOBOL_DIAG(1, 2);
+void cbl_errx(const char *format_string, ...) ATTRIBUTE_GCOBOL_DIAG(1, 2);
 
 bool fisdigit(int c);
 bool fisspace(int c);