public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] [testsuite] test for weak_undefined support and add options
@ 2023-03-15 14:06 Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-03-15 14:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6c10ee598ca6914fc7d190b12ea48dd0afa5544f

commit 6c10ee598ca6914fc7d190b12ea48dd0afa5544f
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Wed Mar 15 07:54:47 2023 -0300

    [testsuite] test for weak_undefined support and add options
    
    A number of tests that depend on weak undefined symbols fail to
    require that support, and arrange to skip some targets and add special
    options to others on a test-by-test basis.  Fix this by stating the
    requirement explicitly, and adding a proc to return any required
    options.
    
    Others rely on weak undefined symbols only to test for the
    availability of posix_memalign.  Drop that in favor of dg effective
    target support for posix_memalign.
    
    
    for  gcc/testsuite/ChangeLog
    
            * lib/target-supports.exp (add_options_for_weak_undefined):
            New.
            (check_effective_target_weak_undefined): Use it.
            (check_effective_target_posix_memalign): New.
            * gcc.dg/torture/pr53922.c: Drop skips and custom options in
            favor of effective target requirement and added options for
            weak_undefined symbols.
            * gcc.dg/torture/pr90020.c: Likewise.
            * gcc.dg/addr_equal-1.c: Likewise.
            * gcc.target/aarch64/aapcs64/aapcs64.exp: Likewise, for
            abitest.S-using tests.
            * gcc.dg/torture/pr60092.c: Likewise, but in favor of
            posix_memalign tests.
            * gcc.dg/vect/vect-tail-nomask-1.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/addr_equal-1.c                |  5 ++---
 gcc/testsuite/gcc.dg/torture/pr53922.c             | 10 ++-------
 gcc/testsuite/gcc.dg/torture/pr60092.c             | 12 ++--------
 gcc/testsuite/gcc.dg/torture/pr90020.c             |  7 ++----
 gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c     | 11 ++-------
 .../gcc.target/aarch64/aapcs64/aapcs64.exp         |  6 +++--
 gcc/testsuite/lib/target-supports.exp              | 26 ++++++++++++++++++++--
 7 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/addr_equal-1.c b/gcc/testsuite/gcc.dg/addr_equal-1.c
index 35fa0102e30..db65dea4a8d 100644
--- a/gcc/testsuite/gcc.dg/addr_equal-1.c
+++ b/gcc/testsuite/gcc.dg/addr_equal-1.c
@@ -1,9 +1,8 @@
-/* { dg-do run { target { nonpic || pie_enabled } } } */
-/* { dg-require-weak "" } */
+/* { dg-do run { target { { nonpic || pie_enabled } && weak_undefined } } } */
 /* { dg-require-alias "" } */
 /* { dg-options "-O2 -fdelete-null-pointer-checks" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
 /* { dg-skip-if "function pointers can be NULL" { keeps_null_pointer_checks } } */
+/* { dg-add-options weak_undefined } */
 void abort (void);
 extern int undef_var0, undef_var1;
 extern __attribute__ ((weak)) int weak_undef_var0;
diff --git a/gcc/testsuite/gcc.dg/torture/pr53922.c b/gcc/testsuite/gcc.dg/torture/pr53922.c
index b3f2c1a58f8..07359d67649 100644
--- a/gcc/testsuite/gcc.dg/torture/pr53922.c
+++ b/gcc/testsuite/gcc.dg/torture/pr53922.c
@@ -1,11 +1,5 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined" { *-*-mingw* } } */
-/* { dg-skip-if "No undefined weak" { *-*-aix* } } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 int x(int a)
 {
diff --git a/gcc/testsuite/gcc.dg/torture/pr60092.c b/gcc/testsuite/gcc.dg/torture/pr60092.c
index 74e7c174a83..102ba6e0d9f 100644
--- a/gcc/testsuite/gcc.dg/torture/pr60092.c
+++ b/gcc/testsuite/gcc.dg/torture/pr60092.c
@@ -1,12 +1,7 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { posix_memalign } } } */
 
 typedef __SIZE_TYPE__ size_t;
-extern int posix_memalign(void **memptr, size_t alignment, size_t size) __attribute__((weak));
+extern int posix_memalign(void **memptr, size_t alignment, size_t size);
 extern void abort(void);
 int
 main (void)
@@ -14,9 +9,6 @@ main (void)
   void *p;
   int ret;
 
-  if (!posix_memalign)
-    return 0;
-
   p = (void *)&ret;
   ret = posix_memalign (&p, sizeof (void *), -1);
   if (p != (void *)&ret)
diff --git a/gcc/testsuite/gcc.dg/torture/pr90020.c b/gcc/testsuite/gcc.dg/torture/pr90020.c
index 657c4ccfe45..40035aa758e 100644
--- a/gcc/testsuite/gcc.dg/torture/pr90020.c
+++ b/gcc/testsuite/gcc.dg/torture/pr90020.c
@@ -1,8 +1,5 @@
-/* { dg-do run } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* || powerpc-ibm-aix* } } */
-/* { dg-require-weak "" } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run  { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 void __attribute__((noinline,noclone))
 check (int i)
diff --git a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
index e5bbeaede09..ee9ab2e9d91 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
@@ -1,14 +1,10 @@
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-skip-if "No undefined weak" { ! { posix_memalign } } } */
 /* { dg-additional-options "--param vect-epilogues-nomask=1 -mavx2" { target avx2_runtime } } */
 
 #define SIZE 1023
 #define ALIGN 64
 
-extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size) __attribute__((weak));
+extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size);
 extern void free (void *);
 
 void __attribute__((noinline))
