diff options
author | David Malcolm <dmalcolm@redhat.com> | 2020-01-10 20:14:31 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2020-01-10 20:14:31 +0000 |
commit | 83f604e70683b5356bd1bc330a98a34981aad8f4 (patch) | |
tree | 9343ba6eddf8566aaf230ae6c527f3e138b3ca07 | |
parent | 60257913f864a5b9f70fbd45ff267cb703075497 (diff) | |
download | gcc-83f604e70683b5356bd1bc330a98a34981aad8f4.zip gcc-83f604e70683b5356bd1bc330a98a34981aad8f4.tar.gz gcc-83f604e70683b5356bd1bc330a98a34981aad8f4.tar.bz2 |
testsuite: add dg-enable-nn-line-numbers
This patch adds support for obscuring the line numbers printed in the
left-hand margin when printing the source code, converting them to "NN",
e.g from:
7111 | if (!(flags & 0x0001)) {
| ^
| |
| (1) following 'true' branch...
7112 |
to:
NN | if (!(flags & 0x0001)) {
| ^
| |
| (1) following 'true' branch...
NN |
This is useful in followup patches e.g. when testing how interprocedural
paths are printed using multiline.exp, to avoid depending on precise line
numbers.
gcc/testsuite/ChangeLog:
* 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.
From-SVN: r280134
-rw-r--r-- | gcc/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/lib/gcc-dg.exp | 2 | ||||
-rw-r--r-- | gcc/testsuite/lib/multiline.exp | 88 | ||||
-rw-r--r-- | gcc/testsuite/lib/prune.exp | 4 |
4 files changed, 103 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1edada1..a7a10c9 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 e6875de..cccd3ce 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 e965d89..627ad68 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 6e2e84b..6040220 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] |