From 9b7c6db76c5757a32b246dc8cb912902a3ffdb35 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 1 Nov 2014 16:25:26 +0100
Subject: [PATCH] libgomp C++, Fortran testsuites: Resolve
 'lang_test_file_found' first

	libgomp/
	* testsuite/libgomp.c++/c++.exp: Resolve 'lang_test_file_found'
	first.
	* testsuite/libgomp.fortran/fortran.exp: Likewise.
	* testsuite/libgomp.oacc-c++/c++.exp: Likewise.
	* testsuite/libgomp.oacc-fortran/fortran.exp: Likewise.
---
 libgomp/testsuite/libgomp.c++/c++.exp         | 43 +++++++++----------
 libgomp/testsuite/libgomp.fortran/fortran.exp | 30 ++++++-------
 libgomp/testsuite/libgomp.oacc-c++/c++.exp    | 37 ++++++++--------
 .../libgomp.oacc-fortran/fortran.exp          | 31 +++++++------
 4 files changed, 68 insertions(+), 73 deletions(-)

diff --git a/libgomp/testsuite/libgomp.c++/c++.exp b/libgomp/testsuite/libgomp.c++/c++.exp
index 442e9f744d0..797a05ca870 100644
--- a/libgomp/testsuite/libgomp.c++/c++.exp
+++ b/libgomp/testsuite/libgomp.c++/c++.exp
@@ -1,12 +1,25 @@
 load_lib libgomp-dg.exp
 load_gcc_lib gcc-dg.exp
 
-global shlib_ext
-
-set shlib_ext [get_shlib_extension]
-set lang_link_flags "-lstdc++"
 set lang_test_file_found 0