@@ -98,9 +94,6 @@ run_test ()
 int
 main (int argc, const char **argv)
 {
-  if (!posix_memalign)
-    return 0;
-
   run_test ();
   return 0;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
index 8cf9cc1e8e5..5b40ad2a689 100644
--- a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
+++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
@@ -32,12 +32,14 @@ set additional_flags "-W -Wall -Wno-abi -fno-pie -no-pie"
 # Test parameter passing.  This uses abitest.S which relies on weak
 # symbols.
 
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/test_*.c]] {
+	set additional_flags_for_abitest $additional_flags
+	lappend additional_flags_for_abitest [add_options_for_weak_undefined ""]
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		"$additional_flags_for_abitest"
 	}
     }
 }
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index fcfe290d07d..ac6f000afd1 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -356,6 +356,18 @@ proc check_weak_available { } {
     }
 }
 
+# return options to add to enable weak undefined symbols.
+
+proc add_options_for_weak_undefined { flags } {
+    if { [istarget *-*-darwin*] } {
+	lappend flags "-Wl,-undefined,dynamic_lookup"
+	if { [istarget *-*-darwin[89]*] } {
+	    lappend flags "-Wl,-flat_namespace"
+	}
+    }
+    return $flags
+}
+
 # return 1 if weak undefined symbols are supported.
 
 proc check_effective_target_weak_undefined { } {
@@ -365,7 +377,7 @@ proc check_effective_target_weak_undefined { } {
     return [check_runtime weak_undefined {
 	extern void foo () __attribute__((weak));
 	int main (void) { if (foo) return 1; return 0; }
-    } ""]
+    } [add_options_for_weak_undefined ""]]
 }
 
 ###############################
@@ -1154,6 +1166,16 @@ proc check_effective_target_clone {} {
     return [check_function_available "clone"]
 }
 
+# Return 1 if the target supports posix_memalign, 0 otherwise.
+proc check_effective_target_posix_memalign {} {
+    if { [istarget *-*-vxworks*] } {
+	# VxWorks doesn't have posix_memalign but our way to test
+	# can't tell as we're doing partial links for kernel modules.
+	return 0
+     }    
+    return [check_function_available "posix_memalign"]
+}
+
 # Return 1 if the target supports setrlimit, 0 otherwise.
 proc check_effective_target_setrlimit {} {
     # Darwin has non-posix compliant RLIMIT_AS
@@ -10827,7 +10849,7 @@ proc check_vect_support_and_set_flags { } {
         } else {
             set dg-do-what-default link
         }
-    } elseif [istarget "aarch64*-*-*"] {
+    } elseif [istarget aarch64*-*-*] {
         set dg-do-what-default run
     } elseif [istarget s390*-*-*] {
 	# The S/390 backend set a default of 2 for that value.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gcc(refs/users/aoliva/heads/testme)] [testsuite] test for weak_undefined support and add options
@ 2023-03-23  3:48 Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-03-23  3:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:73ef333ba28558a34a86871b904965ec61229792

commit 73ef333ba28558a34a86871b904965ec61229792
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Thu Mar 23 00:45:05 2023 -0300

    [testsuite] test for weak_undefined support and add options
    
    A number of tests that depend on weak undefined symbols fail to
    require that support, and arrange to skip some targets and add special
    options to others on a test-by-test basis.  Fix this by stating the
    requirement explicitly, and adding a proc to return any required
    options.
    
    Others rely on weak undefined symbols only to test for the
    availability of posix_memalign.  Drop that in favor of dg effective
    target support for posix_memalign.
    
    
    for  gcc/testsuite/ChangeLog
    
            * lib/target-supports.exp (add_options_for_weak_undefined):
            New.
            (check_effective_target_weak_undefined): Use it.
            (check_effective_target_posix_memalign): New.
            * doc/sourcebuild.texi: Document them.
            * gcc.dg/torture/pr53922.c: Drop skips and custom options in
            favor of effective target requirement and added options for
            weak_undefined symbols.
            * gcc.dg/torture/pr90020.c: Likewise.
            * gcc.dg/addr_equal-1.c: Likewise.
            * gcc.target/aarch64/aapcs64/aapcs64.exp: Likewise, for
            abitest.S-using tests.
            * gcc.dg/torture/pr60092.c: Likewise, but in favor of
            posix_memalign tests.
            * gcc.dg/vect/vect-tail-nomask-1.c: Likewise.

Diff:
---
 gcc/doc/sourcebuild.texi                           |  9 +++++++
 gcc/testsuite/gcc.dg/addr_equal-1.c                |  5 ++--
 gcc/testsuite/gcc.dg/torture/pr53922.c             | 10 ++------
 gcc/testsuite/gcc.dg/torture/pr60092.c             | 12 ++--------
 gcc/testsuite/gcc.dg/torture/pr90020.c             |  7 ++----
 gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c     | 11 ++-------
 .../gcc.target/aarch64/aapcs64/aapcs64.exp         | 17 +++++++------
 gcc/testsuite/lib/target-supports.exp              | 28 +++++++++++++++++++---
 8 files changed, 54 insertions(+), 45 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 3c2ada68bb3..8f1c7b65d69 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2693,6 +2693,9 @@ Target supports Newlib.
 GCC was configured with @code{--enable-newlib-nano-formatted-io}, which reduces
 the code size of Newlib formatted I/O functions.
 
+@item posix_memalign
+Target supports @code{posix_memalign}.
+
 @item pow10
 Target provides @code{pow10} function.
 
@@ -2755,6 +2758,9 @@ Target is a VxWorks RTP.
 
 @item wchar
 Target supports wide characters.
+
+@item weak_undefined
+Target supports weak undefined symbols
 @end table
 
 @subsubsection Other attributes
@@ -3126,6 +3132,9 @@ instructions, if any.
 
 @item tls
 Add the target-specific flags needed to use thread-local storage.
+
+@item weak_undefined
+Add the flags needed to enable support for weak undefined symbols.
 @end table
 
 @node Require Support
diff --git a/gcc/testsuite/gcc.dg/addr_equal-1.c b/gcc/testsuite/gcc.dg/addr_equal-1.c
index 35fa0102e30..db65dea4a8d 100644
--- a/gcc/testsuite/gcc.dg/addr_equal-1.c
+++ b/gcc/testsuite/gcc.dg/addr_equal-1.c
@@ -1,9 +1,8 @@
-/* { dg-do run { target { nonpic || pie_enabled } } } */
-/* { dg-require-weak "" } */
+/* { dg-do run { target { { nonpic || pie_enabled } && weak_undefined } } } */
 /* { dg-require-alias "" } */
 /* { dg-options "-O2 -fdelete-null-pointer-checks" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
 /* { dg-skip-if "function pointers can be NULL" { keeps_null_pointer_checks } } */
+/* { dg-add-options weak_undefined } */
 void abort (void);
 extern int undef_var0, undef_var1;
 extern __attribute__ ((weak)) int weak_undef_var0;
diff --git a/gcc/testsuite/gcc.dg/torture/pr53922.c b/gcc/testsuite/gcc.dg/torture/pr53922.c
index b3f2c1a58f8..07359d67649 100644
--- a/gcc/testsuite/gcc.dg/torture/pr53922.c
+++ b/gcc/testsuite/gcc.dg/torture/pr53922.c
@@ -1,11 +1,5 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined" { *-*-mingw* } } */
-/* { dg-skip-if "No undefined weak" { *-*-aix* } } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 int x(int a)
 {
diff --git a/gcc/testsuite/gcc.dg/torture/pr60092.c b/gcc/testsuite/gcc.dg/torture/pr60092.c
index 74e7c174a83..102ba6e0d9f 100644
--- a/gcc/testsuite/gcc.dg/torture/pr60092.c
+++ b/gcc/testsuite/gcc.dg/torture/pr60092.c
@@ -1,12 +1,7 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { posix_memalign } } } */
 
 typedef __SIZE_TYPE__ size_t;
-extern int posix_memalign(void **memptr, size_t alignment, size_t size) __attribute__((weak));
+extern int posix_memalign(void **memptr, size_t alignment, size_t size);
 extern void abort(void);
 int
 main (void)
@@ -14,9 +9,6 @@ main (void)
   void *p;
   int ret;
 
-  if (!posix_memalign)
-    return 0;
-
   p = (void *)&ret;
   ret = posix_memalign (&p, sizeof (void *), -1);
   if (p != (void *)&ret)
diff --git a/gcc/testsuite/gcc.dg/torture/pr90020.c b/gcc/testsuite/gcc.dg/torture/pr90020.c
index 657c4ccfe45..40035aa758e 100644
--- a/gcc/testsuite/gcc.dg/torture/pr90020.c
+++ b/gcc/testsuite/gcc.dg/torture/pr90020.c
@@ -1,8 +1,5 @@
-/* { dg-do run } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* || powerpc-ibm-aix* } } */
-/* { dg-require-weak "" } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run  { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 void __attribute__((noinline,noclone))
 check (int i)
diff --git a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
index e5bbeaede09..ee9ab2e9d91 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
@@ -1,14 +1,10 @@
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-skip-if "No undefined weak" { ! { posix_memalign } } } */
 /* { dg-additional-options "--param vect-epilogues-nomask=1 -mavx2" { target avx2_runtime } } */
 
 #define SIZE 1023
 #define ALIGN 64
 
-extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size) __attribute__((weak));
+extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size);
 extern void free (void *);
 
 void __attribute__((noinline))
