[gdb/testsuite] Introduce supports_scalar_storage_order_attribute
authorTom de Vries <tdevries@suse.de>
Sat, 19 Dec 2020 15:43:17 +0000 (16:43 +0100)
committerTom de Vries <tdevries@suse.de>
Sat, 19 Dec 2020 15:43:17 +0000 (16:43 +0100)
Introduce support test procs:
- supports_scalar_storage_order_attribute, and
- supports_gnuc
and use them in test-case gdb.base/endianity.exp.

Tested on x86_64-linux with gcc-7.5.0, gcc-4.8.5, and clang 10.0.1.

gdb/testsuite/ChangeLog:

2020-12-19  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (supports_scalar_storage_order_attribute)
(supports_gnuc): New proc.
* gdb.base/endianity.exp: Define TEST_SSO.  Eliminate
test_compiler_info calls.  Add unsupported message.
* gdb.base/endianity.c: Use TEST_SSO.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/endianity.c
gdb/testsuite/gdb.base/endianity.exp
gdb/testsuite/lib/gdb.exp

index 5b504526560dece92a0196babd8dc6612d17599a..8bcc735b1ceb458d24de135fdfbd165084bb7668 100644 (file)
@@ -1,3 +1,11 @@
+2020-12-19  Tom de Vries  <tdevries@suse.de>
+
+       * lib/gdb.exp (supports_scalar_storage_order_attribute)
+       (supports_gnuc): New proc.
+       * gdb.base/endianity.exp: Define TEST_SSO.  Eliminate
+       test_compiler_info calls.  Add unsupported message.
+       * gdb.base/endianity.c: Use TEST_SSO.
+
 2020-12-19  Hannes Domani  <ssbssa@yahoo.de>
 
        PR exp/27070
index ef3b6d4fdb20b776e9686a32f33a49e3461ba431..15cbdd9a26555db8a642ced9550b8c8c565f3a80 100644 (file)
@@ -26,7 +26,7 @@ struct otherendian
   __complex__ float cplx;
   double d;
 }
-#if defined __GNUC__ && (__GNUC__ >= 6)
+#if TEST_SSO
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 __attribute__( ( scalar_storage_order( "big-endian" ) ) )
 #else
index 4520799d04e72f8fcfc1ac343833eaaae39f9353..d54c1b6973aaae95518195864daffbf3b05eafa4 100644 (file)
 
 standard_testfile .c
 
-if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+set test_sso [expr \
+                 [supports_scalar_storage_order_attribute] \
+                 && [supports_gnuc]]
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
+         [list debug additional_flags=-DTEST_SSO=$test_sso]] } {
   return -1
 }
 
@@ -37,12 +42,12 @@ gdb_test "print o.d = -23.125" "= -23.125"
 gdb_test "print o" "= {v = 4, w = 3, x = 2, f = 1.5, cplx = 1.25 \\+ 7.25i, d = -23.125}" \
     "print o after assignment"
 
-if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
+if { !$test_sso } {
     # The rest of the testcase requires Scalar Storage Order support.
     # This compiler does not support it, so skip the rest.
+    unsupported "No scalar storage order support"
     return -1
 }
 
 gdb_test "x/x &o.v" "0x04000000"
 gdb_test "x/xh &o.w" "0x0300"
-
index e812237d67ae1d5c58a864a42df1c1c6f5fa53d9..e91023093e1412934e360266be0ec7b0b8173be3 100644 (file)
@@ -7669,5 +7669,51 @@ gdb_caching_proc have_fuse_ld_gold {
     return [gdb_simple_compile $me $src executable $flags]
 }
 
+# Return 1 if compiler supports scalar_storage_order attribute, otherwise
+# return 0.
+gdb_caching_proc supports_scalar_storage_order_attribute {
+    set me "supports_scalar_storage_order_attribute"
+    set src {
+       #include <string.h>
+       struct sle {
+           int v;
+       } __attribute__((scalar_storage_order("little-endian")));
+       struct sbe {
+           int v;
+       } __attribute__((scalar_storage_order("big-endian")));
+       struct sle sle;
+       struct sbe sbe;
+       int main () {
+           sle.v = sbe.v = 0x11223344;
+           int same = memcmp (&sle, &sbe, sizeof (int)) == 0;
+           int sso = !same;
+           return sso;
+       }
+    }
+    if { ![gdb_simple_compile $me $src executable ""] } {
+       return 0
+    }
+
+    set result [remote_exec target $obj]
+    set status [lindex $result 0]
+    set output [lindex $result 1]
+    if { $output != "" } {
+       return 0
+    }
+
+    return $status
+}
+
+# Return 1 if compiler supports __GNUC__, otherwise return 0.
+gdb_caching_proc supports_gnuc {
+    set me "supports_gnuc"
+    set src {
+       #ifndef __GNUC__
+       #error "No gnuc"
+       #endif
+    }
+    return [gdb_simple_compile $me $src object ""]
+}
+
 # Always load compatibility stuff.
 load_lib future.exp