gdb/fortran: Use floatformats_ia64_quad for fortran 16-byte floats
authorAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 3 May 2019 14:23:55 +0000 (15:23 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Sat, 18 May 2019 08:49:02 +0000 (09:49 +0100)
PR gdb/18644 is caused by GDB using the wrong floating point format
for gfortran's 16-byte floating point type, including when the 16-byte
float is used as the component of a 32-byte complex type.

This commit addresses the issue in two places, first in i386-tdep.c,
there is already some code to force the use of floatformats_ia64_quad
for specific named types, this is extended to include the type names
that gfortran uses for its 16-byte floats.

Second, the builtin 16-byte float type (in f-lang.c) is changed so it
no longer uses gdbarch_long_double_format.  On i386 this type is not
16-bytes, but is smaller, this is not what gfortran is expecting.
Instead we now use gdbarch_floatformat_for_type and ask for a
16-byte (128 bit) type using the common gfortran type name.  This is
then spotted in i386-tdep.c (thanks to the first change above) and we
again get floatformats_ia64_quad returned.

This patch was tested on X86-64/GNU-Linux using '--target_board=unix'
and '--target_board=unix/-m32', and resolves all of the known failures
associated with PR gdb/18644.  I've also added the test case from the
original bug report.

gdb/ChangeLog:

PR gdb/18644:
* f-lang.c (build_fortran_types): Use floatformats_ia64_quad for
16-byte floats.
* i386-tdep.c (i386_floatformat_for_type): Use
floatformats_ia64_quad for the 16-byte floating point component
within a fortran 32-byte complex number.

gdb/testsuite/ChangeLog:

PR gdb/18644
* gdb.fortran/complex.exp: Remove setup_kfail calls.
* gdb.fortran/printing-types.exp: Add new test.
* gdb.fortran/printing-types.f90: Add 16-byte real variable for
testing.
* gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): Remove
setup_kfail call.

gdb/ChangeLog
gdb/f-lang.c
gdb/i386-tdep.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/complex.exp
gdb/testsuite/gdb.fortran/printing-types.exp
gdb/testsuite/gdb.fortran/printing-types.f90
gdb/testsuite/gdb.fortran/type-kinds.exp

index 871e3dc661b1385ee357a3ce2f3e413a22e4d391..51e946f70209b969578473ae4c4d418693e64b96 100644 (file)
@@ -1,3 +1,12 @@
+2019-05-18  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       PR gdb/18644:
+       * f-lang.c (build_fortran_types): Use floatformats_ia64_quad for
+       16-byte floats.
+       * i386-tdep.c (i386_floatformat_for_type): Use
+       floatformats_ia64_quad for the 16-byte floating point component
+       within a fortran 32-byte complex number.
+
 2019-05-18  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * dwarf2read.c (struct cu_partial_die_info): Add constructor,
index 9da6fdb3e1c35744ac9dc6fc48f84b2ca769a1ad..5855c68b38c632d566bf42bd65c4002964223349 100644 (file)
@@ -727,9 +727,9 @@ build_fortran_types (struct gdbarch *gdbarch)
   builtin_f_type->builtin_real_s8
     = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
                       "real*8", gdbarch_double_format (gdbarch));
+  auto fmt = gdbarch_floatformat_for_type (gdbarch, "real(kind=16)", 128);
   builtin_f_type->builtin_real_s16
-    = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
-                      "real*16", gdbarch_long_double_format (gdbarch));
+    = arch_float_type (gdbarch, 128, "real*16", fmt);
 
   builtin_f_type->builtin_complex_s8
     = arch_complex_type (gdbarch, "complex*8",
index 8990583d8721427d51098fb1b9b347b1af73ea1e..c542edf28adbe65b364ed6b651ed57a4fbbb3b30 100644 (file)
@@ -8158,7 +8158,9 @@ i386_floatformat_for_type (struct gdbarch *gdbarch,
   if (len == 128 && name)
     if (strcmp (name, "__float128") == 0
        || strcmp (name, "_Float128") == 0
-       || strcmp (name, "complex _Float128") == 0)
+       || strcmp (name, "complex _Float128") == 0
+       || strcmp (name, "complex(kind=16)") == 0
+       || strcmp (name, "real(kind=16)") == 0)
       return floatformats_ia64_quad;
 
   return default_floatformat_for_type (gdbarch, name, len);
index 186b13e3d6afc0ec3d50da1312196846a43e1746..5cfad2754e6473aada84549c720975f245bb0217 100644 (file)
@@ -1,3 +1,13 @@
+2019-05-18  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       PR gdb/18644
+       * gdb.fortran/complex.exp: Remove setup_kfail calls.
+       * gdb.fortran/printing-types.exp: Add new test.
+       * gdb.fortran/printing-types.f90: Add 16-byte real variable for
+       testing.
+       * gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): Remove
+       setup_kfail call.
+
 2019-05-17  Alan Hayward  <alan.hayward@arm.com>
 
        * README (Running the Testsuite): Change example.
index 136f1c4df7912776cda840869da36de184761b08..94ac53afc70d1662f88860115436474a490be440 100644 (file)
@@ -33,7 +33,6 @@ gdb_test "print c4" " = \\(1000,-50\\)"
 gdb_test "print c8" " = \\(321,-22\\)"
 gdb_test "print dc" " = \\(321,-22\\)"
 
-setup_kfail gdb/18644 "*-*-*"
 gdb_test "print c16" " = \\(-874,19\\)"
 
 gdb_test "whatis c" "type = complex\\(kind=4\\)"
@@ -53,7 +52,6 @@ gdb_test "print \$_creal (dc)" " = 321"
 gdb_test "whatis \$" " = real\\*8"
 
 gdb_test "whatis c16" "type = complex\\(kind=16\\)"
-setup_kfail gdb/18644 "*-*-*"
 gdb_test "print \$_creal (c16)" " = -874"
 gdb_test "whatis \$" " = real\\*16"
 
index 2f6be4ec249f49a1766db38e4b6fe28439d60353..6394e45f4c3a967cb6703551eebd5820d1c6fe32 100644 (file)
@@ -33,3 +33,4 @@ gdb_test "print oneByte"      " = 1"
 gdb_test "print twobytes"      " = 2"
 gdb_test "print chvalue"       " = \'a\'"
 gdb_test "print logvalue"      " = \.TRUE\."
+gdb_test "print rVal"          " = 2000"
index b4ff928604ffc28f2dc0701ac3516e89b83464d7..36b63532c8e0c7846e8cc9e4f410600ee709c1c6 100644 (file)
@@ -18,10 +18,12 @@ program prog
   integer(2) :: twoBytes
   character  :: chValue
   logical(1) :: logValue
+  real(kind=16) :: rVal
 
   oneByte  = 1
   twoBytes = 2
   chValue  = 'a'
   logValue = .true.
+  rVal = 2000
   write(*,*) s
 end
index 1ae15b96f1aa366ee53b746a5f707983dbc2bb19..9d19a9ceb39a1f57c142067f7fc25864b7689be2 100644 (file)
@@ -27,12 +27,6 @@ if { [skip_fortran_tests] } { continue }
 proc test_cast_1_to_type_kind {base_type type_kind cast_result size_result} {
     set type_string "$base_type (kind=$type_kind)"
     gdb_test "p (($type_string) 1)" " = $cast_result"
-
-    if {($base_type == "real" || $base_type == "complex")
-       && $type_kind == 16} {
-       setup_kfail gdb/18644 "*-*-*"
-    }
-
     gdb_test "p sizeof (($type_string) 1)" " = $size_result"
 }