@@ -98,9 +94,6 @@ run_test ()
 int
 main (int argc, const char **argv)
 {
-  if (!posix_memalign)
-    return 0;
-
   run_test ();
   return 0;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
index 8cf9cc1e8e5..38a2c06a595 100644
--- a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
+++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
@@ -32,12 +32,15 @@ set additional_flags "-W -Wall -Wno-abi -fno-pie -no-pie"
 # Test parameter passing.  This uses abitest.S which relies on weak
 # symbols.
 
-if { [check_weak_available] } {
+set additional_flags_for_abitest [add_options_for_weak_undefined ""]
+set additional_flags_for_abitest "$additional_flags $additional_flags_for_abitest"
+
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/test_*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		$additional_flags_for_abitest
 	}
     }
 }
@@ -54,28 +57,28 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/rec_*.c]] {
 
 # Test unnamed argument retrieval via the va_arg macro.  This uses abitest.S
 # which relies on weak symbols.
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/va_arg-*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		$additional_flags_for_abitest
 	}
     }
 }
 
 # Test function return value.  This uses abitest.S which relies on
 # weak symbols.
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     #   Disable -fipa-ra to prevent the compiler from generating
     #   conflicting code.
-    set additional_flags_for_func_ret $additional_flags
+    set additional_flags_for_func_ret $additional_flags_for_abitest
     append additional_flags_for_func_ret " -fno-ipa-ra"
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/func-ret-*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags_for_func_ret
+		$additional_flags_for_func_ret
 	}
     }
 }
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index d7d3c2b6f9b..577c26e0ae2 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -356,6 +356,18 @@ proc check_weak_available { } {
     }
 }
 
+# return options to add to enable weak undefined symbols.
+
+proc add_options_for_weak_undefined { flags } {
+    if { [istarget *-*-darwin*] } {
+	lappend flags "-Wl,-undefined,dynamic_lookup"
+	if { [istarget *-*-darwin[89]*] } {
+	    lappend flags "-Wl,-flat_namespace"
+	}
+    }
+    return $flags
+}
+
 # return 1 if weak undefined symbols are supported.
 
 proc check_effective_target_weak_undefined { } {
@@ -365,7 +377,7 @@ proc check_effective_target_weak_undefined { } {
     return [check_runtime weak_undefined {
 	extern void foo () __attribute__((weak));
 	int main (void) { if (foo) return 1; return 0; }
-    } ""]
+    } [add_options_for_weak_undefined ""]]
 }
 
 ###############################
@@ -1154,6 +1166,16 @@ proc check_effective_target_clone {} {
     return [check_function_available "clone"]
 }
 
