]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[testsuite] conditionalize dg-additional-sources on target and type
authorAlexandre Oliva <oliva@adacore.com>
Thu, 30 May 2024 05:06:48 +0000 (02:06 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Thu, 30 May 2024 05:06:48 +0000 (02:06 -0300)
g++.dg/vect/pr95401.cc has dg-additional-sources, and that fails when
check_vect_support_and_set_flags finds vector support lacking for
execution tests: tests decay to compile tests, and additional sources
are rejected by the compiler when compiling to a named output file.

At first I considered using some effective target to conditionalize
the additional sources.  There was no support for target-specific
additional sources, so I added that.

But then, I found that adding an effective target to check whether the
test involves linking would just make for busy work in this case, and
so I went ahead and adjusted the handling of additional sources to
refrain from adding them on compile tests, reporting them as
unsupported.

That solves the problem without using the newly-added machinery for
per-target additional sources, but I figured since I'd implemented it
I might as well contribute it, since there might be other uses for it.

for  gcc/ChangeLog

* doc/sourcebuild.texi (dg-additional-sources): Document
newly-added support for target selectors, and implicit discard
on non-linking tests that name the compiler output explicitly.

for  gcc/testsuite/ChangeLog

* lib/gcc-defs.exp (dg-additional-sources): Support target
selectors.  Make it cumulative.
(dg-additional-files-options): Take dest and type.  Note
unsupported additional sources when not linking and naming the
compiler output.  Adjust source dirname prepending to cope
with leading blanks.
* lib/g++.exp (g++_target_compile): Pass dest and type on to
dg-additional-files-options.
* lib/gcc.exp (gcc_target_compile): Likewise.
* lib/gdc.exp (gdb_target_compile): Likewise.
* lib/gfortran.exp (gfortran_target_compile): Likewise.
* lib/go.exp (go_target_compile): Likewise.
* lib/obj-c++.exp (obj-c++_target_compile): Likewise.
* lib/objc.exp (objc_target_compile): Likewise.
* lib/rust.exp (rust_target_compile): Likewise.
* lib/profopt.exp (profopt-execute): Likewise-ish.

gcc/doc/sourcebuild.texi
gcc/testsuite/lib/g++.exp
gcc/testsuite/lib/gcc-defs.exp
gcc/testsuite/lib/gcc.exp
gcc/testsuite/lib/gdc.exp
gcc/testsuite/lib/gfortran.exp
gcc/testsuite/lib/go.exp
gcc/testsuite/lib/obj-c++.exp
gcc/testsuite/lib/objc.exp
gcc/testsuite/lib/profopt.exp
gcc/testsuite/lib/rust.exp

index 8e4e59ac44c74277b63ee4d5016e15af01792e86..e997dbec3334bf5e012a48d5d9361bcee9eea552 100644 (file)
@@ -1320,9 +1320,15 @@ 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}" @}
+@item @{ dg-additional-sources "@var{filelist}" [@{ target @var{selector} @}] @}
 Specify additional source files to appear in the compile line
 following the main test file.
+If the directive includes the optional @samp{@{ @var{selector} @}}
+then the additional sources are only added if the target system
+matches the @var{selector}.
+Additional sources are generally 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.
 @end table
 
 @subsubsection Add checks at the end of a test
index 0e47769c25b8b47b641603aac643874cd882d685..a6b34d5d3a2b7bbc4b8de846a25d155159f0f9d1 100644 (file)
@@ -326,7 +326,7 @@ proc g++_target_compile { source dest type options } {
         append board_info($tboard,multilib_flags) " $flags_to_postpone"
     }
 
-    set options [dg-additional-files-options $options $source]
+    set options [dg-additional-files-options $options $source $dest $type]
 
     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
        lappend options "libs=${gluefile}"
