I used Jakub's patch[1] as a starting point. After cleaning the
variables I tested using g++ for the C++ tests and it wans't onerous
as the comment in c++.exp implied, so I decided to just use g++.

[1] 
https://inbox.sourceware.org/gcc-patches/aYxz3oGdlDLWZPbI@tucnak/T/#m2fffbd0c0853485a80c7ed5101b6892cf1179a31

-- >8 --

The commit r16-7202-gb129ff0880c6d1 broke running libitm’s testsuite
using combinations of options because it didn’t clean up all the
global variables set in c++.exp.  Fix the regression by using g++ for
the C++ tests and cleaning up the variables shared between C and C++
tests.

libitm/ChangeLog:
        PR libitm/69018
        * testsuite/lib/libitm.exp (libitm_init):  Check
        GXX_UNDER_TEST.  Add "${blddir}/.libs" to
        always_ld_library_path if blddir is not empty.  Use
        "-fdiagnostics-plain-output".  Don't set compiler to GCC_UNDER_TEST.
        * testsuite/libitm.c++/c++.exp: If $blddir is not empty set
        libstdc++_library_path, shlib_ext, lang_include_flags, add
        "${blddir}/${lang_library_paths}" to ld_library_path.
        Unset libstdc++_library_path and shlib_ext if we skip C++
        tests and at the end of the test run.
        * testsuite/libitm.c/c.exp: Update the FSF address to the
        website in the license text. Unset lang_library_paths and
        lang_include_flags.  Set the compiler to $GCC_UNDER_TEST.

Co-authored-by: Jakub Jelinek  <[email protected]>
Signed-off-by: Pietro Monteiro <[email protected]>
---
 libitm/testsuite/lib/libitm.exp     | 21 ++++++++++++---
 libitm/testsuite/libitm.c++/c++.exp | 42 +++++++++++------------------
 libitm/testsuite/libitm.c/c.exp     | 14 +++++-----
 3 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/libitm/testsuite/lib/libitm.exp b/libitm/testsuite/lib/libitm.exp
