[binutils-gdb] gdb.base/nodebug.exp: Add long double testing

Pedro Alves via Gdb-cvs <[email protected]> Wed, 22 Jul 2026 13:00:57 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da22497eb1e18=
534c9989054537defb15e2424f95

commit a22497eb1e18534c9989054537defb15e2424f95
Author: Pedro Alves <[email protected]>
Date:   Tue Jul 14 00:34:43 2026 +0100

    gdb.base/nodebug.exp: Add long double testing
   =20
    gdb.base/nodebug.exp is missing testing calling long double functions.
    This commit adds such tests.
   =20
    With a GDB that doesn't know that "long double" is 64-bit on
    x86_64-pc-windows-msvc, we get:
   =20
     FAIL: gdb.base/nodebug.exp: p (long double) mult_long_double(2.0L, 3.0=
L)
     FAIL: gdb.base/nodebug.exp: p ((long double (*) (long double, long dou=
ble)) mult_long_double)(2.0L, 3.0L)
     FAIL: gdb.base/nodebug.exp: p ((long double (*) (long double, long dou=
ble)) mult_long_double)(2, 3)
     FAIL: gdb.base/nodebug.exp: p ((long double (*) ()) mult_long_double_n=
oproto)(2.0L, 3.0L)
   =20
    Passes cleanly on:
   =20
     - x86_64-pc-linux-gnu
     - x86_64-w64-mingw32
     - x86_64-pc-windows-msvc, with the "long double" fix
   =20
    Change-Id: If9ee749187e1d30fedcba17ae12634f3bd90de2f

Diff:
---
 gdb/testsuite/gdb.base/nodebug.c   | 13 +++++++++++++
 gdb/testsuite/gdb.base/nodebug.exp | 21 ++++++++++++++++-----
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.base/nodebug.c b/gdb/testsuite/gdb.base/node=
bug.c
index c7bc93991b8..00e854844bf 100644
--- a/gdb/testsuite/gdb.base/nodebug.c
+++ b/gdb/testsuite/gdb.base/nodebug.c
@@ -79,6 +79,19 @@ mult_noproto (v1, v2)
   return v1 * v2;
 }
=20
+long double
+mult_long_double (long double v1, long double v2)
+{
+  return v1 * v2;
+}
+
+long double
+mult_long_double_noproto (v1, v2)
+  long double v1, v2;
+{
+  return v1 * v2;
+}
+
 uint8_t
 add8 (uint8_t v1, uint8_t v2)
 {
diff --git a/gdb/testsuite/gdb.base/nodebug.exp b/gdb/testsuite/gdb.base/no=
debug.exp
index 9cdff5d5560..76de3b82f97 100644
--- a/gdb/testsuite/gdb.base/nodebug.exp
+++ b/gdb/testsuite/gdb.base/nodebug.exp
@@ -60,8 +60,8 @@ proc nodebug_runto {func} {
 }
=20
 # Test calling no-debug functions involving argument types that may
-# require coercion/promotion, both prototyped and unprototyped, both
-# return-type-cast style, and function-pointer-cast styles.
+# require coercion or promotion, both prototyped and unprototyped,
+# both return-type-cast style, and function-pointer-cast styles.
 proc test_call_promotion {} {
     if {[target_info exists gdb,cannot_call_functions]} {
 	return
@@ -69,14 +69,15 @@ proc test_call_promotion {} {
=20
     # Call prototyped function with float parameters via both
     # return-type cast and function-pointer cast.  This checks that
-    # GDB doesn't do float->double coercion.
+    # GDB doesn't do float->double promotion.
     gdb_test "p (float) multf(2.0f, 3.0f)" " =3D 6"
-    gdb_test "p ((float (*) (float, float)) multf)(2, 3)" " =3D 6"
     gdb_test "p ((float (*) (float, float)) multf)(2.0f, 3.0f)" " =3D 6"
+    # This tests int->float coercion.
+    gdb_test "p ((float (*) (float, float)) multf)(2, 3)" " =3D 6"
=20
     # Call unprototyped function with float parameters via
     # function-pointer cast, only.  return-type cast assumes
-    # protototyped.  Check that GDB does float->double coercion.
+    # prototyped.  Check that GDB does float->double promotion.
     gdb_test "p ((float (*) ()) multf_noproto)(2.0f, 3.0f)" " =3D 6"
     gdb_test "p ((float (*) ()) multf_noproto)(2.0, 3.0)" " =3D 6"
=20
@@ -87,6 +88,16 @@ proc test_call_promotion {} {
     gdb_test "p ((double (*) ()) mult_noproto)(2.0f, 3.0f)" " =3D 6"
     gdb_test "p ((double (*) ()) mult_noproto)(2.0, 3.0)" " =3D 6"
=20
+    # Same, but for long double.
+    gdb_test "p (long double) mult_long_double(2.0L, 3.0L)" " =3D 6"
+    gdb_test "p ((long double (*) (long double, long double)) mult_long_do=
uble)(2.0L, 3.0L)" " =3D 6"
+    gdb_test "p ((long double (*) (long double, long double)) mult_long_do=
uble)(2, 3)" " =3D 6"
+    # For unprototyped calls, the standard C default argument
+    # promotion (for floating point) applies only to float and
+    # promotes to double, so test only with the expected type, using
+    # L-suffixed literals to pass long doubles.
+    gdb_test "p ((long double (*) ()) mult_long_double_noproto)(2.0L, 3.0L=
)" " =3D 6"
+
     # Check that GDB promotes char->int correctly.
     gdb_test "p /d (uint8) add8((uint8) 2, (uint8) 3)" " =3D 5"
     gdb_test "p /d ((uint8 (*) (uint8, uint8)) add8)((uint8) 2, (uint8) 3)=
" " =3D 5"