https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68950
Bug ID: 68950 Summary: [fortran] gfc_format_decoder cannot handle %qE Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: vries at gcc dot gnu.org Target Milestone: --- I. Consider test.f90: ... subroutine bar () implicit none !$acc routine nohost gang end subroutine ... When compiling with current gomp-4_0-branch, we run into an assert during error: ... $ ./lean-fortran/install/bin/gfortran test.f90 -O2 -fopenacc -S ‘ test.f90:1:0: subroutine bar () in pp_format, at pretty-print.c:635 0x1e3426e pp_format(pretty_printer*, text_info*) src/gcc/pretty-print.c:635 0x1e2de0a diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*) src/gcc/diagnostic.c:797 0x1e2f0d7 error(char const*, ...) src/gcc/diagnostic.c:1157 0x1eae569 decl_attributes(tree_node**, tree_node*, int) src/gcc/attribs.c:450 0x842726 build_function_decl src/gcc/fortran/trans-decl.c:2114 0x84506e gfc_create_function_decl(gfc_namespace*, bool) src/gcc/fortran/trans-decl.c:2755 0x850b9b gfc_generate_function_code(gfc_namespace*) src/gcc/fortran/trans-decl.c:5967 0x81885b gfc_generate_code(gfc_namespace*) src/gcc/fortran/trans.c:1977 0x7ae412 translate_all_program_units src/gcc/fortran/parse.c:5549 0x7aea6d gfc_parse_file() src/gcc/fortran/parse.c:5755 0x802356 gfc_be_parse_file src/gcc/fortran/f95-lang.c:201 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. ... II. The assert that triggers is: ... (gdb) #5 0x0000000001e3426f in pp_format (pp=0x2b85a80, text=0x7fffffffd310) at /home/vries/gcc_versions/devel/gomp-4_0-branch/src/gcc/pretty-print.c:635 635 gcc_assert (ok); (gdb) l 630 bool ok; 631 632 gcc_assert (pp_format_decoder (pp)); 633 ok = pp_format_decoder (pp) (pp, text, p, 634 precision, wide, plus, hash); 635 gcc_assert (ok); 636 } 637 } 638 639 if (quote) ... The assert occurs when we trying to print this text: ... (gdb) p *text $1 = {format_spec = 0x25a0c20 "wrong number of arguments specified for %qE attribute", args_ptr = 0x7fffffffd2f8, err_no = 0, x_data = 0x7fffffffd340, m_richloc = 0x7fffffffd350} ... Using this pretty-printer: ... (gdb) p *pp $2 = {_vptr.pretty_printer = 0x2570490 <vtable for pretty_printer+16>, buffer = 0x2b85ad0, prefix = 0x0, padding = pp_none, maximum_length = 0, indent_skip = 0, wrapping = {rule = DIAGNOSTICS_SHOW_PREFIX_NEVER, line_cutoff = 0}, format_decoder = 0x73c23a <gfc_format_decoder(pretty_printer*, text_info*, char const*, int, bool, bool, bool)>, emitted_prefix = false, need_newline = false, translate_identifiers = true, show_color = true} ... III. The error message originates here: ... else if (list_length (args) < spec->min_length || (spec->max_length >= 0 && list_length (args) > spec->max_length)) { error ("wrong number of arguments specified for %qE attribute", name); continue; } ... Because args is not null: ... (gdb) call debug_generic_expr (args) nohost ... And the spec doesn't allow any args since min_length and max_length are 0: ... (gdb) p *spec $3 = {name = 0x1f013ac "omp declare target", min_length = 0, max_length = 0, decl_required = true, type_required = false, function_type_required = false, handler = 0x8022e7 <gfc_handle_omp_declare_target_attribute(tree*, tree, tree, int, bool*)>, affects_type_identity = false} ... The error occurs because nohost support is not finished yet for fortran in gomp-4_0-branch, but this PR is not about that. IV. The compiler shouldn't assert during printing the error message. AFAIU, the assert happens because gfc_format_decoder can't handle %qE, it only handles %C and %L. So, it sound like gfc_format_decoder misses handling of %qE, which is also missing in trunk, but not so easy to trigger there.