diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1edada1ca15a701e28a6431e4096543a6bf7ec87..a7a10c906f60a9bb66fd47319deb5d15d3c3bd05 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2020-01-10 David Malcolm <dmalcolm@redhat.com> + + * lib/gcc-dg.exp (cleanup-after-saved-dg-test): Reset global + nn_line_numbers_enabled. + * lib/multiline.exp (nn_line_numbers_enabled): New global. + (dg-enable-nn-line-numbers): New proc. + (maybe-handle-nn-line-numbers): New proc. + * lib/prune.exp (prune_gcc_output): Call maybe-handle-nn-line-numbers. + 2020-01-10 Vladimir Makarov <vmakarov@redhat.com> PR inline-asm/93207 diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index e6875de23831691f73191287b91fc66bda694146..cccd3ce4742cde28bdfd14e038d222b64be441f8 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -940,6 +940,7 @@ if { [info procs saved-dg-test] == [list] } { global set_compiler_env_var global saved_compiler_env_var global keep_saved_temps_suffixes + global nn_line_numbers_enabled global multiline_expected_outputs global freeform_regexps global save_linenr_varnames @@ -967,6 +968,7 @@ if { [info procs saved-dg-test] == [list] } { if [info exists testname_with_flags] { unset testname_with_flags } + set nn_line_numbers_enabled 0 set multiline_expected_outputs [] set freeform_regexps [] diff --git a/gcc/testsuite/lib/multiline.exp b/gcc/testsuite/lib/multiline.exp index e965d8946f77a805cb59826f8234e2e51d2816b4..627ad68817f3cf964aaee2deccbdfd4a0663f909 100644 --- a/gcc/testsuite/lib/multiline.exp +++ b/gcc/testsuite/lib/multiline.exp @@ -60,6 +60,9 @@ set _multiline_last_beginning_line -1 # This is cleared at the end of each test by gcc-dg.exp's wrapper for dg-test. set multiline_expected_outputs [] +# Was dg-enable-nn-line-numbers called? +set nn_line_numbers_enabled 0 + ############################################################################ # Exported functions. ############################################################################ @@ -177,6 +180,91 @@ proc handle-multiline-outputs { text } { return $text } +# DejaGnu directive to enable post-processing the line numbers printed in +# the left-hand margin when printing the source code, converting them to +# "NN", e.g from: +# +# 100 | if (flag) +# | ^ +# | | +# | (1) following 'true' branch... +# 101 | { +# 102 | foo (); +# | ^ +# | | +# | (2) ...to here +# +# to: +# +# NN | if (flag) +# | ^ +# | | +# | (1) following 'true' branch... +# NN | { +# NN | foo (); +# | ^ +# | | +# | (2) ...to here +# +# This is useful e.g. when testing how interprocedural paths are printed +# via dg-begin/end-multiline-output, to avoid depending on precise line +# numbers. + +proc dg-enable-nn-line-numbers { args } { + verbose "dg-nn-line-numbers: args: $args" 2 + global nn_line_numbers_enabled + set nn_line_numbers_enabled 1 +} + +# Hook to be called by prune.exp's prune_gcc_output to convert such line +# numbers to "NN" form. +# +# Match substrings of the form: +# " 25 |" +# and convert them to: +# " NN |" +# +# It returns a copy of its input, with the above changes. + +proc maybe-handle-nn-line-numbers { text } { + global testname_with_flags + + verbose "maybe-handle-nn-line-numbers" 3 + + global nn_line_numbers_enabled + if { [expr {!$nn_line_numbers_enabled}] } { + verbose "nn_line_numbers_enabled false; bailing out" 3 + return $text + } + + verbose "maybe-handle-nn-line-numbers: text before: ${text}" 4 + + # dg.exp's dg-test trims leading whitespace from the output + # in this line: + # set comp_output [string trimleft $comp_output] + # so we can't rely on the exact leading whitespace for the + # first line in the output. + # Match initial input lines that start like: + # "25 |" + # and convert them to: + # " NN |" + set rexp2 {(^[0-9]+ \|)} + set count_a [regsub -all $rexp2 $text " NN |" text] + verbose "maybe-handle-nn-line-numbers: count_a: $count_a" 4 + + # Match lines that start like: + # " 25 |" + # and convert them to: + # " NN |" + set rexp {([ ]+[0-9]+ \|)} + set count_b [regsub -all $rexp $text " NN |" text] + verbose "maybe-handle-nn-line-numbers: count_b: $count_b" 4 + + verbose "maybe-handle-nn-line-numbers: text after: ${text}" 4 + + return $text +} + ############################################################################ # Internal functions ############################################################################ diff --git a/gcc/testsuite/lib/prune.exp b/gcc/testsuite/lib/prune.exp index 6e2e84ba171cb9bfba2c08033a15330446791455..60402208c375c572766a8adce0def3cf4b400fe5 100644 --- a/gcc/testsuite/lib/prune.exp +++ b/gcc/testsuite/lib/prune.exp @@ -74,6 +74,10 @@ proc prune_gcc_output { text } { # Ignore harmless warnings from Xcode 4.0. regsub -all "(^|\n)\[^\n\]*ld: warning: could not create compact unwind for\[^\n\]*" $text "" text + # If dg-enable-nn-line-numbers was provided, then obscure source-margin + # line numbers by converting them to "NN" form. + set text [maybe-handle-nn-line-numbers $text] + # Call into multiline.exp to handle any multiline output directives. set text [handle-multiline-outputs $text]