+# Return 1 if the target supports posix_memalign, 0 otherwise.
+proc check_effective_target_posix_memalign {} {
+    if { [istarget *-*-vxworks*] } {
+	# VxWorks doesn't have posix_memalign but our way to test
+	# can't tell as we're doing partial links for kernel modules.
+	return 0
+    }
+    return [check_function_available "posix_memalign"]
+}
+
 # Return 1 if the target supports setrlimit, 0 otherwise.
 proc check_effective_target_setrlimit {} {
     # Darwin has non-posix compliant RLIMIT_AS
@@ -2891,7 +2913,7 @@ proc check_fork_available {} {
 	# VxWorks doesn't have fork but our way to test can't
 	# tell as we're doing partial links for kernel modules.
 	return 0
-     }    
+    }
     if { [istarget cris-*-*] } {
 	# Compiling and linking works, and an executable running e.g.
 	# gcc.dg/torture/ftrapv-1.c works on now-historical hardware,
@@ -10839,7 +10861,7 @@ proc check_vect_support_and_set_flags { } {
         } else {
             set dg-do-what-default link
         }
-    } elseif [istarget "aarch64*-*-*"] {
+    } elseif [istarget aarch64*-*-*] {
         set dg-do-what-default run
     } elseif [istarget s390*-*-*] {
 	# The S/390 backend set a default of 2 for that value.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gcc(refs/users/aoliva/heads/testme)] [testsuite] test for weak_undefined support and add options
@ 2023-03-16 14:22 Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-03-16 14:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:27da714df0e185ad8fb49fab92348e46b438cc6c

commit 27da714df0e185ad8fb49fab92348e46b438cc6c
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Wed Mar 15 07:54:47 2023 -0300

    [testsuite] test for weak_undefined support and add options
    
    A number of tests that depend on weak undefined symbols fail to
    require that support, and arrange to skip some targets and add special
    options to others on a test-by-test basis.  Fix this by stating the
    requirement explicitly, and adding a proc to return any required
    options.
    
    Others rely on weak undefined symbols only to test for the
    availability of posix_memalign.  Drop that in favor of dg effective
    target support for posix_memalign.
    
    
    for  gcc/testsuite/ChangeLog
    
            * lib/target-supports.exp (add_options_for_weak_undefined):
            New.
            (check_effective_target_weak_undefined): Use it.
            (check_effective_target_posix_memalign): New.
            * gcc.dg/torture/pr53922.c: Drop skips and custom options in
            favor of effective target requirement and added options for
            weak_undefined symbols.
            * gcc.dg/torture/pr90020.c: Likewise.
            * gcc.dg/addr_equal-1.c: Likewise.
            * gcc.target/aarch64/aapcs64/aapcs64.exp: Likewise, for
            abitest.S-using tests.
            * gcc.dg/torture/pr60092.c: Likewise, but in favor of
            posix_memalign tests.
            * gcc.dg/vect/vect-tail-nomask-1.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/addr_equal-1.c                |  5 ++--
 gcc/testsuite/gcc.dg/torture/pr53922.c             | 10 ++------
 gcc/testsuite/gcc.dg/torture/pr60092.c             | 12 ++--------
 gcc/testsuite/gcc.dg/torture/pr90020.c             |  7 ++----
 gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c     | 11 ++-------
 .../gcc.target/aarch64/aapcs64/aapcs64.exp         | 17 +++++++------
 gcc/testsuite/lib/target-supports.exp              | 28 +++++++++++++++++++---
 7 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/addr_equal-1.c b/gcc/testsuite/gcc.dg/addr_equal-1.c
index 35fa0102e30..db65dea4a8d 100644
--- a/gcc/testsuite/gcc.dg/addr_equal-1.c
+++ b/gcc/testsuite/gcc.dg/addr_equal-1.c
@@ -1,9 +1,8 @@
-/* { dg-do run { target { nonpic || pie_enabled } } } */
-/* { dg-require-weak "" } */
+/* { dg-do run { target { { nonpic || pie_enabled } && weak_undefined } } } */
 /* { dg-require-alias "" } */
 /* { dg-options "-O2 -fdelete-null-pointer-checks" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
 /* { dg-skip-if "function pointers can be NULL" { keeps_null_pointer_checks } } */
+/* { dg-add-options weak_undefined } */
 void abort (void);
 extern int undef_var0, undef_var1;
 extern __attribute__ ((weak)) int weak_undef_var0;
diff --git a/gcc/testsuite/gcc.dg/torture/pr53922.c b/gcc/testsuite/gcc.dg/torture/pr53922.c
index b3f2c1a58f8..07359d67649 100644
--- a/gcc/testsuite/gcc.dg/torture/pr53922.c
+++ b/gcc/testsuite/gcc.dg/torture/pr53922.c
@@ -1,11 +1,5 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined" { *-*-mingw* } } */
-/* { dg-skip-if "No undefined weak" { *-*-aix* } } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 int x(int a)
 {
diff --git a/gcc/testsuite/gcc.dg/torture/pr60092.c b/gcc/testsuite/gcc.dg/torture/pr60092.c
index 74e7c174a83..102ba6e0d9f 100644
--- a/gcc/testsuite/gcc.dg/torture/pr60092.c
+++ b/gcc/testsuite/gcc.dg/torture/pr60092.c
@@ -1,12 +1,7 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { posix_memalign } } } */
 
 typedef __SIZE_TYPE__ size_t;
-extern int posix_memalign(void **memptr, size_t alignment, size_t size) __attribute__((weak));
+extern int posix_memalign(void **memptr, size_t alignment, size_t size);
 extern void abort(void);
 int
 main (void)
@@ -14,9 +9,6 @@ main (void)
   void *p;
   int ret;
 
-  if (!posix_memalign)
-    return 0;
-
   p = (void *)&ret;
   ret = posix_memalign (&p, sizeof (void *), -1);
   if (p != (void *)&ret)
diff --git a/gcc/testsuite/gcc.dg/torture/pr90020.c b/gcc/testsuite/gcc.dg/torture/pr90020.c
index 657c4ccfe45..40035aa758e 100644
--- a/gcc/testsuite/gcc.dg/torture/pr90020.c
+++ b/gcc/testsuite/gcc.dg/torture/pr90020.c
@@ -1,8 +1,5 @@
-/* { dg-do run } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* || powerpc-ibm-aix* } } */
-/* { dg-require-weak "" } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run  { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 void __attribute__((noinline,noclone))
 check (int i)
diff --git a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
index e5bbeaede09..ee9ab2e9d91 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
@@ -1,14 +1,10 @@
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-skip-if "No undefined weak" { ! { posix_memalign } } } */
 /* { dg-additional-options "--param vect-epilogues-nomask=1 -mavx2" { target avx2_runtime } } */
 
 #define SIZE 1023
 #define ALIGN 64
 
-extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size) __attribute__((weak));
+extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size);
 extern void free (void *);
 
 void __attribute__((noinline))