-set lang_library_path "../libstdc++-v3/src/.libs"
+if { $blddir != "" } {
+    set lang_library_path "../libstdc++-v3/src/.libs"
+    set shlib_ext [get_shlib_extension]
+    # Look for a static libstdc++ first.
+    if [file exists "${blddir}/${lang_library_path}/libstdc++.a"] {
+        set lang_test_file_found 1
+        # We may have a shared only build, so look for a shared libstdc++.
+    } elseif [file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] {
+        set lang_test_file_found 1
+    } else {
+        puts "No libstdc++ library found, will not execute c++ tests"
+    }
+} elseif { [info exists GXX_UNDER_TEST] } {
+    set lang_test_file_found 1
+} else {
+    puts "GXX_UNDER_TEST not defined, will not execute c++ tests"
+}
+set lang_link_flags "-lstdc++"
 
 # If a testcase doesn't have special options, use these.
 if ![info exists DEFAULT_CFLAGS] then {
@@ -24,22 +37,6 @@ lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
 set SAVE_GCC_UNDER_TEST "$GCC_UNDER_TEST"
 set GCC_UNDER_TEST "$GCC_UNDER_TEST -x c++"
 
-if { $blddir != "" } {
-    # Look for a static libstdc++ first.
-    if [file exists "${blddir}/${lang_library_path}/libstdc++.a"] {
-        set lang_test_file_found 1
-        # We may have a shared only build, so look for a shared libstdc++.
-    } elseif [file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] {
-        set lang_test_file_found 1
-    } else {
-        puts "No libstdc++ library found, will not execute c++ tests"
-    }
-} elseif { [info exists GXX_UNDER_TEST] } {
-    set lang_test_file_found 1
-} else {
-    puts "GXX_UNDER_TEST not defined, will not execute c++ tests"
-}
-
 if { $lang_test_file_found } {
     # Gather a list of all tests.
     set tests [lsort [concat \
@@ -72,7 +69,9 @@ if [info exists lang_include_flags] then {
     unset lang_source_re
     unset lang_include_flags
 }
-unset lang_library_path
+if { $blddir != "" } {
+    unset lang_library_path
+}
 unset lang_link_flags
 unset lang_test_file_found
 
diff --git a/libgomp/testsuite/libgomp.fortran/fortran.exp b/libgomp/testsuite/libgomp.fortran/fortran.exp
index 7ea00a25bd9..16ce9d3e023 100644
--- a/libgomp/testsuite/libgomp.fortran/fortran.exp
+++ b/libgomp/testsuite/libgomp.fortran/fortran.exp
@@ -2,23 +2,10 @@ load_lib libgomp-dg.exp
 load_gcc_lib gcc-dg.exp
 load_gcc_lib gfortran-dg.exp
 
-global shlib_ext
-global ALWAYS_CFLAGS
-
-set shlib_ext [get_shlib_extension]
-set lang_library_path	"../libgfortran/.libs"
-set lang_link_flags	"-lgfortran -foffload=-lgfortran"
 set lang_test_file_found 0
-
-# Initialize dg.
-dg-init
-
-# Turn on OpenMP.
-lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
-
 if { $blddir != "" } {
-    set lang_source_re {^.*\.[fF](|90|95|03|08)$}
-    set lang_include_flags "-fintrinsic-modules-path=${blddir}"
+    set lang_library_path "../libgfortran/.libs"
+    set shlib_ext [get_shlib_extension]
     # Look for a static libgfortran first.
     if [file exists "${blddir}/${lang_library_path}/libgfortran.a"] {
         set lang_test_file_found 1
@@ -33,6 +20,17 @@ if { $blddir != "" } {
 } else {
     puts "GFORTRAN_UNDER_TEST not defined, will not execute fortran tests"
 }
+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"
+
+# Initialize dg.
+dg-init
+
+# Turn on OpenMP.
+lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
 
 if { $lang_test_file_found } {
     # Gather a list of all tests.
@@ -71,8 +69,8 @@ if { $lang_test_file_found } {
 if { $blddir != "" } {
     unset lang_source_re
     unset lang_include_flags
+    unset lang_library_path
 }
-unset lang_library_path
 unset lang_link_flags
 unset lang_test_file_found
 
diff --git a/libgomp/testsuite/libgomp.oacc-c++/c++.exp b/libgomp/testsuite/libgomp.oacc-c++/c++.exp
index 5d9dc5d4a3f..060aaa27419 100644
--- a/libgomp/testsuite/libgomp.oacc-c++/c++.exp
+++ b/libgomp/testsuite/libgomp.oacc-c++/c++.exp
@@ -11,26 +11,10 @@ proc check_effective_target_c++ { } {
     return 1
 }
 
-global shlib_ext
-
-set shlib_ext [get_shlib_extension]
-set lang_link_flags "-lstdc++"
 set lang_test_file_found 0
-set lang_library_path "../libstdc++-v3/src/.libs"
-
-# Initialize dg.
-dg-init
-torture-init
-
-# Turn on OpenACC.
-lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
-
-# 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++"
-
 if { $blddir != "" } {
+    set lang_library_path "../libstdc++-v3/src/.libs"
+    set shlib_ext [get_shlib_extension]
     # Look for a static libstdc++ first.
     if [file exists "${blddir}/${lang_library_path}/libstdc++.a"] {
         set lang_test_file_found 1
@@ -45,6 +29,19 @@ if { $blddir != "" } {
 } else {
     puts "GXX_UNDER_TEST not defined, will not execute c++ tests"
 }
+set lang_link_flags "-lstdc++"
+
+# Initialize dg.
+dg-init
+torture-init
+
+# Turn on OpenACC.
+lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
+
+# 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++"
 
 if { $lang_test_file_found } {
     # Gather a list of all tests.
@@ -153,7 +150,9 @@ if [info exists lang_include_flags] then {
     unset lang_source_re
     unset lang_include_flags
 }
-unset lang_library_path
+if { $blddir != "" } {
+    unset lang_library_path
+}
 unset lang_link_flags
 unset lang_test_file_found
 
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp b/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
index 1ac2320ec22..9af526007cf 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
+++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
@@ -4,23 +4,10 @@ load_lib libgomp-dg.exp
 load_gcc_lib gcc-dg.exp
 load_gcc_lib gfortran-dg.exp
 
-global shlib_ext
-global ALWAYS_CFLAGS
-
-set shlib_ext [get_shlib_extension]
-set lang_library_path	"../libgfortran/.libs"
-set lang_link_flags	"-lgfortran -foffload=-lgfortran"
 set lang_test_file_found 0
-
-# Initialize dg.
-dg-init
-
-# Turn on OpenACC.
-lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
-
 if { $blddir != "" } {
-    set lang_source_re {^.*\.[fF](|90|95|03|08)$}
-    set lang_include_flags "-fintrinsic-modules-path=${blddir}"
+    set lang_library_path "../libgfortran/.libs"
+    set shlib_ext [get_shlib_extension]
     # Look for a static libgfortran first.
     if [file exists "${blddir}/${lang_library_path}/libgfortran.a"] {
         set lang_test_file_found 1
@@ -35,6 +22,18 @@ if { $blddir != "" } {
 } else {
     puts "GFORTRAN_UNDER_TEST not defined, will not execute fortran tests"
 }
+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"
+
+# Initialize dg.
+dg-init
+
+# Turn on OpenACC.
+lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
+
 
 if { $lang_test_file_found } {
     # Gather a list of all tests.
@@ -120,8 +119,8 @@ if { $lang_test_file_found } {
 if { $blddir != "" } {
     unset lang_source_re
     unset lang_include_flags
+    unset lang_library_path
 }
-unset lang_library_path
 unset lang_link_flags
 unset lang_test_file_found
 
-- 
2.34.1

