Consider '--with-build-sysroot=[...]' for target libraries' build-tree testing (instead of build-time 'CC' etc.) [PR109951]

Message ID 875y868a4b.fsf@euler.schwinge.homeip.net
State Superseded
Headers
Series Consider '--with-build-sysroot=[...]' for target libraries' build-tree testing (instead of build-time 'CC' etc.) [PR109951] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 pending Test started
linaro-tcwg-bot/tcwg_gcc_check--master-arm pending Test started

Commit Message

Thomas Schwinge June 2, 2023, 9:52 a.m. UTC
  Hi!

For context:

In early 2020, Maciej pushed a set of changes that made target libraries
capture their build-time 'CC' for test-time usage as 'GCC_UNDER_TEST'
(via the respective 'site.exp'), for build-tree testing (but not
installed testing).  This was motivated by the need for '--sysroot=[...]'
as set per '--with-build-sysroot=[...]'.  For example, for libgomp that's
Subversion r279708 (Git commit c8e759b4215ba4b376c9d468aeffe163b3d520f0)
"libgomp/test: Fix compilation for build sysroot", followed by
Git commit 749bd22ddc50b5112e5ed506ffef7249bf8e6fb3
"libgomp/test: Remove a build sysroot fix regression".  (Similarly other
commits for a number of (but not all?) other target libraries).

In recent Git commit 11f4d483600b5788a3d1cf1527e838e4a7ed1455
"libgomp testsuite: As appropriate, use the 'gcc', 'g++', 'gfortran' driver [PR91884]"
I've then extended this approach for 'CXX': 'GXX_UNDER_TEST',
'FC': 'GFORTRAN_UNDER_TEST'.

Per <https://gcc.gnu.org/PR109951>
"libgomp, testsuite: non-native multilib c++ tests fail on Darwin"
we have however found that there is a conceptual problem in the original
approach: the build-time 'CC' etc. potentially are different per multilib
build of the target library (say, multilib-specific '-L[...]'  flags),
whereas the test-time usage will always use the 'GCC_UNDER_TEST', thus
build-time 'CC' of the default multilib.  (This is fundamental in how the
GCC/DejaGnu testsuite is set up; we're not going to change this without
considerable effort.)  Often this is not a problem (if, effectively,
non-applicable flags etc. are dropped silently, for example), but as Iain
has demonstrated, this is an actual problem in certain configurations
(if, effectively, non-applicable flags etc. cause diagnostics, for
example).

Now, back then, Chung-Lin actually had a different proposal:

On 2020-01-14T21:31:13+0800, Chung-Lin Tang <chunglin_tang@mentor.com> wrote:
> I understand your situation with --with-build-sysroot/--without-sysroot, [...]
>
> Can you test if the attached patch works for you? The patch exports the build sysroot
> setting from the toplevel to target library subdirs, and adds the --sysroot= option
> when doing build-tree testing [...]

Belatedly: thanks, I like that approach better indeed.

This is, by the way, in line with what GCC compiler testing is doing;
'gcc/Makefile.in':

    # Set if the compiler was configured with --with-build-sysroot.
    SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@

    # TEST_ALWAYS_FLAGS are flags that should be passed to every compilation.
    # They are passed first to allow individual tests to override them.
            @echo "set TEST_ALWAYS_FLAGS \"$(SYSROOT_CFLAGS_FOR_TARGET)\"" >> ./site.tmp

That is, via 'site.exp', put 'SYSROOT_CFLAGS_FOR_TARGET' into
'TEST_ALWAYS_FLAGS', which is "passed to every compilation".

> [...], if this does work, then other library testsuites (e.g. libatomic.exp) might
> also need considering updating, I think.