@@ -98,9 +94,6 @@ run_test ()
 int
 main (int argc, const char **argv)
 {
-  if (!posix_memalign)
-    return 0;
-
   run_test ();
   return 0;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
index 8cf9cc1e8e5..38a2c06a595 100644
--- a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
+++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
@@ -32,12 +32,15 @@ set additional_flags "-W -Wall -Wno-abi -fno-pie -no-pie"
 # Test parameter passing.  This uses abitest.S which relies on weak
 # symbols.
 
-if { [check_weak_available] } {
+set additional_flags_for_abitest [add_options_for_weak_undefined ""]
+set additional_flags_for_abitest "$additional_flags $additional_flags_for_abitest"
+
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/test_*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		$additional_flags_for_abitest
 	}
     }
 }
@@ -54,28 +57,28 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/rec_*.c]] {
 
 # Test unnamed argument retrieval via the va_arg macro.  This uses abitest.S
 # which relies on weak symbols.
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/va_arg-*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		$additional_flags_for_abitest
 	}
     }
 }
 
 # Test function return value.  This uses abitest.S which relies on
 # weak symbols.
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     #   Disable -fipa-ra to prevent the compiler from generating
     #   conflicting code.
-    set additional_flags_for_func_ret $additional_flags
+    set additional_flags_for_func_ret $additional_flags_for_abitest
     append additional_flags_for_func_ret " -fno-ipa-ra"
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/func-ret-*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags_for_func_ret
+		$additional_flags_for_func_ret
 	}
     }
 }
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index fcfe290d07d..2b31b19f0e9 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -356,6 +356,18 @@ proc check_weak_available { } {
     }
 }
 
+# return options to add to enable weak undefined symbols.
+
+proc add_options_for_weak_undefined { flags } {
+    if { [istarget *-*-darwin*] } {
+	lappend flags "-Wl,-undefined,dynamic_lookup"
+	if { [istarget *-*-darwin[89]*] } {
+	    lappend flags "-Wl,-flat_namespace"
+	}
+    }
+    return $flags
+}
+
 # return 1 if weak undefined symbols are supported.
 
 proc check_effective_target_weak_undefined { } {
@@ -365,7 +377,7 @@ proc check_effective_target_weak_undefined { } {
     return [check_runtime weak_undefined {
 	extern void foo () __attribute__((weak));
 	int main (void) { if (foo) return 1; return 0; }
-    } ""]
+    } [add_options_for_weak_undefined ""]]
 }
 
 ###############################
@@ -1154,6 +1166,16 @@ proc check_effective_target_clone {} {
     return [check_function_available "clone"]
 }
 
