libgomp testsuite: As appropriate, use the 'gcc', 'g++', 'gfortran' driver [PR91884] (was: libgomp testsuite: Have each '*.exp' file specify the compiler to use [PR91884] (was: libgomp testsuite: (not) using a specific driver for C++, Fortran?))

Message ID 877cte9cfa.fsf@euler.schwinge.homeip.net
State Unresolved
Headers
Series libgomp testsuite: As appropriate, use the 'gcc', 'g++', 'gfortran' driver [PR91884] (was: libgomp testsuite: Have each '*.exp' file specify the compiler to use [PR91884] (was: libgomp testsuite: (not) using a specific driver for C++, Fortran?)) |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Thomas Schwinge May 12, 2023, 8:33 a.m. UTC
  Hi!

On 2023-05-12T10:27:29+0200, I wrote:
> The cleanup is done, now turn ourselves to the changes proper re PR91884
> "libgomp testsuite: (not) using a specific driver for C++, Fortran":
>
> On 2014-11-04T10:31:37-0800, Mike Stump <mikestump@comcast.net> wrote:
>> On Nov 4, 2014, at 4:13 AM, Thomas Schwinge <thomas@codesourcery.com> wrote:
>>> On Wed, 15 Oct 2014 17:46:48 +0200, I wrote:
>>>> No matter whether it's C, C++, or Fortran source code, the libgomp
>>>> testsuite always uses (for build-tree testing) gcc/xgcc, or (for
>>>> installed testing) GCC_UNDER_TEST.  It doesn't make use of
>>>> GXX_UNDER_TEST, GFORTRAN_UNDER_TEST.  To support the latter two
>>>> languages' needs, some -l[...] flags are then added via lang_link_flags.
>>>> For example, for Fortran this is -lgfortran.  This is, however, not what
>>>> would happen if using the gfortran driver to build (which is what a user
>>>> would be doing -- which we should replicate as much as possible at least
>>>> for installed testing): the gfortran driver also adds -lquadmath, if
>>>> applicable.
>>>>
>>>> Now, I wonder why to re-invent all that in the libgomp testsuite, if the
>>>> respective driver already has that knowledge, via spec files, for
>>>> example?  (Also, the regular GCC compiler tests, gcc/testsuite/, are
>>>> doing the right thing.)  Why is libgomp testsuite implemented this way --
>>>> just a legacy of the past, or is there a need for that (that I'm not
>>>> seeing)?
>>>>
>>>> [...]
>>>>
>>>> Am I on the right track with the following?
>>>
>>> Nobody commented, which also means nobody disagreed
>>
>> :-)
>>
>>> OK to commit all that to trunk?
>>
>> Ok, thanks.
>
>> Watch for any review points from the libgomp people, they might trickle a few in.  I don’t mean to cut short any review points from them.
>
> After Tobias in his 2019 "PR testsuite/91884 Add -lquadmath if available"
> again picked up my idea and parts of my 2014 patches (... but in the end
> settled for a "simpler" solution to the problem at hand), my original
> proposal also got an ACK from Rainer,
> <https://inbox.sourceware.org/ydd36g2jc7a.fsf@CeBiTec.Uni-Bielefeld.DE>.
>
>> Also, please watch for breakage.
>
> Always.  :-)
>
>
> First, another "no change in behavior" new patch, loosely based
> on/extracted out of my earlier work.  I'm posting it separately, but
> given that it's in line with my earlier work (just a separate step), I
> intend to push it soon, unless there are any objections, of course.
> "libgomp testsuite: Have each '*.exp' file specify the compiler to use [PR91884]"
> ("..., which is still 'GCC_UNDER_TEST' for all of them"), see attached.

..., and then finally
"libgomp testsuite: As appropriate, use the 'gcc', 'g++', 'gfortran' driver [PR91884]",
see attached.

    ..., that is, 'GCC_UNDER_TEST', 'GXX_UNDER_TEST', 'GFORTRAN_UNDER_TEST' instead
    of 'GCC_UNDER_TEST' for all of them.  No need anymore for 'gcc -lstdc++ -x c++'
    for C++ code, or 'gcc -lgfortran' plus conditional '-lquadmath' for Fortran
    code.  (Getting rid of explicit '-foffload=-lgfortran' is for another day.)


By the way, all changes (individually) tested in a number of different
configurations: '--enable-languages=[...]', native vs. cross, build-tree
vs. installed testing, etc.


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
  

