[gcc(refs/users/aoliva/heads/testme)] [testsuite] add linkonly to dg-additional-sources [PR115295]

Alexandre Oliva aoliva@gcc.gnu.org
Wed Jun 12 00:47:43 GMT 2024


https://gcc.gnu.org/g:d0e0c26b2a3211ca0e1d945b4745c580d8f65f33

commit d0e0c26b2a3211ca0e1d945b4745c580d8f65f33
Author: Alexandre Oliva <oliva@gnu.org>
Date:   Tue Jun 11 21:44:55 2024 -0300

    [testsuite] add linkonly to dg-additional-sources [PR115295]

Diff:
---
 gcc/doc/sourcebuild.texi             |  9 +++++----
 gcc/testsuite/g++.dg/vect/pr95401.cc |  2 +-
 gcc/testsuite/lib/gcc-defs.exp       | 36 ++++++++++++++++++++++++++++--------
 3 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index e997dbec3334..08c178db674c 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1320,15 +1320,16 @@ 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}" [@{ target @var{selector} @}] @}
+@item @{ dg-additional-sources "@var{filelist}" [@{ \[linkonly\] \[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.
+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.
 @end table
 
 @subsubsection Add checks at the end of a test
diff --git a/gcc/testsuite/g++.dg/vect/pr95401.cc b/gcc/testsuite/g++.dg/vect/pr95401.cc
index 6a56dab09572..8b1be4f24252 100644
--- a/gcc/testsuite/g++.dg/vect/pr95401.cc
+++ b/gcc/testsuite/g++.dg/vect/pr95401.cc
@@ -1,5 +1,5 @@
 // { dg-additional-options "-mavx2 -O3" { target avx2_runtime } }
-// { dg-additional-sources pr95401a.cc }
+// { dg-additional-sources pr95401a.cc linkonly }
 
 extern int var_9;
 extern unsigned var_14;
diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.exp
index cdca4c254d6e..324a90981e43 100644
--- a/gcc/testsuite/lib/gcc-defs.exp
+++ b/gcc/testsuite/lib/gcc-defs.exp
@@ -303,6 +303,7 @@ proc dg-additional-options { args } {
 # main source file.
 
 set additional_sources ""
+set additional_sources_omit_on_compile ""
 set additional_sources_used ""
 
 proc dg-additional-sources { args } {
@@ -313,8 +314,14 @@ proc dg-additional-sources { args } {
 	return
     }
 
-    if { [llength $args] >= 3 } {
-	switch [dg-process-target [lindex $args 2]] {
+    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]
+    }
+
+    if { [llength $args] >= 3 && $target != ""} {
+	switch [dg-process-target $target] {
 	    "S" { append additional_sources " [lindex $args 1]" }
 	    "N" { }
 	    "F" { error "[lindex $args 0]: `xfail' not allowed here" }
@@ -407,17 +414,30 @@ 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 == "" } 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 { $type != "executable" && $dest != "" && \
+		 $additional_sources_omit_on_compile != "" } then {
+	    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 { $s != "" } {
+		    append linkonly " $s"
+		}
+	    }
+	    set additional_sources "$linkonly"
+	}
 	if [is_remote host] {
 	    lappend options "additional_flags=$additional_sources"
 	}


More information about the Gcc-cvs mailing list