On Tue, Mar 11, 2025 at 01:24:12PM +0100, Richard Biener wrote: > The following adds a simple cobol.dg test harness, based on gfortran.dg. > It's invoked by make check-cobol, has a single test that should pass. > > Running /home/rguenther/src/gcc/gcc/testsuite/cobol.dg/dg.exp ... > FAIL: cobol.dg/pass.cob -O3 -fomit-frame-pointer -funroll-loops > -fpeel-loops -ftracer -finline-functions (test for excess errors) > > === cobol Summary === > > # of expected passes 10 > # of unexpected failures 1 > # of unresolved testcases 1 > > OK? > > Thanks, > Richard. > > gcc/cobol/ > * Make-lang.in (lang_checks): Add check-cobol. > > gcc/testsuite/ > * lib/cobol-dg.exp: New, based on gfortran-dg.exp. > * lib/cobol.exp: New, based on gfortran.exp. > * cobol.dg/dg.exp: New. > * cobol.dg/pass.cob: New test.
> + # gcc's default is to print the caret and source code, but > + # most test cases implicitly use the flag -fno-diagnostics-show-caret > + # to disable caret (and source code) printing. > + # > + # However, a few test cases override this back to the default by > + # explicily supplying "-fdiagnostics-show-caret", so that we can have > + # test coverage for caret/source code printing. > + # > + # cobol error messages with caret-printing look like this: > + # [name]:[locus]: > + # > + # some code > + # 1 > + # Error: Some error at (1) > + # or > + # [name]:[locus]: > + # > + # some code > + # 1 > + # [name]:[locus2]: > + # > + # some other code > + # 2 > + # Error: Some error at (1) and (2) > + # or > + # [name]:[locus]: > + # > + # some code and some more code > + # 1 2 > + # Error: Some error at (1) and (2) > + # > + # If this is such a test case, skip the rest of this function, so > + # that the test case can explicitly verify the output that it expects. > + if {[string first "-fdiagnostics-show-caret" $extra_tool_flags] >= 0} { > + return [list $comp_output $output_file] > + } > + > + # Otherwise, caret-printing is disabled. > + # cobol errors with caret-printing disabled look like this: > + # [name]:[locus]: Error: Some error > + # or > + # [name]:[locus]: Error: (1) > + # [name]:[locus2]: Error: Some error at (1) and (2) > + # > + # Where [locus] is either [line] or [line].[column] or > + # [line].[column]-[column] . > + # > + # We collapse these to look like: > + # [name]:[line]:[column]: Error: Some error at (1) and (2) > + # or > + # [name]:[line]:[column]: Error: Some error at (1) and (2) > + # [name]:[line2]:[column]: Error: Some error at (1) and (2) > + # > + # Note that these regexps only make sense in the combinations used below. > + # Note also that is imperative that we first deal with the form with > + # two loci. > + set locus_regexp > "(\[^\n\]+:\[0-9\]+)\[\.:\](\[0-9\]+)(-\[0-9\]+)?:\n\n\[^\n\]+\n\[^\n\]+\n" > + set diag_regexp "(\[^\n\]+)\n" > + > + # We proceed in steps: > + > + # 1. We add first a column number if none exists. > + # (Some cobol diagnostics have the locus after Warning|Error) > + set colnum_regexp "(^|\n)(Warning: |Error: )?(\[^:\n\]+:\[0-9\]+):(\[ > \n\])" > + regsub -all $colnum_regexp $comp_output "\\1\\3:0:\\4\\2" comp_output > + verbose "comput_output0:\n$comp_output" > + > + # 2. We deal with the form with two different locus lines, > + set two_loci "(^|\n)$locus_regexp$locus_regexp$diag_regexp" > + regsub -all $two_loci $comp_output "\\1\\2:\\3: \\8\n\\5\:\\6: \\8\n" > comp_output > + verbose "comput_output1:\n$comp_output" > + > + set locus_prefix "(\[^:\n\]+:\[0-9\]+:\[0-9\]+: )(Warning: |Error: )" > + set two_loci2 "(^|\n)$locus_prefix\\(1\\)\n$locus_prefix$diag_regexp" > + regsub -all $two_loci2 $comp_output "\\1\\2\\3\\6\n\\4\\5\\6\n" > comp_output > + verbose "comput_output2:\n$comp_output" > + > + # 3. then with the form with only one locus line. > + set single_locus "(^|\n)$locus_regexp$diag_regexp" > + regsub -all $single_locus $comp_output "\\1\\2:\\3: \\5\n" comp_output > + verbose "comput_output3:\n$comp_output" > + > + # 4. Add a line number if none exists > + regsub -all "(^|\n)(Warning: |Error: )" $comp_output "\\1:0:0: \\2" > comp_output > + verbose "comput_output4:\n$comp_output" > + return [list $comp_output $output_file] Looking at pretty much all of the above, it seems very Fortran specific with its weird diagnostic output (capital Warning:/Error:, the (1) and (2) in the diagnostics with later printing of those lines and the like. Unless cobol1 does it the same, this should be replaced with what is done for other FEs (likely almost nothing). Otherwise LGTM. Jakub