Patch

From 5324d8fb140c1ab790ea4756983bff203c549ce3 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Wed, 10 May 2023 15:01:55 +0200
Subject: [PATCH] libgomp testsuite: As appropriate, use the 'gcc', 'g++',
 'gfortran' driver [PR91884]

..., that is, 'GCC_UNDER_TEST', 'GXX_UNDER_TEST', 'GFORTRAN_UNDER_TEST' instead
of 'GCC_UNDER_TEST' for all of them.  No need anymore for 'gcc -lstdc++ -x c++'
for C++ code, or 'gcc -lgfortran' plus conditional '-lquadmath' for Fortran
code.  (Getting rid of explicit '-foffload=-lgfortran' is for another day.)

	PR testsuite/91884
	libgomp/
	* configure.ac: 'AC_SUBST(CXX)'.
	* configure: Regenerate.
	* Makefile.in: Likewise.
	* testsuite/Makefile.in: Likewise.
	* testsuite/libgomp-site-extra.exp.in (GXX_UNDER_TEST)
	(GFORTRAN_UNDER_TEST): Set.
	* testsuite/lib/libgomp.exp (libgomp_init): Adjust.
	* testsuite/libgomp.c++/c++.exp: Use 'GXX_UNDER_TEST'.
	* testsuite/libgomp.oacc-c++/c++.exp: Likewise.
	* testsuite/libgomp.fortran/fortran.exp: Use
	'GFORTRAN_UNDER_TEST'.
	* testsuite/libgomp.oacc-fortran/fortran.exp: Likewise.
---
 libgomp/Makefile.in                           |  1 +
 libgomp/configure                             | 18 ++++++++--
 libgomp/configure.ac                          | 13 ++++++-
 libgomp/testsuite/Makefile.in                 |  1 +
 libgomp/testsuite/lib/libgomp.exp             | 35 ++++++++++++++++++-
 libgomp/testsuite/libgomp-site-extra.exp.in   |  2 ++
 libgomp/testsuite/libgomp.c++/c++.exp         | 22 +-----------
 libgomp/testsuite/libgomp.fortran/fortran.exp | 11 ++----
 libgomp/testsuite/libgomp.oacc-c++/c++.exp    | 22 +-----------
 .../libgomp.oacc-fortran/fortran.exp          | 11 ++----
 10 files changed, 71 insertions(+), 65 deletions(-)

diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 2c81ccacc1d..95585353b4e 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -368,6 +368,7 @@  CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CPU_COUNT = @CPU_COUNT@
+CXX = @CXX@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
diff --git a/libgomp/configure b/libgomp/configure
index fd0e337b578..9c91173015f 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -678,6 +678,7 @@  libtool_VERSION
 ac_ct_FC
 FCFLAGS
 FC
+CXX
 MAINT
 MAINTAINER_MODE_FALSE
 MAINTAINER_MODE_TRUE
@@ -11418,7 +11419,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11421 "configure"
+#line 11422 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11524,7 +11525,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11527 "configure"
+#line 11528 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11814,7 +11815,18 @@  fi
 test -f libgfortran.spec || touch libgfortran.spec
 FCFLAGS="$FCFLAGS -L."
 
-# We need gfortran to compile parts of the library
+# 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').
+
+
+# We need 'gfortran' to compile parts of the library, and test libgomp Fortran
+# support.
 # We can't use AC_PROG_FC because it expects a fully working gfortran.
 #AC_PROG_FC(gfortran)
 case `echo $GFORTRAN` in
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index a9b1f3973f7..4d2518d7cb9 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -156,7 +156,18 @@  AM_MAINTAINER_MODE
 test -f libgfortran.spec || touch libgfortran.spec
 FCFLAGS="$FCFLAGS -L."
 
-# We need gfortran to compile parts of the library
+# 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)
+
+# We need 'gfortran' to compile parts of the library, and test libgomp Fortran
+# support.
 # We can't use AC_PROG_FC because it expects a fully working gfortran.
 #AC_PROG_FC(gfortran)
 case `echo $GFORTRAN` in