Correct.  (I'm offering to take care of that.)

> 2020-01-14  Chung-Lin Tang  <cltang@codesourcery.com>
>
>       * Makefile.tpl  (NORMAL_TARGET_EXPORTS): Add export of
>       SYSROOT_CFLAGS_FOR_TARGET variable.
>       * Makefile.in:  Regenerate.
>
>       libgomp/
>       * testsuite/lib/libgomp.exp (ALWAYS_CFLAGS): Add
>       --sysroot=$SYSROOT_CFLAGS_FOR_TARGET option when doing build-tree testing.
>       Fix comment typo.
>       * testsuite/libgomp-test-support.exp.in (GCC_UNDER_TEST): Delete definition.

To that, Maciej had to report:

On 2020-01-31T21:46:01+0000, "Maciej W. Rozycki" <macro@wdc.com> wrote:
>  So it does seem to pick the right uninstalled compiler, however without
> the sysroot option and therefore all tests fail [...]

That, however, is not a conceptual but simply an implementation problem:

> --- libgomp/testsuite/lib/libgomp.exp (revision 279954)
> +++ libgomp/testsuite/lib/libgomp.exp (working copy)
> @@ -171,9 +171,16 @@ proc libgomp_init { args } {
>      lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
>      lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
>
> -    # For build-tree testing, also consider the library paths used for builing.
> +    # For build-tree testing, also consider the library paths used for building.
>      # For installed testing, we assume all that to be provided in the sysroot.
>      if { $blddir != "" } {
> +
> +     # If --with-build-sysroot= was specified, we assume it will be needed
> +     # for build-tree testing.
> +     if [info exists SYSROOT_CFLAGS_FOR_TARGET] {
> +         lappend ALWAYS_CFLAGS "additional_flags=--sysroot=$SYSROOT_CFLAGS_FOR_TARGET"
> +     }

Need 'global SYSROOT_CFLAGS_FOR_TARGET'.

Need to change:

    -       lappend ALWAYS_CFLAGS "additional_flags=--sysroot=$SYSROOT_CFLAGS_FOR_TARGET"
    +       lappend ALWAYS_CFLAGS "additional_flags=$SYSROOT_CFLAGS_FOR_TARGET"

..., as 'SYSROOT_CFLAGS_FOR_TARGET' already includes '--sysroot=' prefix.

> --- libgomp/testsuite/libgomp-test-support.exp.in     (revision 279954)
> +++ libgomp/testsuite/libgomp-test-support.exp.in     (working copy)
> @@ -1,5 +1,3 @@
> -set GCC_UNDER_TEST {@CC@}

Also need to capture 'SYSROOT_CFLAGS_FOR_TARGET' here, so that it's then
available at test time.

> --- Makefile.tpl      (revision 279954)
> +++ Makefile.tpl      (working copy)
> @@ -322,6 +322,7 @@ RAW_CXX_TARGET_EXPORTS = \
>
>  NORMAL_TARGET_EXPORTS = \
>       $(BASE_TARGET_EXPORTS) \
> +     SYSROOT_CFLAGS_FOR_TARGET="$(SYSROOT_CFLAGS_FOR_TARGET)"; export SYSROOT_CFLAGS_FOR_TARGET; \
>       CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX;

With that one moved into the generic 'BASE_TARGET_EXPORTS', adapting
things to the current state of affaris plus some polishing, the attached
"Consider '--with-build-sysroot=[...]' for target libraries' build-tree testing (instead of build-time 'CC' etc.) [PR109951]"
appears to be doing the right thing per my (limited, so far) testing.

Will you, Maciej, please test that this doesn't break your setting?

Will you, Iain, please test that this does address
<https://gcc.gnu.org/PR109951>
"libgomp, testsuite: non-native multilib c++ tests fail on Darwin"?

Anybody got any other comments?

Once that's all clear, we may either push this one already, and then I
work on applying the same changes to other target libraries
incrementally, or do all that at once.  I suppose: "push this one
already", to restore Iain's testing as well as giving these changes some
wider exposure, and in parallel "I work on applying the same changes to
other target libraries incrementally"?


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Comments

Maciej W. Rozycki June 3, 2023, 8:32 p.m. UTC | #1
Hi Thomas,

> Will you, Maciej, please test that this doesn't break your setting?

 Umm, this was implemented for my Western Digital development environment, 
which I don't have access to anymore.  I'll see what I can do, but it may 
be neither easy nor quick.  It's been long ago and I don't have a setup 
with multilibs enabled anymore.  And neither I remember the thorough 
problem analysis I went through that has led me to the conclusions.

 I've come across my note, in a reply to Chung-Lin's concerns, about using 
libgomp.exp as a standalone test driver.  Has this been verified somehow 
with your proposed change?

 Also I've skimmed over your change and this has caught my eye:

> diff --git a/libgomp/configure.ac b/libgomp/configure.ac
> index 1aad83a79da..49f7fb0dc82 100644
> --- a/libgomp/configure.ac
> +++ b/libgomp/configure.ac
> @@ -151,22 +151,11 @@ AC_SUBST(enable_static)
>  
>  AM_MAINTAINER_MODE
>  
> -# We optionally test libgomp C++ support, and for that want to use the proper
> -# C++ driver, 'g++' (or 'xg++' for build-tree testing).  Given that build of
> -# target libstdc++-v3 depends on target libgomp (see '../Makefile.def'), we
> -# cannot make build of target libgomp depend on target libstdc++-v3: circular
> -# dependency.  We thus cannot instantiate 'AC_PROG_CXX' here: we'd get
> -# '-funconfigured-libstdc++-v3' (see '../configure.ac').  Therefore, just
> -# capture 'CXX', and we'll fix this up at 'make check' time (see
> -# 'testsuite/lib/libgomp.exp:libgomp_init').
> -AC_SUBST(CXX)
> -
>  # Create a spec file, so that compile/link tests don't fail
>  test -f libgfortran.spec || touch libgfortran.spec
>  FCFLAGS="$FCFLAGS -L."
>  
> -# We need 'gfortran' to compile parts of the library, and test libgomp Fortran
> -# support.
> +# We need gfortran to compile parts of the library
>  # We can't use AC_PROG_FC because it expects a fully working gfortran.

-- missing full stop here, and I suggest to just make all this comment one 
paragraph (I can't imagine why it's not already, as the second sentence is 
clearly a continuation of the first one).

 I think a proper change description would be good too, as otherwise one 
may wonder why you have removed all the stuff above, and what this change 
is about anyway.

  Maciej
  

Patch

From ab5d1d3ef91b2ad7e1ed262c9487f727b79ceb3f Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 1 Jun 2023 23:07:37 +0200
Subject: [PATCH] Consider '--with-build-sysroot=[...]' for target libraries'
 build-tree testing (instead of build-time 'CC' etc.) [PR109951]

	PR testsuite/109951
	* Makefile.tpl (BASE_TARGET_EXPORTS): Add
	'SYSROOT_CFLAGS_FOR_TARGET'.
	* Makefile.in: Regenerate.
	libgomp/
	* configure.ac: Revert earlier changes, instead
	'AC_SUBST(SYSROOT_CFLAGS_FOR_TARGET)'.
	* Makefile.in: Regenerate.
	* configure: Likewise.
	* testsuite/Makefile.in: Likewise.
	* testsuite/lib/libgomp.exp (libgomp_init): Remove
	"Fix up '-funconfigured-libstdc++-v3' in 'GXX_UNDER_TEST'" code.
	If '--with-build-sysroot=[...]' was specified, use it for
	build-tree testing.
	* testsuite/libgomp-site-extra.exp.in (GCC_UNDER_TEST)
	(GXX_UNDER_TEST, GFORTRAN_UNDER_TEST): Don't set.
	(SYSROOT_CFLAGS_FOR_TARGET): Set.
	* testsuite/libgomp.c++/c++.exp (lang_source_re)
	(lang_include_flags): Set for build-tree testing.
	* testsuite/libgomp.oacc-c++/c++.exp (lang_source_re)
	(lang_include_flags): Likewise.

Co-authored-by: Chung-Lin Tang <cltang@codesourcery.com>
---
 Makefile.in                                 |  1 +
 Makefile.tpl                                |  1 +
 libgomp/Makefile.in                         |  2 +-
 libgomp/configure                           | 17 ++++-------------
 libgomp/configure.ac                        | 15 +++------------
 libgomp/testsuite/Makefile.in               |  2 +-
 libgomp/testsuite/lib/libgomp.exp           | 18 +++++-------------
 libgomp/testsuite/libgomp-site-extra.exp.in |  4 +---
 libgomp/testsuite/libgomp.c++/c++.exp       |  6 ++++++
 libgomp/testsuite/libgomp.oacc-c++/c++.exp  |  6 ++++++
 10 files changed, 29 insertions(+), 43 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index b559454cc90..e75bd98bde5 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -320,6 +320,7 @@  BASE_TARGET_EXPORTS = \
 	RANLIB="$(RANLIB_FOR_TARGET)"; export RANLIB; \
 	READELF="$(READELF_FOR_TARGET)"; export READELF; \
 	STRIP="$(STRIP_FOR_TARGET)"; export STRIP; \
+	SYSROOT_CFLAGS_FOR_TARGET="$(SYSROOT_CFLAGS_FOR_TARGET)"; export SYSROOT_CFLAGS_FOR_TARGET; \
 	WINDRES="$(WINDRES_FOR_TARGET)"; export WINDRES; \
 	WINDMC="$(WINDMC_FOR_TARGET)"; export WINDMC; \
 @if gcc-bootstrap
diff --git a/Makefile.tpl b/Makefile.tpl
index 6bcee3021c9..91bb9d279e4 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -323,6 +323,7 @@  BASE_TARGET_EXPORTS = \
 	RANLIB="$(RANLIB_FOR_TARGET)"; export RANLIB; \
 	READELF="$(READELF_FOR_TARGET)"; export READELF; \
 	STRIP="$(STRIP_FOR_TARGET)"; export STRIP; \
+	SYSROOT_CFLAGS_FOR_TARGET="$(SYSROOT_CFLAGS_FOR_TARGET)"; export SYSROOT_CFLAGS_FOR_TARGET; \
 	WINDRES="$(WINDRES_FOR_TARGET)"; export WINDRES; \
 	WINDMC="$(WINDMC_FOR_TARGET)"; export WINDMC; \
 @if gcc-bootstrap
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 3ef05e6a3cb..431bc87b629 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -368,7 +368,6 @@  CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CPU_COUNT = @CPU_COUNT@
-CXX = @CXX@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
@@ -436,6 +435,7 @@  SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
+SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
 VERSION = @VERSION@
 XCFLAGS = @XCFLAGS@
 XLDFLAGS = @XLDFLAGS@
diff --git a/libgomp/configure b/libgomp/configure
index e4e79c5199a..26557ac44f7 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -656,6 +656,7 @@  tmake_file
 XLDFLAGS
 XCFLAGS
 config_path
+SYSROOT_CFLAGS_FOR_TARGET
 FLOCK
 CPU_COUNT
 LIBGOMP_BUILD_VERSIONED_SHLIB_SUN_FALSE
@@ -679,7 +680,6 @@  libtool_VERSION
 ac_ct_FC
 FCFLAGS
 FC
-CXX
 MAINT
 MAINTAINER_MODE_FALSE
 MAINTAINER_MODE_TRUE
@@ -11770,22 +11770,11 @@  fi
 
 
 
-# We optionally test libgomp C++ support, and for that want to use the proper
-# C++ driver, 'g++' (or 'xg++' for build-tree testing).  Given that build of
-# target libstdc++-v3 depends on target libgomp (see '../Makefile.def'), we
-# cannot make build of target libgomp depend on target libstdc++-v3: circular
-# dependency.  We thus cannot instantiate 'AC_PROG_CXX' here: we'd get
-# '-funconfigured-libstdc++-v3' (see '../configure.ac').  Therefore, just
-# capture 'CXX', and we'll fix this up at 'make check' time (see
-# 'testsuite/lib/libgomp.exp:libgomp_init').
-
-
 # Create a spec file, so that compile/link tests don't fail
 test -f libgfortran.spec || touch libgfortran.spec
 FCFLAGS="$FCFLAGS -L."
 
-# We need 'gfortran' to compile parts of the library, and test libgomp Fortran
-# support.
+# We need gfortran to compile parts of the library
 # We can't use AC_PROG_FC because it expects a fully working gfortran.
 #AC_PROG_FC(gfortran)
 case `echo $GFORTRAN` in
@@ -16542,6 +16531,8 @@  fi
 
 fi
 
+
+
 # Get target configury.
 . ${srcdir}/configure.tgt
 CFLAGS="$save_CFLAGS $XCFLAGS"
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index 1aad83a79da..49f7fb0dc82 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -151,22 +151,11 @@  AC_SUBST(enable_static)
 
 AM_MAINTAINER_MODE
 
-# We optionally test libgomp C++ support, and for that want to use the proper
-# C++ driver, 'g++' (or 'xg++' for build-tree testing).  Given that build of
-# target libstdc++-v3 depends on target libgomp (see '../Makefile.def'), we
-# cannot make build of target libgomp depend on target libstdc++-v3: circular
-# dependency.  We thus cannot instantiate 'AC_PROG_CXX' here: we'd get
-# '-funconfigured-libstdc++-v3' (see '../configure.ac').  Therefore, just
-# capture 'CXX', and we'll fix this up at 'make check' time (see
-# 'testsuite/lib/libgomp.exp:libgomp_init').
-AC_SUBST(CXX)
-
 # Create a spec file, so that compile/link tests don't fail
 test -f libgfortran.spec || touch libgfortran.spec
 FCFLAGS="$FCFLAGS -L."
 
-# We need 'gfortran' to compile parts of the library, and test libgomp Fortran
-# support.
+# We need gfortran to compile parts of the library
 # We can't use AC_PROG_FC because it expects a fully working gfortran.
 #AC_PROG_FC(gfortran)
 case `echo $GFORTRAN` in
@@ -356,6 +345,8 @@  if test -z "$FLOCK"; then
   AC_CHECK_PROG(FLOCK, perl, $srcdir/testsuite/flock)
 fi
 
+AC_SUBST(SYSROOT_CFLAGS_FOR_TARGET)
+
 # Get target configury.
 . ${srcdir}/configure.tgt
 CFLAGS="$save_CFLAGS $XCFLAGS"
diff --git a/libgomp/testsuite/Makefile.in b/libgomp/testsuite/Makefile.in
index d743e464cdc..4155350cf80 100644
--- a/libgomp/testsuite/Makefile.in
+++ b/libgomp/testsuite/Makefile.in
@@ -147,7 +147,6 @@  CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CPU_COUNT = @CPU_COUNT@
-CXX = @CXX@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
@@ -215,6 +214,7 @@  SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
+SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
 VERSION = @VERSION@
 XCFLAGS = @XCFLAGS@
 XLDFLAGS = @XLDFLAGS@
diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp
index 2f9e538278f..1c4af9a8a2c 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -91,19 +91,6 @@  proc libgomp_init { args } {
       setenv LANG C.ASCII
     }
 
-    if { $blddir != "" } {
-	# Fix up '-funconfigured-libstdc++-v3' in 'GXX_UNDER_TEST' (see
-	# '../../configure.ac').
-	set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
-	if { [file exists $flags_file] } {
-	    set flags [exec sh $flags_file --build-includes]
-	    verbose -log "GXX_UNDER_TEST = $GXX_UNDER_TEST"
-	    set GXX_UNDER_TEST [string map [list \
-	      " -funconfigured-libstdc++-v3 " " $flags " \
-					   ] $GXX_UNDER_TEST]
-	    verbose -log "GXX_UNDER_TEST = $GXX_UNDER_TEST"
-	}
-    }
     if ![info exists GCC_UNDER_TEST] then {
 	if [info exists TOOL_EXECUTABLE] {
 	    set GCC_UNDER_TEST $TOOL_EXECUTABLE
@@ -185,6 +172,11 @@  proc libgomp_init { args } {
 
     set ALWAYS_CFLAGS ""
     if { $blddir != "" } {
+	# If '--with-build-sysroot=[...]' was specified, use it for build-tree
+	# testing.
+	global SYSROOT_CFLAGS_FOR_TARGET
+	lappend ALWAYS_CFLAGS "additional_flags=${SYSROOT_CFLAGS_FOR_TARGET}"
+
         lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
         # targets that use libgomp.a%s in their specs need a -B option
         # for uninstalled testing.
diff --git a/libgomp/testsuite/libgomp-site-extra.exp.in b/libgomp/testsuite/libgomp-site-extra.exp.in
index c824d85f7ed..8de14f48976 100644
--- a/libgomp/testsuite/libgomp-site-extra.exp.in
+++ b/libgomp/testsuite/libgomp-site-extra.exp.in
@@ -1,4 +1,2 @@ 
 set FLOCK {@FLOCK@}
-set GCC_UNDER_TEST {@CC@}
-set GXX_UNDER_TEST {@CXX@}
-set GFORTRAN_UNDER_TEST {@FC@}
+set SYSROOT_CFLAGS_FOR_TARGET {@SYSROOT_CFLAGS_FOR_TARGET@}
diff --git a/libgomp/testsuite/libgomp.c++/c++.exp b/libgomp/testsuite/libgomp.c++/c++.exp
index 8b4563b1d0d..ed096e17b9c 100644
--- a/libgomp/testsuite/libgomp.c++/c++.exp
+++ b/libgomp/testsuite/libgomp.c++/c++.exp
@@ -15,6 +15,10 @@  if { $blddir != "" } {
     verbose -log "GXX_UNDER_TEST not defined, will not execute c++ tests"
     return
 }
+if { $blddir != "" } {
+    set lang_source_re {^.*\.[cC]$}
+    set lang_include_flags [exec sh ${blddir}/../libstdc++-v3/scripts/testsuite_flags --build-includes]
+}
 lappend ALWAYS_CFLAGS "compiler=$GXX_UNDER_TEST"
 
 # If a testcase doesn't have special options, use these.
@@ -44,6 +48,8 @@  set_ld_library_path_env_vars
 dg-runtest $tests "" $DEFAULT_CFLAGS
 
 if { $blddir != "" } {
+    unset lang_source_re
+    unset lang_include_flags
     unset libstdc++_library_path
     unset lang_library_paths
 }
diff --git a/libgomp/testsuite/libgomp.oacc-c++/c++.exp b/libgomp/testsuite/libgomp.oacc-c++/c++.exp
index 79df401c99a..7b2315e406f 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/c++.exp
+++ b/libgomp/testsuite/libgomp.oacc-c++/c++.exp
@@ -25,6 +25,10 @@  if { $blddir != "" } {
     verbose -log "GXX_UNDER_TEST not defined, will not execute c++ tests"
     return
 }
+if { $blddir != "" } {
+    set lang_source_re {^.*\.[cC]$}
+    set lang_include_flags [exec sh ${blddir}/../libstdc++-v3/scripts/testsuite_flags --build-includes]
+}
 lappend ALWAYS_CFLAGS "compiler=$GXX_UNDER_TEST"
 
 # Initialize dg.
@@ -121,6 +125,8 @@  foreach offload_target [concat [split $offload_targets ","] "disable"] {
 unset offload_target
 
 if { $blddir != "" } {
+    unset lang_source_re
+    unset lang_include_flags
     unset libstdc++_library_path
     unset lang_library_paths
 }
-- 
2.34.1