+# Return 1 if the target supports posix_memalign, 0 otherwise.
+proc check_effective_target_posix_memalign {} {
+    if { [istarget *-*-vxworks*] } {
+	# VxWorks doesn't have posix_memalign but our way to test
+	# can't tell as we're doing partial links for kernel modules.
+	return 0
+    }
+    return [check_function_available "posix_memalign"]
+}
+
 # Return 1 if the target supports setrlimit, 0 otherwise.
 proc check_effective_target_setrlimit {} {
     # Darwin has non-posix compliant RLIMIT_AS
@@ -2879,7 +2901,7 @@ proc check_fork_available {} {
 	# VxWorks doesn't have fork but our way to test can't
 	# tell as we're doing partial links for kernel modules.
 	return 0
-     }    
+    }
     if { [istarget cris-*-*] } {
 	# Compiling and linking works, and an executable running e.g.
 	# gcc.dg/torture/ftrapv-1.c works on now-historical hardware,
@@ -10827,7 +10849,7 @@ proc check_vect_support_and_set_flags { } {
         } else {
             set dg-do-what-default link
         }
-    } elseif [istarget "aarch64*-*-*"] {
+    } elseif [istarget aarch64*-*-*] {
         set dg-do-what-default run
     } elseif [istarget s390*-*-*] {
 	# The S/390 backend set a default of 2 for that value.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gcc(refs/users/aoliva/heads/testme)] [testsuite] test for weak_undefined support and add options
@ 2023-03-16  1:44 Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-03-16  1:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d96fef696c20c0741d420d7ecd111de174ec04e7

commit d96fef696c20c0741d420d7ecd111de174ec04e7
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Wed Mar 15 07:54:47 2023 -0300

    [testsuite] test for weak_undefined support and add options
    
    A number of tests that depend on weak undefined symbols fail to
    require that support, and arrange to skip some targets and add special
    options to others on a test-by-test basis.  Fix this by stating the
    requirement explicitly, and adding a proc to return any required
    options.
    
    Others rely on weak undefined symbols only to test for the
    availability of posix_memalign.  Drop that in favor of dg effective
    target support for posix_memalign.
    
    
    for  gcc/testsuite/ChangeLog
    
            * lib/target-supports.exp (add_options_for_weak_undefined):
            New.
            (check_effective_target_weak_undefined): Use it.
            (check_effective_target_posix_memalign): New.
            * gcc.dg/torture/pr53922.c: Drop skips and custom options in
            favor of effective target requirement and added options for
            weak_undefined symbols.
            * gcc.dg/torture/pr90020.c: Likewise.
            * gcc.dg/addr_equal-1.c: Likewise.
            * gcc.target/aarch64/aapcs64/aapcs64.exp: Likewise, for
            abitest.S-using tests.
            * gcc.dg/torture/pr60092.c: Likewise, but in favor of
            posix_memalign tests.
            * gcc.dg/vect/vect-tail-nomask-1.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/addr_equal-1.c                |  5 ++---
 gcc/testsuite/gcc.dg/torture/pr53922.c             | 10 ++-------
 gcc/testsuite/gcc.dg/torture/pr60092.c             | 12 ++--------
 gcc/testsuite/gcc.dg/torture/pr90020.c             |  7 ++----
 gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c     | 11 ++-------
 .../gcc.target/aarch64/aapcs64/aapcs64.exp         | 17 ++++++++------
 gcc/testsuite/lib/target-supports.exp              | 26 ++++++++++++++++++++--
 7 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/addr_equal-1.c b/gcc/testsuite/gcc.dg/addr_equal-1.c
index 35fa0102e30..db65dea4a8d 100644
--- a/gcc/testsuite/gcc.dg/addr_equal-1.c
+++ b/gcc/testsuite/gcc.dg/addr_equal-1.c
@@ -1,9 +1,8 @@
-/* { dg-do run { target { nonpic || pie_enabled } } } */
-/* { dg-require-weak "" } */
+/* { dg-do run { target { { nonpic || pie_enabled } && weak_undefined } } } */
 /* { dg-require-alias "" } */
 /* { dg-options "-O2 -fdelete-null-pointer-checks" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
 /* { dg-skip-if "function pointers can be NULL" { keeps_null_pointer_checks } } */
+/* { dg-add-options weak_undefined } */
 void abort (void);
 extern int undef_var0, undef_var1;
 extern __attribute__ ((weak)) int weak_undef_var0;
diff --git a/gcc/testsuite/gcc.dg/torture/pr53922.c b/gcc/testsuite/gcc.dg/torture/pr53922.c
index b3f2c1a58f8..07359d67649 100644
--- a/gcc/testsuite/gcc.dg/torture/pr53922.c
+++ b/gcc/testsuite/gcc.dg/torture/pr53922.c
@@ -1,11 +1,5 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined" { *-*-mingw* } } */
-/* { dg-skip-if "No undefined weak" { *-*-aix* } } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 int x(int a)
 {
diff --git a/gcc/testsuite/gcc.dg/torture/pr60092.c b/gcc/testsuite/gcc.dg/torture/pr60092.c
index 74e7c174a83..102ba6e0d9f 100644
--- a/gcc/testsuite/gcc.dg/torture/pr60092.c
+++ b/gcc/testsuite/gcc.dg/torture/pr60092.c
@@ -1,12 +1,7 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { posix_memalign } } } */
 
 typedef __SIZE_TYPE__ size_t;
-extern int posix_memalign(void **memptr, size_t alignment, size_t size) __attribute__((weak));
+extern int posix_memalign(void **memptr, size_t alignment, size_t size);
 extern void abort(void);
 int
 main (void)
@@ -14,9 +9,6 @@ main (void)
   void *p;
   int ret;
 
-  if (!posix_memalign)
-    return 0;
-
   p = (void *)&ret;
   ret = posix_memalign (&p, sizeof (void *), -1);
   if (p != (void *)&ret)
diff --git a/gcc/testsuite/gcc.dg/torture/pr90020.c b/gcc/testsuite/gcc.dg/torture/pr90020.c
index 657c4ccfe45..40035aa758e 100644
--- a/gcc/testsuite/gcc.dg/torture/pr90020.c
+++ b/gcc/testsuite/gcc.dg/torture/pr90020.c
@@ -1,8 +1,5 @@
-/* { dg-do run } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* || powerpc-ibm-aix* } } */
-/* { dg-require-weak "" } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run  { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 void __attribute__((noinline,noclone))
 check (int i)
diff --git a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
index e5bbeaede09..ee9ab2e9d91 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
@@ -1,14 +1,10 @@
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-skip-if "No undefined weak" { ! { posix_memalign } } } */
 /* { dg-additional-options "--param vect-epilogues-nomask=1 -mavx2" { target avx2_runtime } } */
 
 #define SIZE 1023
 #define ALIGN 64
 
-extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size) __attribute__((weak));
+extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size);
 extern void free (void *);
 
 void __attribute__((noinline))
@@ -98,9 +94,6 @@ run_test ()
 int
 main (int argc, const char **argv)
 {
-  if (!posix_memalign)
-    return 0;
-
   run_test ();
   return 0;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
index 8cf9cc1e8e5..38a2c06a595 100644
--- a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
+++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
@@ -32,12 +32,15 @@ set additional_flags "-W -Wall -Wno-abi -fno-pie -no-pie"
 # Test parameter passing.  This uses abitest.S which relies on weak
 # symbols.
 
-if { [check_weak_available] } {
+set additional_flags_for_abitest [add_options_for_weak_undefined ""]
+set additional_flags_for_abitest "$additional_flags $additional_flags_for_abitest"
+
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/test_*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		$additional_flags_for_abitest
 	}
     }
 }
@@ -54,28 +57,28 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/rec_*.c]] {
 
 # Test unnamed argument retrieval via the va_arg macro.  This uses abitest.S
 # which relies on weak symbols.
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/va_arg-*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		$additional_flags_for_abitest
 	}
     }
 }
 
 # Test function return value.  This uses abitest.S which relies on
 # weak symbols.
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     #   Disable -fipa-ra to prevent the compiler from generating
     #   conflicting code.
-    set additional_flags_for_func_ret $additional_flags
+    set additional_flags_for_func_ret $additional_flags_for_abitest
     append additional_flags_for_func_ret " -fno-ipa-ra"
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/func-ret-*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags_for_func_ret
+		$additional_flags_for_func_ret
 	}
     }
 }
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index fcfe290d07d..ac6f000afd1 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -356,6 +356,18 @@ proc check_weak_available { } {
     }
 }
 
