[PATCH,testsuite] fix darwin-longlong.c for 32-bit simulator targets

Nathan Froyd froydnj@codesourcery.com
Mon Jan 12 21:39:00 GMT 2009


gcc.target/powerpc/darwin-longlong.c uses SIGILL to determine whether
the target has 64-bit instruction support.  However, newlib lets
applications that use signal() link successfully, but the registered
signal handler doesn't actually get invoked.  Therefore, it's better to
use a dg-require-effective-target test rather than a runtime check.

Tested on powerpc-none-eabi.  OK to commit?

-Nathan

2009-01-12  Daniel Jacobowitz  <dan@codesourcery.com>

	* lib/target-supports.exp (check_effective_target_ppc64): New.
	* gcc.target/powerpc/darwin-longlong.c: Explicitly require 64-bit
	instruction support.  Do not check for it at runtime.

Index: gcc.target/powerpc/darwin-longlong.c
===================================================================
--- gcc.target/powerpc/darwin-longlong.c	(revision 143306)
+++ gcc.target/powerpc/darwin-longlong.c	(working copy)
@@ -1,17 +1,9 @@
 /* { dg-do run { target powerpc*-*-* } } */
-/* { dg-xfail-if "" { "powerpc-*-eabispe*" "powerpc-ibm-aix*" } { "*" } { "" } } */
+/* { dg-require-effective-target ppc64 } */
 /* { dg-options "-mcpu=G5" } */
 
-#include <signal.h>
 #include <stdlib.h>
 
-void
-sig_ill_handler (int sig)
-{
-    exit(0);
-}
-
-
 int  msw(long long in)
 {
   union {
@@ -24,16 +16,6 @@ int  msw(long long in)
 
 int main()
 {
-
-  /* Exit on systems without 64bit instructions.  */
-  signal (SIGILL, sig_ill_handler);
-#ifdef __MACH__
-  asm volatile ("extsw r0,r0");
-#else
-  asm volatile ("extsw 0,0");
-#endif
-  signal (SIGILL, SIG_DFL);
-
   if (msw(1) != 0)
     abort();
   exit(0);
Index: lib/target-supports.exp
===================================================================
--- lib/target-supports.exp	(revision 143306)
+++ lib/target-supports.exp	(working copy)
@@ -905,6 +905,65 @@ proc check_vmx_hw_available { } {
     }]
 }
 
+# Return 1 if the target supports executing 64-bit instructions, 0
+# otherwise.  Cache the result.
+
+proc check_effective_target_ppc64 { } {
+    global ppc64_available_saved
+    global tool
+
+    if [info exists ppc64_available_saved] {
+	verbose "check_effective_target_ppc64 returning saved $ppc64_available_saved" 2
+    } else {
+	set ppc64_available_saved 0
+
+	# Some simulators are known to not support VMX instructions.
+	if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
+	    verbose "check_effective_target_ppc64 returning 0" 2
+	    return $ppc64_available_saved
+	}
+
+	# Set up, compile, and execute a test program containing a 64-bit
+	# instruction.  Include the current process ID in the file
+	# names to prevent conflicts with invocations for multiple
+	# testsuites.
+	set src ppc[pid].c
+	set exe ppc[pid].x
+
+	set f [open $src "w"]
+	puts $f "int main() {"
+	puts $f "#ifdef __MACH__"
+	puts $f "  asm volatile (\"extsw r0,r0\");"
+	puts $f "#else"
+	puts $f "  asm volatile (\"extsw 0,0\");"
+	puts $f "#endif"
+	puts $f "  return 0; }"
+	close $f
+
+	set opts "additional_flags=-mcpu=G5"
+
+	verbose "check_effective_target_ppc64 compiling testfile $src" 2
+	set lines [${tool}_target_compile $src $exe executable "$opts"]
+	file delete $src
+
+	if [string match "" $lines] then {
+	    # No error message, compilation succeeded.
+	    set result [${tool}_load "./$exe" "" ""]
+	    set status [lindex $result 0]
+	    remote_file build delete $exe
+	    verbose "check_effective_target_ppc64 testfile status is <$status>" 2
+
+	    if { $status == "pass" } then {
+		set ppc64_available_saved 1
+	    }
+	} else {
+	    verbose "check_effective_target_ppc64 testfile compilation failed" 2
+	}
+    }
+
+    return $ppc64_available_saved
+}
+
 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
 # complex float arguments.  This affects gfortran tests that call cabsf
 # in libm built by an earlier compiler.  Return 1 if libm uses the same



More information about the Gcc-patches mailing list