]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Add dg-lto-additional-options directive
authorLewis Hyatt <lhyatt@gmail.com>
Sat, 11 Jul 2026 18:21:12 +0000 (14:21 -0400)
committerLewis Hyatt <lhyatt@gcc.gnu.org>
Fri, 17 Jul 2026 12:33:43 +0000 (08:33 -0400)
In the LTO testsuite, tests run by default with a variety of options. If
the dg-lto-options directive is used, the default list is replaced with just
the requested options, so there is no convenient way, for instance, to add a
given option like -Wall to all of the options being tested.

This will be handy for testing `#pragma GCC diagnostic' in the next patch in
this series, so this patch adds a new directive dg-lto-additional-options
for that purpose. This keeps the list of options to test unchanged, and
just adds the requested options to all of them.

gcc/ChangeLog:

* doc/sourcebuild.texi: Document dg-lto-additional-options
directive.

gcc/testsuite/ChangeLog:

* gcc.dg/lto/README: Document dg-lto-additional-options directive.
* lib/lto.exp (lto-get-options-main): Implement
dg-lto-additional-options directive.
(lto-execute-1): Likewise.

gcc/doc/sourcebuild.texi
gcc/testsuite/gcc.dg/lto/README
gcc/testsuite/lib/lto.exp

index a377739edb66745b523efdc31f3488811b05dd47..6c0a3a4c74f93e07216f9807fd9da6de76e3a490 100644 (file)
@@ -4134,8 +4134,17 @@ Unlike @code{dg-do}, @code{dg-lto-do} does not support an optional
 
 @item @{ dg-lto-options @{ @{ @var{options} @} [@{ @var{options} @}] @} [@{ target @var{selector} @}]@}
 This directive provides a list of one or more sets of compiler options
-to override @var{LTO_OPTIONS}.  Each test will be compiled and run with
-each of these sets of options.
+to override @var{LTO_OPTIONS}.  Every test file will be compiled and
+run once for each of these sets of options.  Individual source files
+within a test may also use @code{dg-options} to specify additional
+options to include.
+
+@item @{ dg-lto-additional-options @{ @{ @var{options} @} [@{ @var{options} @}] @} [@{ target @var{selector} @}]@}
+This is similar to @code{dg-lto-options}, but rather than overriding
+@var{LTO_OPTIONS}, it appends the given options to each of the sets
+specified in @var{LTO_OPTIONS}.  This can be used to add a given list
+of options to every compilation of all source files in the test,
+without otherwise changing which combinations of options are tested.
 
 @item @{ dg-extra-ld-options @var{options} [@{ target @var{selector} @}]@}
 This directive adds @var{options} to the linker options used.
index 6777c15766a3530cf2ad8cbf33e4e53b5c037fb9..1ee8b00dee8fd0d2cddc4600ecc60f560da2af1e 100644 (file)
@@ -8,6 +8,8 @@ The LTO harness recognizes the following special DejaGnu directives:
  *  dg-lto-options - the equivalent of dg-options with additional syntax
       to support different sets of options for different files compiled
       as part of the same test case,
+ *  dg-lto-additional-options - the equivalent of dg-additional-options;
+      adds to the default options instead of overwriting them
  *  dg-lto-warning - the equivalent of dg-warning for diagnostics expected
       to be emitted at LTO link time,
  *  dg-lto-message - the equivakent of dg-message for informational notes
index 036d7e6cc86ca9d3b7c9c67586670bddecc3c936..2cff54b699d060dd58116ea43521f17fa5bd9df2 100644 (file)
@@ -507,6 +507,7 @@ proc lto-get-options-main { src } {
 
     # dg-options sets a variable called dg-extra-tool-flags.
     set dg-extra-tool-flags ""
+    set lto-additional-tool-flags ""
 
     # dg-options sets a variable called tool_flags.
     set tool_flags ""
@@ -541,6 +542,18 @@ proc lto-get-options-main { src } {
                unresolved "$src: $errmsg for \"$op\""
                return
            }
+       } elseif { [string match "dg-lto-additional-options" $cmd] } {
+           set op [lreplace $op 0 0 "dg-additional-options"]
+           set saved-dg-extra-tool-flags ${dg-extra-tool-flags}
+           set dg-extra-tool-flags ${lto-additional-tool-flags}
+           set status [catch "$op" errmsg]
+           if { $status != 0 } {
+               perror "src: $errmsg for \"$op\"\n"
+               unresolved "$src: $errmsg for \"$op\""
+               return
+           }
+           set lto-additional-tool-flags ${dg-extra-tool-flags}
+           set dg-extra-tool-flags ${saved-dg-extra-tool-flags}
        } elseif { ![string compare "dg-xfail-if" $cmd] \
                   || ![string compare "dg-options" $cmd] } {
            warning "lto.exp does not support $cmd in primary source file"
@@ -610,7 +623,8 @@ proc lto-get-options-main { src } {
     # Return flags to use for compiling the primary source file and for
     # linking.
     verbose "dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
-    return ${dg-extra-tool-flags}
+    verbose "lto-additional-tool-flags for main is ${lto-additional-tool-flags}"
+    return [list ${dg-extra-tool-flags} ${lto-additional-tool-flags}]
 }
 
 
@@ -692,7 +706,7 @@ proc lto-execute-1 { src1 sid } {
     set compile_type "run"
     set dg-do-what [list ${dg-do-what-default} "" P]
     array set dg-messages-by-file [list]
-    set extra_flags(0) [lto-get-options-main $src1]
+    lassign [lto-get-options-main $src1] extra_flags(0) additional-flags
     set compile_xfail(0) "" 
 
     # If the main file defines dg-options, those flags are used to
@@ -821,7 +835,7 @@ proc lto-execute-1 { src1 sid } {
        # Compile pieces with the compiler under test.
        set i 0
        foreach src $src_list obj $obj_list {
-           lto-obj $src $obj $option $extra_flags($i) $option \
+           lto-obj $src $obj $option "$extra_flags($i) ${additional-flags}" $option \
                    $compile_xfail($i)
            incr i
        }
@@ -857,7 +871,7 @@ proc lto-execute-1 { src1 sid } {
 
            lto-link-and-maybe-run \
                    "[lindex $obj_list 0]-[lindex $obj_list end]" \
-                   $obj_list $execname $filtered ${dg-extra-ld-options} \
+               $obj_list $execname $filtered "${additional-flags} ${dg-extra-ld-options}" \
                    $filtered
 
            if (![string compare "ar-link" $compile_type]) {