On Fri, Jun 19, 2026 at 9:09 PM Lewis Hyatt <[email protected]> wrote:
>
> On Fri, Jun 19, 2026 at 12:33:21PM +0200, Richard Biener wrote:
> > 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.
> >
>
> Oh, thanks, I missed that. Below incremental patch adds some documentation
> there, and I tried to clarify the existing documentation of dg-lto-options a
> bit as well. Does that look OK please?
>
> > 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?
>
> The current state of things is like this:
> - A given LTO test consists of a main source file, and additional source
> files to be compiled separately.
>
> - dg-lto-options can be specified in the main file to change which
> options are used for the test.
>
> - The main options, specified either by the LTO_OPTIONS variable or by
> dg-lto-options in the main file, are used for all source files in the
> test.
>
> - If a particular non-main source file needs to add other options, it
> can use the plain dg-options directive to do that.
>
> One potential source of confusion is that in most tests, dg-options
> overwrites the default options, but for LTO, it appends to them. It probably
> predates the dg-additional-options directive, but that might have been a
> clearer name for it, since it behaves like dg-additional-options does here.
>
> The fact that dg-lto-options overwrites the default options can be
> inconvenient, because the default set is rather large, testing 6 different
> variations that are also chosen dynamically according to whether the linker
> plugin is available. So if you just want to, say, add -Wall to the test,
> it's not practical to use dg-lto-options for that. You could add
> { dg-options "-Wall" } to append the option to all the non-main source files
> in the test, but there is no way to do it for the main file. Only
> dg-lto-options is supported there, and using it overwrites the default set
> of options. So I thought dg-lto-additional-options could be useful,
> especially since, for testing diagnostics, it is necessary to add some
> options to all the compilations.
>
> I think the name dg-lto-additional-options is consistent with
> dg-lto-options, in that it is meant for options that apply to every source
> file in the test. lto.exp does not currently allow dg-options or
> dg-additional-options in the main file, but if it did, they would presumably
> apply only to the main file, similar to how dg-options in a non-main file
> applies only to that file.
Thanks for checking and explaining.
The patch is OK with the sourcebuild.texi hunk added.
Thanks,
Richard.
> -Lewis
>
> -----<8-----
>
> diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
> index ef2ca9eab5e..fd5f88447fc 100644
> --- a/gcc/doc/sourcebuild.texi
> +++ b/gcc/doc/sourcebuild.texi
> @@ -4108,8 +4108,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.