index 70215ed49052e53a4e378649cd4b7b2302d42c8b..cdca4c254d6ec33c1063a347ffbc79cb27d59765 100644 (file)
@@ -307,7 +307,22 @@ set additional_sources_used ""
 
 proc dg-additional-sources { args } {
     global additional_sources
-    set additional_sources [lindex $args 1]
+
+    if { [llength $args] > 3 } {
+       error "[lindex $args 0]: too many arguments"
+       return
+    }
+
+    if { [llength $args] >= 3 } {
+       switch [dg-process-target [lindex $args 2]] {
+           "S" { append additional_sources " [lindex $args 1]" }
+           "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]"
+    }
 }
 
 # Record additional files -- other than source files -- that must be
@@ -383,20 +398,30 @@ proc gcc_adjust_linker_flags {} {
 
 # Return an updated version of OPTIONS that mentions any additional
 # source files registered with dg-additional-sources.  SOURCE is the
-# name of the test case.
+# name of the test case.  If DEST is given and TYPE does not require
+# linking, additional sources are noted as unsupported rather than
+# added, because the compiler rejects a single output for multiple
+# sources.
 
-proc dg-additional-files-options { options source } {
+proc dg-additional-files-options { options source dest type } {
     gcc_adjust_linker_flags
 
     global additional_sources
     global additional_sources_used
     global additional_files
     set to_download [list]
-    if { $additional_sources != "" } then {
+    if { $additional_sources == "" } then {
+    } elseif { $type != "executable" && $dest != "" } then {
+       foreach s $additional_sources {
+           unsupported "$s: additional-source will not be used to build $dest"
+       }
+       set additional_sources_used ""
+       set additional_sources ""
+    } else {
        if [is_remote host] {
            lappend options "additional_flags=$additional_sources"
        }
-       regsub -all "^| " $additional_sources " [file dirname $source]/" additional_sources
+       regsub -all {^ *|  *} $additional_sources " [file dirname $source]/" additional_sources
        if ![is_remote host] {
            lappend options "additional_flags=$additional_sources"
        }
index 63e61c3c9fd9cccdf4d02329b70d69eeb00606c9..3bcd98eb9a7ba4022709c503ce67a2a1aededd1a 100644 (file)
@@ -159,7 +159,7 @@ proc gcc_target_compile { source dest type options } {
 
     lappend options "timeout=[timeout_value]"
     lappend options "compiler=$GCC_UNDER_TEST"
-    set options [dg-additional-files-options $options $source]
+    set options [dg-additional-files-options $options $source $dest $type]
 
     if {[target_info needs_status_wrapper] != "" && \
            [target_info needs_status_wrapper] != "0" && \
index 3c284229609a9503c2c9752faf16e6e638fa4c57..fd9cea67d0a9fe0713c1cd7745367298cdde89d2 100644 (file)
@@ -327,6 +327,6 @@ proc gdc_target_compile { source dest type options } {
     lappend options "compiler=$GDC_UNDER_TEST"
 
     set options [concat "$always_dflags" $options]
-    set options [dg-additional-files-options $options $source]
+    set options [dg-additional-files-options $options $source $dest $type]
     return [target_compile $source $dest $type $options]
 }
index 1ccb81ccec5a8519087a11f8c6b7068912e6b880..3a9e81b69a3d1dc09a064ca6256645cb4ec9a200 100644 (file)
@@ -295,7 +295,7 @@ proc gfortran_target_compile { source dest type options } {
     lappend options "timeout=[timeout_value]"
 
     set options [concat "$ALWAYS_GFORTRANFLAGS" $options]
-    set options [dg-additional-files-options $options $source]
+    set options [dg-additional-files-options $options $source $dest $type]
     set return_val [target_compile $source $dest $type $options]
 
     if {[board_info $tboard exists multilib_flags]} {
index 714afb173d8e04f8fd482ebb64ab155e7fb8b640..509d528d861fc57b1871701c56e73ae2426c5ead 100644 (file)
@@ -221,6 +221,6 @@ proc go_target_compile { source dest type options } {
     lappend options "compiler=$GOC_UNDER_TEST"
 
     set options [concat "$ALWAYS_GOCFLAGS" $options]
-    set options [dg-additional-files-options $options $source]
+    set options [dg-additional-files-options $options $source $dest $type]
     return [target_compile $source $dest $type $options]
 }
index 854dc264f9d0ee27667654f499803ccba7032bce..1c5ef57ce837085ca0d02299cef1f7e4f53f541d 100644 (file)
@@ -388,7 +388,7 @@ proc obj-c++_target_compile { source dest type options } {
 
     set options [concat "$ALWAYS_OBJCXXFLAGS" $options];
 
-    set options [dg-additional-files-options $options $source]
+    set options [dg-additional-files-options $options $source $dest $type]
 
     set result [target_compile $source $dest $type $options]
 
index b02fd77289c45e15d3fc7b70dfe2df0d5f168c75..3d2cc05c15d117ae732c300b6c4b9c8731810c91 100644 (file)
@@ -248,7 +248,7 @@ proc objc_target_compile { source dest type options } {
 
     set_ld_library_path_env_vars
 
-    set options [dg-additional-files-options $options $source]
+    set options [dg-additional-files-options $options $source $dest $type]
 
     return [target_compile $source $dest $type $options]
 }
index 6524d95f69d5a831eee694442994fb2d1f416179..6d7159b7a8691485144bb7df4cdb10f6b2619475 100644 (file)
@@ -388,7 +388,7 @@ proc profopt-execute { src } {
        # schedule removal of dump files et al
        # Do this before the call below destroys additional_sources..
        append use_final_code [schedule-cleanups "$option $extra_flags"]
-        set extra_options [dg-additional-files-options "" "$src"]
+        set extra_options [dg-additional-files-options "" "$src" $execname1 "executable"]
 
        # Remove old profiling data files.  Make sure additional_sources_used is
        # valid, by running it after dg-additional-files-options.
index 5ded0edf914646de9cf85a89655a4c8c5c8164b2..4c296228fa2afe40a336ae66c7cbfc9ca01f5935 100644 (file)
@@ -182,7 +182,7 @@ proc rust_target_compile { source dest type options } {
     lappend options "compiler=$RUST_UNDER_TEST"
 
     set options [concat "$ALWAYS_RUSTFLAGS" $options]
-    set options [dg-additional-files-options $options $source]
+    set options [dg-additional-files-options $options $source $dest $type]
 
     return [target_compile $source $dest $type $options]
 }