+# return options to add to enable weak undefined symbols.
+
+proc add_options_for_weak_undefined { flags } {
+    if { [istarget *-*-darwin*] } {
+	lappend flags "-Wl,-undefined,dynamic_lookup"
+	if { [istarget *-*-darwin[89]*] } {
+	    lappend flags "-Wl,-flat_namespace"
+	}
+    }
+    return $flags
+}
+
 # return 1 if weak undefined symbols are supported.
 
 proc check_effective_target_weak_undefined { } {
@@ -365,7 +377,7 @@ proc check_effective_target_weak_undefined { } {
     return [check_runtime weak_undefined {
 	extern void foo () __attribute__((weak));
 	int main (void) { if (foo) return 1; return 0; }
-    } ""]
+    } [add_options_for_weak_undefined ""]]
 }
 
 ###############################
@@ -1154,6 +1166,16 @@ proc check_effective_target_clone {} {
     return [check_function_available "clone"]
 }
 
+# Return 1 if the target supports posix_memalign, 0 otherwise.
+proc check_effective_target_posix_memalign {} {
+    if { [istarget *-*-vxworks*] } {
+	# VxWorks doesn't have posix_memalign but our way to test
+	# can't tell as we're doing partial links for kernel modules.
+	return 0
+     }    
+    return [check_function_available "posix_memalign"]
+}
+
 # Return 1 if the target supports setrlimit, 0 otherwise.
 proc check_effective_target_setrlimit {} {
     # Darwin has non-posix compliant RLIMIT_AS
@@ -10827,7 +10849,7 @@ proc check_vect_support_and_set_flags { } {
         } else {
             set dg-do-what-default link
         }
-    } elseif [istarget "aarch64*-*-*"] {
+    } elseif [istarget aarch64*-*-*] {
         set dg-do-what-default run
     } elseif [istarget s390*-*-*] {
 	# The S/390 backend set a default of 2 for that value.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gcc(refs/users/aoliva/heads/testme)] [testsuite] test for weak_undefined support and add options
@ 2023-03-15 23:30 Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-03-15 23:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9afce77154c9c5ad40c39ba2deab8bd5ab9911d8

commit 9afce77154c9c5ad40c39ba2deab8bd5ab9911d8
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Wed Mar 15 07:54:47 2023 -0300

    [testsuite] test for weak_undefined support and add options
    
    A number of tests that depend on weak undefined symbols fail to
    require that support, and arrange to skip some targets and add special
    options to others on a test-by-test basis.  Fix this by stating the
    requirement explicitly, and adding a proc to return any required
    options.
    
    Others rely on weak undefined symbols only to test for the
    availability of posix_memalign.  Drop that in favor of dg effective
    target support for posix_memalign.
    
    
    for  gcc/testsuite/ChangeLog
    
            * lib/target-supports.exp (add_options_for_weak_undefined):
            New.
            (check_effective_target_weak_undefined): Use it.
            (check_effective_target_posix_memalign): New.
            * gcc.dg/torture/pr53922.c: Drop skips and custom options in
            favor of effective target requirement and added options for
            weak_undefined symbols.
            * gcc.dg/torture/pr90020.c: Likewise.
            * gcc.dg/addr_equal-1.c: Likewise.
            * gcc.target/aarch64/aapcs64/aapcs64.exp: Likewise, for
            abitest.S-using tests.
            * gcc.dg/torture/pr60092.c: Likewise, but in favor of
            posix_memalign tests.
            * gcc.dg/vect/vect-tail-nomask-1.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/addr_equal-1.c                |  5 ++---
 gcc/testsuite/gcc.dg/torture/pr53922.c             | 10 ++-------
 gcc/testsuite/gcc.dg/torture/pr60092.c             | 12 ++--------
 gcc/testsuite/gcc.dg/torture/pr90020.c             |  7 ++----
 gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c     | 11 ++-------
 .../gcc.target/aarch64/aapcs64/aapcs64.exp         | 17 ++++++++------
 gcc/testsuite/lib/target-supports.exp              | 26 ++++++++++++++++++++--
 7 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/addr_equal-1.c b/gcc/testsuite/gcc.dg/addr_equal-1.c
index 35fa0102e30..db65dea4a8d 100644
--- a/gcc/testsuite/gcc.dg/addr_equal-1.c
+++ b/gcc/testsuite/gcc.dg/addr_equal-1.c
@@ -1,9 +1,8 @@
-/* { dg-do run { target { nonpic || pie_enabled } } } */
-/* { dg-require-weak "" } */
+/* { dg-do run { target { { nonpic || pie_enabled } && weak_undefined } } } */
 /* { dg-require-alias "" } */
 /* { dg-options "-O2 -fdelete-null-pointer-checks" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
 /* { dg-skip-if "function pointers can be NULL" { keeps_null_pointer_checks } } */
+/* { dg-add-options weak_undefined } */
 void abort (void);
 extern int undef_var0, undef_var1;
 extern __attribute__ ((weak)) int weak_undef_var0;
diff --git a/gcc/testsuite/gcc.dg/torture/pr53922.c b/gcc/testsuite/gcc.dg/torture/pr53922.c
index b3f2c1a58f8..07359d67649 100644
--- a/gcc/testsuite/gcc.dg/torture/pr53922.c
+++ b/gcc/testsuite/gcc.dg/torture/pr53922.c
@@ -1,11 +1,5 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined" { *-*-mingw* } } */
-/* { dg-skip-if "No undefined weak" { *-*-aix* } } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 int x(int a)
 {
diff --git a/gcc/testsuite/gcc.dg/torture/pr60092.c b/gcc/testsuite/gcc.dg/torture/pr60092.c
index 74e7c174a83..102ba6e0d9f 100644
--- a/gcc/testsuite/gcc.dg/torture/pr60092.c
+++ b/gcc/testsuite/gcc.dg/torture/pr60092.c
@@ -1,12 +1,7 @@
-/* { dg-do run } */
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run { target { posix_memalign } } } */
 
 typedef __SIZE_TYPE__ size_t;
