On Thu, Jan 1, 2026 at 6:06 PM Lewis Hyatt <[email protected]> wrote:
>
> 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.
Looks good to me, but the documentation should be in sourcebuild.texi
as well.
What's the actual difference between dg-lto-additional-options and
a dg-additional-options which we could just support for lto.exp? Is
there any?
> 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/testsuite/gcc.dg/lto/README | 2 ++
> gcc/testsuite/lib/lto.exp | 22 ++++++++++++++++++----
> 2 files changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.dg/lto/README b/gcc/testsuite/gcc.dg/lto/README
> index 6777c15766a..1ee8b00dee8 100644
> --- a/gcc/testsuite/gcc.dg/lto/README
> +++ b/gcc/testsuite/gcc.dg/lto/README
> @@ -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
> diff --git a/gcc/testsuite/lib/lto.exp b/gcc/testsuite/lib/lto.exp
> index a35a3fc3a74..89c86a0f779 100644
> --- a/gcc/testsuite/lib/lto.exp
> +++ b/gcc/testsuite/lib/lto.exp
> @@ -492,6 +492,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 ""
> @@ -526,6 +527,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"
> @@ -595,7 +608,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}]
> }
>
>
> @@ -677,7 +691,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
> @@ -796,7 +810,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
> }
> @@ -832,7 +846,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]) {