From: Arsen Arsenović <[email protected]> This patch permits the dg-additional-sources construct to accept a 'lang' clause. This 'lang' clause tells the testsuite to pass '-x' flags around the additional sources list, which is useful for multi-language tests that can be built with one driver invocation.
Tested-by: navi <[email protected]> gcc/testsuite/ChangeLog: * lib/gcc-defs.exp (additional_sources_omit_on_compile): Drop. (additional_sources): Instead of a list, make it a list of "additional sources" entries, which are triplets holding the language and linkonly status for a given dg-additional-sources invocation in addition to FILELIST. (dg-additional-sources): Process 'lang' clause. Produce entries like described above. Rewrite clause parsing to be less strange. (dg-additional-files-options): Update to match changes above. Pass -x LANG -Wno-complain-wrong-lang ... -x none if LANG is nonempty in list above. * lib/gcc-dg.exp (schedule-cleanups): Fix interpretation of $additional_sources now that it's a list. gcc/ChangeLog: * doc/sourcebuild.texi (Specify additional files for a test): Document dg-additional-sources { lang ... } clause. --- gcc/doc/sourcebuild.texi | 7 +- gcc/testsuite/lib/gcc-defs.exp | 140 ++++++++++++++++++++++++++------- gcc/testsuite/lib/gcc-dg.exp | 4 +- 3 files changed, 119 insertions(+), 32 deletions(-) diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index c464bede5b2..5771bc11c49 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -1347,7 +1347,7 @@ to @var{var_value} before execution of the program created by the test. Specify additional files, other than source files, that must be copied to the system where the compiler runs. -@item @{ dg-additional-sources "@var{filelist}" [@{ \[linkonly\] \[target @var{selector}\] @}] @} +@item @{ dg-additional-sources "@var{filelist}" [@{ \[linkonly\] \[target @var{selector}\] @}] @{ lang @var{lang} @} @} Specify additional source files to appear in the compile line following the main test file. If the directive includes the optional @samp{@{ @var{selector} @}} @@ -1357,6 +1357,11 @@ If @samp{linkonly} is specified, additional sources are used only in @samp{link} and @samp{run} tests; they are reported as unsupported and discarded in other kinds of tests that direct the compiler to output to a single file. + +If the directive includes the optional @samp{@{ lang @var{lang} @}} +clause, then the additional sources are given to the driver surrounded +with @code{-x @var{lang}} and @code{-x none} flag. The driver is also +given the @option{-Wno-complain-wrong-lang} flag. @end table @subsubsection Add checks at the end of a test diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.exp index 191e2b83fe1..0b58f45d587 100644 --- a/gcc/testsuite/lib/gcc-defs.exp +++ b/gcc/testsuite/lib/gcc-defs.exp @@ -305,34 +305,86 @@ proc dg-additional-options { args } { # Record additional sources files that must be compiled along with the # main source file. +# List of additional sources. Each additional sources entry is a list of form: +# +# { FILELIST LANG LINKONLY } +# +# FILELIST is a list of additional files, LANG is the language they should be +# parsed as, if any. If present, FILELIST will be passed to the compiler as: +# +# -x LANG FILELIST -x none +# +# ... and otherwise just as FILELIST, without any '-x'. LINKONLY is true iff +# FILELIST should be omitted on compile, otherwise false. set additional_sources "" -set additional_sources_omit_on_compile "" set additional_sources_used "" proc dg-additional-sources { args } { global additional_sources - global additional_sources_omit_on_compile - if { [llength $args] > 3 } { - error "[lindex $args 0]: too many arguments" + # Must see at least { dg-additional-sources SOURCE } + if { [llength $args] < 2 } { + error "[lindex $args 0]: too few arguments" return } - set target [lindex $args 2] - if { [llength $args] >= 3 && [lindex $target 0] == "linkonly" } { - append additional_sources_omit_on_compile " [lindex $args 1]" - set target [lreplace $target 0 1] + set filearg [lindex $args 1] + set target {} + set lang {} + set linkonly false + + # Iterate given clauses. + foreach arg [lreplace $args 0 1] { + # First, check if the current one is { linkonly ... } or "linkonly". + # This is because we currently permit both '{ linkonly target ... }' + # and mere 'linkonly'. + if { [lindex $arg 0] == "linkonly" } { + set linkonly true + set arg [lreplace $arg 0 0] + + # If we processed the whole clause, skip the rest of the work. + if { [llength $arg] == 0 } { + continue + } + } + + # Then, try for the target clause. + if { [lindex $arg 0] == "target" } { + if { $target != {} } { + error "[lindex $args 0]: duplicate `target' clause" + } + set target $arg + continue + } + + # Then, try the 'lang' clause. This one adds '-x LANG ... -x none' to + # additional_flags instead of just the filename. + if { [lindex $arg 0] == "lang" } { + if { $lang != {} } { + error "[lindex $args 0]: duplicate `lang' clause" + } + if { [llength $arg] != 2 } { + error "[lindex $args 0]: `lang' clause must be of form { lang LANG }" + } + set lang [lindex $arg 1] + continue + } + + error "[lindex $args 0]: could not parse clause $arg" } - if { [llength $args] >= 3 && $target != ""} { + # Construct the additional sources element + set entry [list $filearg $lang $linkonly] + + if { $target != "" } { switch [dg-process-target $target] { - "S" { append additional_sources " [lindex $args 1]" } + "S" { lappend additional_sources $entry } "N" { } "F" { error "[lindex $args 0]: `xfail' not allowed here" } "P" { error "[lindex $args 0]: `xfail' not allowed here" } } } else { - append additional_sources " [lindex $args 1]" + lappend additional_sources $entry } } @@ -418,39 +470,67 @@ proc dg-additional-files-options { options source dest type } { gcc_adjust_linker_flags global additional_sources - global additional_sources_omit_on_compile global additional_sources_used global additional_files set to_download [list] - if { $additional_sources_omit_on_compile != "" \ + + # Find if we have any linkonly sources. + set has_linkonly false + foreach s $additional_sources { + if [lindex $s 2] { + set has_linkonly true + break + } + } + + if { $has_linkonly && $additional_sources != "" \ && $type != "executable" && $dest != "" } then { - set linkonly "" + # Extract only linkonly sources, emit unsupported for rest. + set linkonly {} foreach s $additional_sources { - foreach s2 $additional_sources_omit_on_compile { - if { $s == $s2 } { - unsupported "$s: additional-source will not be used to build $dest" - set s "" - break - } + if [lindex $s 2] { + lappend linkonly $s + continue } - if { $s != "" } { - append linkonly " $s" + + # This source set is not linkonly, emit 'unsupported'. + foreach s2 [lindex $s 0] { + unsupported "$s2: additional-source will not be used to build $dest" } } set additional_sources "$linkonly" } if { $additional_sources == "" } then { } else { - if [is_remote host] { - lappend options "additional_flags=$additional_sources" + set additional_sources_used {} + foreach s $additional_sources { + set files [lindex $s 0] + set lang [lindex $s 1] + + # Add -x LANG + if { $lang != "" } { + lappend options "additional_flags=-x $lang" + lappend options "additional_flags=-Wno-complain-wrong-lang" + } + + # Add the actual sources + if [is_remote host] { + lappend options "additional_flags=$files" + } + regsub -all {^ *| *} $files " [file dirname $source]/" files + if ![is_remote host] { + lappend options "additional_flags=$files" + } + append to_download $files + append additional_sources_used $files + + # Undo -x LANG + if { $lang != "" } { + lappend options "additional_flags=-x none" + } } - regsub -all {^ *| *} $additional_sources " [file dirname $source]/" additional_sources - if ![is_remote host] { - lappend options "additional_flags=$additional_sources" - } - set to_download [concat $to_download $additional_sources] - set additional_sources_used "$additional_sources" + set additional_sources "" # This option restores naming of aux and dump output files # after input files when multiple input files are named, diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 9f183259257..ac1412d8195 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -139,7 +139,9 @@ proc schedule-cleanups { opts } { lappend testcases [lindex [testname-for-summary] 0] verbose "Cleanup testcases: $testcases" 4 if { [info exists additional_sources] && $additional_sources != "" } { - lappend testcases $additional_sources + foreach s $additional_sources { + append testcases " [lindex $s 0]" + } verbose "Cleanup testcases, additional: $additional_sources" 4 } verbose "Cleanup all options: $opts" 4 -- 2.55.0