-extern int posix_memalign(void **memptr, size_t alignment, size_t size) __attribute__((weak));
+extern int posix_memalign(void **memptr, size_t alignment, size_t size);
 extern void abort(void);
 int
 main (void)
@@ -14,9 +9,6 @@ main (void)
   void *p;
   int ret;
 
-  if (!posix_memalign)
-    return 0;
-
   p = (void *)&ret;
   ret = posix_memalign (&p, sizeof (void *), -1);
   if (p != (void *)&ret)
diff --git a/gcc/testsuite/gcc.dg/torture/pr90020.c b/gcc/testsuite/gcc.dg/torture/pr90020.c
index 657c4ccfe45..40035aa758e 100644
--- a/gcc/testsuite/gcc.dg/torture/pr90020.c
+++ b/gcc/testsuite/gcc.dg/torture/pr90020.c
@@ -1,8 +1,5 @@
-/* { dg-do run } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* || powerpc-ibm-aix* } } */
-/* { dg-require-weak "" } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-do run  { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
 
 void __attribute__((noinline,noclone))
 check (int i)
diff --git a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
index e5bbeaede09..ee9ab2e9d91 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-tail-nomask-1.c
@@ -1,14 +1,10 @@
-/* { dg-require-weak "" } */
-/* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
-/* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
-/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
-/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
+/* { dg-skip-if "No undefined weak" { ! { posix_memalign } } } */
 /* { dg-additional-options "--param vect-epilogues-nomask=1 -mavx2" { target avx2_runtime } } */
 
 #define SIZE 1023
 #define ALIGN 64
 
-extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size) __attribute__((weak));
+extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size);
 extern void free (void *);
 
 void __attribute__((noinline))
@@ -98,9 +94,6 @@ run_test ()
 int
 main (int argc, const char **argv)
 {
-  if (!posix_memalign)
-    return 0;
-
   run_test ();
   return 0;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
index 8cf9cc1e8e5..ef3799fdee3 100644
--- a/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
+++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp
@@ -32,12 +32,15 @@ set additional_flags "-W -Wall -Wno-abi -fno-pie -no-pie"
 # Test parameter passing.  This uses abitest.S which relies on weak
 # symbols.
 
-if { [check_weak_available] } {
+set additional_flags_for_abitest $additional_flags
+lappend additional_flags_for_abitest [add_options_for_weak_undefined ""]
+
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/test_*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		$additional_flags_for_abitest
 	}
     }
 }
@@ -54,28 +57,28 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/rec_*.c]] {
 
 # Test unnamed argument retrieval via the va_arg macro.  This uses abitest.S
 # which relies on weak symbols.
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/va_arg-*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags
+		$additional_flags_for_abitest
 	}
     }
 }
 
 # Test function return value.  This uses abitest.S which relies on
 # weak symbols.
-if { [check_weak_available] } {
+if { [check_effective_target_weak_undefined] } {
     #   Disable -fipa-ra to prevent the compiler from generating
     #   conflicting code.
-    set additional_flags_for_func_ret $additional_flags
+    set additional_flags_for_func_ret $additional_flags_for_abitest
     append additional_flags_for_func_ret " -fno-ipa-ra"
     foreach src [lsort [glob -nocomplain $srcdir/$subdir/func-ret-*.c]] {
 	if {[runtest_file_p $runtests $src]} {
 	    c-torture-execute [list $src \
 				    $srcdir/$subdir/abitest.S] \
-				    $additional_flags_for_func_ret
+		$additional_flags_for_func_ret
 	}
     }
 }
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index fcfe290d07d..ac6f000afd1 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -356,6 +356,18 @@ proc check_weak_available { } {
     }
 }
 
+# return options to add to enable weak undefined symbols.
+
+proc add_options_for_weak_undefined { flags } {
+    if { [istarget *-*-darwin*] } {
+	lappend flags "-Wl,-undefined,dynamic_lookup"
+	if { [istarget *-*-darwin[89]*] } {
+	    lappend flags "-Wl,-flat_namespace"
+	}
+    }
+    return $flags
+}
+
 # return 1 if weak undefined symbols are supported.
 
 proc check_effective_target_weak_undefined { } {
@@ -365,7 +377,7 @@ proc check_effective_target_weak_undefined { } {
     return [check_runtime weak_undefined {
 	extern void foo () __attribute__((weak));
 	int main (void) { if (foo) return 1; return 0; }
-    } ""]
+    } [add_options_for_weak_undefined ""]]
 }
 
 ###############################
@@ -1154,6 +1166,16 @@ proc check_effective_target_clone {} {
     return [check_function_available "clone"]
 }
 
+# Return 1 if the target supports posix_memalign, 0 otherwise.
+proc check_effective_target_posix_memalign {} {
+    if { [istarget *-*-vxworks*] } {
+	# VxWorks doesn't have posix_memalign but our way to test
+	# can't tell as we're doing partial links for kernel modules.
+	return 0
+     }    
+    return [check_function_available "posix_memalign"]
+}
+
 # Return 1 if the target supports setrlimit, 0 otherwise.
 proc check_effective_target_setrlimit {} {
     # Darwin has non-posix compliant RLIMIT_AS
@@ -10827,7 +10849,7 @@ proc check_vect_support_and_set_flags { } {
         } else {
             set dg-do-what-default link
         }
-    } elseif [istarget "aarch64*-*-*"] {
+    } elseif [istarget aarch64*-*-*] {
         set dg-do-what-default run
     } elseif [istarget s390*-*-*] {
 	# The S/390 backend set a default of 2 for that value.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-23  3:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 14:06 [gcc(refs/users/aoliva/heads/testme)] [testsuite] test for weak_undefined support and add options Alexandre Oliva
2023-03-15 23:30 Alexandre Oliva
2023-03-16  1:44 Alexandre Oliva
2023-03-16 14:22 Alexandre Oliva
2023-03-23  3:48 Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).