diff --git a/libgomp/testsuite/Makefile.in b/libgomp/testsuite/Makefile.in
index 7a88f0fe5c6..4e8b21e8b38 100644
--- a/libgomp/testsuite/Makefile.in
+++ b/libgomp/testsuite/Makefile.in
@@ -147,6 +147,7 @@  CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CPU_COUNT = @CPU_COUNT@
+CXX = @CXX@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp
index 48c43e4a136..30d67e4f280 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -66,7 +66,7 @@  proc libgomp_init { args } {
     global ALWAYS_CFLAGS
     global CFLAGS
     global TOOL_EXECUTABLE TOOL_OPTIONS
-    global GCC_UNDER_TEST
+    global GCC_UNDER_TEST GXX_UNDER_TEST GFORTRAN_UNDER_TEST
     global TESTING_IN_BUILD_TREE
     global target_triplet
     global always_ld_library_path
@@ -85,12 +85,45 @@  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
 	} else {
 	    set GCC_UNDER_TEST "[find_gcc]"
 	}
+	# Only if we're guessing 'GCC_UNDER_TEST', we're also going to guess
+	# 'GXX_UNDER_TEST', 'GFORTRAN_UNDER_TEST'.
+	if ![info exists GXX_UNDER_TEST] then {
+	    if [info exists TOOL_EXECUTABLE] {
+		set GXX_UNDER_TEST $TOOL_EXECUTABLE
+	    } else {
+		set GXX_UNDER_TEST "[find_g++]"
+	    }
+	} else {
+	    error "GXX_UNDER_TEST set but not GCC_UNDER_TEST"
+	}
+	if ![info exists GFORTRAN_UNDER_TEST] then {
+	    if [info exists TOOL_EXECUTABLE] {
+		set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
+	    } else {
+		set GFORTRAN_UNDER_TEST "[find_gfortran]"
+	    }
+	} else {
+	    error "GFORTRAN_UNDER_TEST set but not GCC_UNDER_TEST"
+	}
     }
 
     if ![info exists tmpdir] {
diff --git a/libgomp/testsuite/libgomp-site-extra.exp.in b/libgomp/testsuite/libgomp-site-extra.exp.in
index c0d26660bad..15407ab1749 100644
--- a/libgomp/testsuite/libgomp-site-extra.exp.in
+++ b/libgomp/testsuite/libgomp-site-extra.exp.in
@@ -1 +1,3 @@ 
 set GCC_UNDER_TEST {@CC@}
+set GXX_UNDER_TEST {@CXX@}
+set GFORTRAN_UNDER_TEST {@FC@}
diff --git a/libgomp/testsuite/libgomp.c++/c++.exp b/libgomp/testsuite/libgomp.c++/c++.exp
index 4110ada7c46..8b4563b1d0d 100644
--- a/libgomp/testsuite/libgomp.c++/c++.exp
+++ b/libgomp/testsuite/libgomp.c++/c++.exp
@@ -15,12 +15,7 @@  if { $blddir != "" } {
     verbose -log "GXX_UNDER_TEST not defined, will not execute c++ tests"
     return
 }
-set lang_link_flags "-lstdc++"
-# Switch into C++ mode.  Otherwise, the 'libgomp.c-c++-common/*.c'
-# files would be compiled as C files.
-set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST"
-set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++"
-lappend ALWAYS_CFLAGS "compiler=$GCC_UNDER_TEST"
+lappend ALWAYS_CFLAGS "compiler=$GXX_UNDER_TEST"
 
 # If a testcase doesn't have special options, use these.
 if ![info exists DEFAULT_CFLAGS] then {
@@ -45,28 +40,13 @@  if { $blddir != "" } {
 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
 set_ld_library_path_env_vars
 
-set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
-if { $blddir != ""
-     && [file exists $flags_file] } {
-    set lang_source_re {^.*\.[cC]$}
-    set lang_include_flags [exec sh $flags_file --build-includes]
-}
-
 # Main loop.
 dg-runtest $tests "" $DEFAULT_CFLAGS
 
-# See above.
-set GCC_UNDER_TEST "$SAVE_GCC_UNDER_TEST"
-
-if [info exists lang_include_flags] then {
-    unset lang_source_re
-    unset lang_include_flags
-}
 if { $blddir != "" } {
     unset libstdc++_library_path
     unset lang_library_paths
 }
-unset lang_link_flags
 
 # All done.
 dg-finish
diff --git a/libgomp/testsuite/libgomp.fortran/fortran.exp b/libgomp/testsuite/libgomp.fortran/fortran.exp
index 9aeebd3af7c..e69656bce23 100644
--- a/libgomp/testsuite/libgomp.fortran/fortran.exp
+++ b/libgomp/testsuite/libgomp.fortran/fortran.exp
@@ -28,8 +28,8 @@  if { $blddir != "" } {
     set lang_source_re {^.*\.[fF](|90|95|03|08)$}
     set lang_include_flags "-fintrinsic-modules-path=${blddir}"
 }
-set lang_link_flags "-lgfortran -foffload=-lgfortran"
-lappend ALWAYS_CFLAGS "compiler=$GCC_UNDER_TEST"
+set lang_link_flags "-foffload=-lgfortran"
+lappend ALWAYS_CFLAGS "compiler=$GFORTRAN_UNDER_TEST"
 
 # Initialize dg.
 dg-init
@@ -46,13 +46,6 @@  if { $blddir != "" } {
 
     if { $libquadmath_library_path != "" } {
 	append ld_library_path ":${blddir}/${libquadmath_library_path}"
-	append lang_link_flags " -lquadmath"
-    }
-} else {
-    if { [check_no_compiler_messages has_libquadmath executable {
-             int main() {return 0;}
-          } "-lgfortran -lquadmath"] } then {
-	append lang_link_flags " -lquadmath"
     }
 }
 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
diff --git a/libgomp/testsuite/libgomp.oacc-c++/c++.exp b/libgomp/testsuite/libgomp.oacc-c++/c++.exp
index 70fb9da0ef4..79df401c99a 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/c++.exp
+++ b/libgomp/testsuite/libgomp.oacc-c++/c++.exp
@@ -25,12 +25,7 @@  if { $blddir != "" } {
     verbose -log "GXX_UNDER_TEST not defined, will not execute c++ tests"
     return
 }
-set lang_link_flags "-lstdc++"
-# Switch into C++ mode.  Otherwise, the 'libgomp.oacc-c-c++-common/*.c'
-# files would be compiled as C files.
-set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST"
-set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++"
-lappend ALWAYS_CFLAGS "compiler=$GCC_UNDER_TEST"
+lappend ALWAYS_CFLAGS "compiler=$GXX_UNDER_TEST"
 
 # Initialize dg.
 dg-init
@@ -51,13 +46,6 @@  if { $blddir != "" } {
 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
 set_ld_library_path_env_vars
 
-set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
-if { $blddir != ""
-     && [file exists $flags_file] } {
-    set lang_source_re {^.*\.[cC]$}
-    set lang_include_flags [exec sh $flags_file --build-includes]
-}
-
 # Test with all available offload targets, and with offloading disabled.
 foreach offload_target [concat [split $offload_targets ","] "disable"] {
     global openacc_device_type
@@ -132,18 +120,10 @@  foreach offload_target [concat [split $offload_targets ","] "disable"] {
 }
 unset offload_target
 
-# See above.
-set GCC_UNDER_TEST "$SAVE_GCC_UNDER_TEST"
-
-if [info exists lang_include_flags] then {
-    unset lang_source_re
-    unset lang_include_flags
-}
 if { $blddir != "" } {
     unset libstdc++_library_path
     unset lang_library_paths
 }
-unset lang_link_flags
 
 # All done.
 torture-finish
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp b/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
index 56dd9485339..2e8aa2285fb 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
+++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
@@ -30,8 +30,8 @@  if { $blddir != "" } {
     set lang_source_re {^.*\.[fF](|90|95|03|08)$}
     set lang_include_flags "-fintrinsic-modules-path=${blddir}"
 }
-set lang_link_flags "-lgfortran -foffload=-lgfortran"
-lappend ALWAYS_CFLAGS "compiler=$GCC_UNDER_TEST"
+set lang_link_flags "-foffload=-lgfortran"
+lappend ALWAYS_CFLAGS "compiler=$GFORTRAN_UNDER_TEST"
 
 # Initialize dg.
 dg-init
@@ -49,13 +49,6 @@  if { $blddir != "" } {
 
     if { $libquadmath_library_path != "" } {
 	append ld_library_path ":${blddir}/${libquadmath_library_path}"
-	append lang_link_flags " -lquadmath"
-    }
-} else {
-    if { [check_no_compiler_messages has_libquadmath executable {
-             int main() {return 0;}
-          } "-lgfortran -lquadmath"] } then {
-	append lang_link_flags " -lquadmath"
     }
 }
 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
-- 
2.34.1