index 69a49906d33..2de0f6cbf15 100644
--- a/libitm/testsuite/lib/libitm.exp
+++ b/libitm/testsuite/lib/libitm.exp
@@ -79,7 +79,7 @@ proc libitm_init { args } {
     global ALWAYS_CFLAGS
     global CFLAGS
     global TOOL_EXECUTABLE TOOL_OPTIONS
-    global GCC_UNDER_TEST
+    global GCC_UNDER_TEST GXX_UNDER_TEST
     global TESTING_IN_BUILD_TREE
     global target_triplet
     global always_ld_library_path
@@ -97,6 +97,17 @@ proc libitm_init { args } {
        } else {
            set GCC_UNDER_TEST "[find_gcc]"
        }
+       # Only if we're guessing 'GCC_UNDER_TEST', we're also going to guess
+       # 'GXX_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 tmpdir] {
@@ -119,7 +130,7 @@ proc libitm_init { args } {
     }
 
     # Compute what needs to be put into LD_LIBRARY_PATH
-    set always_ld_library_path ".:${blddir}/.libs"
+    set always_ld_library_path "."
 
     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
     if {$gccdir != ""} {
@@ -150,6 +161,8 @@ proc libitm_init { args } {
        lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
        lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
        lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
+
+       append always_ld_library_path ":${blddir}/.libs"
     }
     lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
 
@@ -179,7 +192,8 @@ proc libitm_init { args } {
     # Turn on transactional memory support.
     lappend ALWAYS_CFLAGS "additional_flags=-fgnu-tm"
 
-    lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
+    # Disable caret, color, URL diagnostics
+    lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-plain-output"
 }
 
 #
@@ -220,7 +234,6 @@ proc libitm_target_compile { source dest type options } {
 
     lappend options "additional_flags=[libio_include_flags]"
     lappend options "timeout=[timeout_value]"
-    lappend options "compiler=$GCC_UNDER_TEST"
 
     set options [concat $libitm_compile_options $options]
 
diff --git a/libitm/testsuite/libitm.c++/c++.exp 
b/libitm/testsuite/libitm.c++/c++.exp
index 90f3058e724..c24dc830bcc 100644
--- a/libitm/testsuite/libitm.c++/c++.exp
+++ b/libitm/testsuite/libitm.c++/c++.exp
@@ -16,39 +16,33 @@
 load_lib libitm-dg.exp
 load_gcc_lib gcc-dg.exp
 
-global shlib_ext
-
-set shlib_ext [get_shlib_extension]
-# The C++ tests should be linked with g++, which defaults to -shared-libgcc.
-# Doing that is currently too intrusive, so hardcode here.
-set lang_link_flags "-shared-libgcc -lstdc++"
-set lang_test_file_found 0
-set lang_library_path "../libstdc++-v3/src/.libs"
-
-# Initialize dg.
-dg-init
-
-set blddir [lookfor_file [get_multilibs] libitm]
-
-
 if { $blddir != "" } {
-    if { ![file exists "${blddir}/${lang_library_path}/libstdc++.a"]
-        && ![file exists 
"${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] } {
+    set libstdc++_library_path "../libstdc++-v3/src/.libs"
+    set shlib_ext [get_shlib_extension]
+    if { ![file exists "${blddir}/${libstdc++_library_path}/libstdc++.a"]
+        && ![file exists 
"${blddir}/${libstdc++_library_path}/libstdc++.${shlib_ext}"] } {
        verbose -log "No libstdc++ library found, will not execute c++ tests"
-       unset lang_library_path
+       unset libstdc++_library_path
+       unset shlib_ext
        return
     }
-    lappend lang_library_paths ${lang_library_path}
+    lappend lang_library_paths ${libstdc++_library_path}
 } elseif { ![info exists GXX_UNDER_TEST] } {
     verbose -log "GXX_UNDER_TEST not defined, will not execute c++ tests"
     return
 }
 
+lappend ALWAYS_CFLAGS "compiler=$GXX_UNDER_TEST"
+
+# Initialize dg.
+dg-init
+
 # Gather a list of all tests.
 set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]]
 
 if { $blddir != "" } {
-    set ld_library_path 
"$always_ld_library_path:${blddir}/${lang_library_path}"
+    set lang_include_flags [exec sh 
${blddir}/../libstdc++-v3/scripts/testsuite_flags --build-includes]
+    set ld_library_path 
"$always_ld_library_path:${blddir}/${lang_library_paths}"
 } else {
     set ld_library_path "$always_ld_library_path"
 }
@@ -56,18 +50,14 @@ 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 { [file exists $flags_file] } {
-    set lang_include_flags [exec sh $flags_file --build-includes]
-}
-
 # Main loop.
 dg-runtest $tests "" ""
 
 if { $blddir != "" } {
     unset lang_include_flags
-    unset lang_library_path
+    unset libstdc++_library_path
     unset lang_library_paths
+    unset shlib_ext
 }
 
 # All done.
diff --git a/libitm/testsuite/libitm.c/c.exp b/libitm/testsuite/libitm.c/c.exp
index daa71427d64..7a697b87093 100644
--- a/libitm/testsuite/libitm.c/c.exp
+++ b/libitm/testsuite/libitm.c/c.exp
@@ -9,20 +9,20 @@
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
 
-if [info exists lang_library_path] then {
-    unset lang_library_path
-    unset lang_link_flags
+if [info exists lang_library_paths] then {
+    unset lang_library_paths
 }
-if [info exists lang_test_file] then {
-    unset lang_test_file
+if [info exists lang_include_flags] then {
+    unset lang_include_flags
 }
 
 load_lib libitm-dg.exp
 load_gcc_lib gcc-dg.exp
 
+lappend ALWAYS_CFLAGS "compiler=$GCC_UNDER_TEST"
+
 # If a testcase doesn't have special options, use these.
 if ![info exists DEFAULT_CFLAGS] then {
     set DEFAULT_CFLAGS "-O2"
-- 
2.52.0

Reply via email to