diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 11dcea94728c97da2ad1da47167a7506c4517b1d..a5b4870bb77bb5ebd4a2b7463b5c3d1ef48808cb 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -12982,7 +12982,7 @@ literal_subscripts_valid( YYLTYPE loc, const cbl_refer_t& name ) { const char *upper_phrase = ""; if( ! oob->occurs.bounds.fixed_size() ) { - static char ub[32]; + static char ub[32] = "boo"; sprintf(ub, " to %lu", oob->occurs.bounds.upper); upper_phrase = ub; } diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index 4737187497302b4af632fb7e903789c8107e5f6b..52d78c98f39f336a3a1d24e6e4c3036838d1bebd 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -1927,6 +1927,14 @@ gcc_location_set_impl( const LOC& loc ) { location_dump(__func__, __LINE__, "parser", loc); } +void gcc_location_set( const YYLTYPE& loc ) { + gcc_location_set_impl(loc); +} + +void gcc_location_set( const YDFLTYPE& loc ) { + gcc_location_set_impl(loc); +} + #ifdef NDEBUG # define verify_format(M) #else @@ -2007,36 +2015,38 @@ class temp_loc_t : protected YYLTYPE { } }; -template <typename LOC> -void -static error_msg_impl( const LOC& loc, const char gmsgid[], ... ) { - temp_loc_t looker(loc); - verify_format(gmsgid); - parse_error_inc(); - global_dc->begin_group(); - va_list ap; - va_start (ap, gmsgid); - rich_location richloc (line_table, token_location); - bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, - gmsgid, &ap, DK_ERROR); - va_end (ap); +/* + * Both CDF and parser need to call error_msg, each with their own distinct + * location type, not because they *need* to be different, but because they + * are, as an artifact of using different prefixes. Possibly a better plan + * would be to convert cdf.y to a pure parser, using no global variables. But + * this is where we are. + * + * Because we can't reliably instantiate it as a forward-declared template + * function, and because the paramters are variadic, we can't use a template + * function or call one. So, a macro. + */ + +#define ERROR_MSG_BODY \ + temp_loc_t looker(loc); \ + verify_format(gmsgid); \ + parse_error_inc(); \ + global_dc->begin_group(); \ + va_list ap; \ + va_start (ap, gmsgid); \ + rich_location richloc (line_table, token_location); \ + bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, \ + gmsgid, &ap, DK_ERROR); \ + va_end (ap); \ global_dc->end_group(); -} + void error_msg( const YYLTYPE& loc, const char gmsgid[], ... ) { - error_msg_impl(loc, gmsgid); + ERROR_MSG_BODY } void error_msg( const YDFLTYPE& loc, const char gmsgid[], ... ) { - error_msg_impl(loc, gmsgid); -} - -void gcc_location_set( const YYLTYPE& loc ) { - gcc_location_set_impl(loc); -} - -void gcc_location_set( const YDFLTYPE& loc ) { - gcc_location_set_impl(loc); + ERROR_MSG_BODY } void