public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/11] Improve Fortran intrinsic types and procedures
@ 2022-03-09 10:39 Nils-Christian Kempke
  2022-03-09 10:39 ` [PATCH 01/11] gdb/f-lang: add Integer*1 to Fortran builtin types Nils-Christian Kempke
                   ` (10 more replies)
  0 siblings, 11 replies; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

This series completes some of the current intrinsics handling in the
Fortran language part.

Mainly, it adds the KIND parameter overload to all currently implemented
intrinsic procedures (in patch #9).  In doing so it refactors the overload
handling in f-exp.y.

It also improves some of the Fortran type handling and adds a few missing
types and changes the default Locical type to be of KIND=4.

Lastly, it adds two sections to the documentation that (hopefully) clearly
describe which Fortran intrinsic procedures and types are available in
GDB.

All changes only affect the Fortran language part of GDB.

Any feedback is highly appreciated.
Thanks!
Nils

Nils-Christian Kempke (11):
  gdb/f-lang: add Integer*1 to Fortran builtin types
  gdb/f-lang: remove hidden ^L characters
  gdb/fortran: fix complex type in Fortran builtin types
  gdb/fortran: reformat build_fortran_types in f-lang.c
  gdb/fortran: change default logical type to builtin_logical
  gdb/fortran: clean-up Fortran intrinsic types
  gdb/fortran: Change GDB print for fortran default types
  gdb/fortran: rename f77_keywords to f_keywords
  gdb/fortran: rewrite intrinsic handling and add some missing overloads
  gdb/fortran/testsuite: add complex from integers test
  gdb/doc: add section about fortran intrinsic functions and types

 gdb/doc/gdb.texinfo                         | 138 ++++++-
 gdb/f-exp.h                                 | 182 +++++++--
 gdb/f-exp.y                                 | 394 ++++++++++++++------
 gdb/f-lang.c                                | 267 +++++++++----
 gdb/f-lang.h                                |   7 +-
 gdb/std-operator.def                        |  10 +-
 gdb/testsuite/gdb.fortran/complex.exp       |  10 +-
 gdb/testsuite/gdb.fortran/complex.f90       |   7 +-
 gdb/testsuite/gdb.fortran/intrinsics.exp    |  46 ++-
 gdb/testsuite/gdb.fortran/lbound-ubound.F90 |  49 ++-
 gdb/testsuite/gdb.fortran/lbound-ubound.exp |  27 +-
 gdb/testsuite/gdb.fortran/size.exp          |  84 ++++-
 gdb/testsuite/gdb.fortran/size.f90          | 213 ++++++++---
 gdb/testsuite/gdb.fortran/type-kinds.exp    |   2 +
 gdb/testsuite/gdb.fortran/types.exp         |  34 +-
 15 files changed, 1151 insertions(+), 319 deletions(-)

-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 01/11] gdb/f-lang: add Integer*1 to Fortran builtin types
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:28   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 02/11] gdb/f-lang: remove hidden ^L characters Nils-Christian Kempke
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

Add builtin_integer_s1 of size TARGET_CHAR_BIT to Fortran builtin types.

gdb/ChangeLog:
2022-01-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* f-exp.y (convert_to_kind_type): Add kind one for integer and
	map to builtin_integer_s1.
	* f-lang.h (builtin_f_type): Add builtin_integer_s1.
	* f-lang.c (build_fortran_types): Initalize builtin_integer_s1
	with TARGET_CHAR_BIT.

gdb/testsuite/ChangeLog:
2022-01-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* gdb.fortran/type-kinds.exp: Add test for Integer*1.
	* gdb.fortran/types.exp: Add test for Integer*1.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-exp.y                              | 4 +++-
 gdb/f-lang.c                             | 4 ++++
 gdb/f-lang.h                             | 1 +
 gdb/testsuite/gdb.fortran/type-kinds.exp | 2 ++
 gdb/testsuite/gdb.fortran/types.exp      | 2 +-
 5 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 9cba30f683..a17d02611b 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1048,7 +1048,9 @@ convert_to_kind_type (struct type *basetype, int kind)
     }
   else if (basetype == parse_f_type (pstate)->builtin_integer)
     {
-      if (kind == 2)
+      if (kind == 1)
+	return parse_f_type (pstate)->builtin_integer_s1;
+      else if (kind == 2)
 	return parse_f_type (pstate)->builtin_integer_s2;
       else if (kind == 4)
 	return parse_f_type (pstate)->builtin_integer;
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index eaeda884ae..5f7a9e868c 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1622,6 +1622,10 @@ build_fortran_types (struct gdbarch *gdbarch)
   builtin_f_type->builtin_logical_s1
     = arch_boolean_type (gdbarch, TARGET_CHAR_BIT, 1, "logical*1");
 
+  builtin_f_type->builtin_integer_s1
+    = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0,
+			 "integer*1");
+
   builtin_f_type->builtin_integer_s2
     = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0,
 			 "integer*2");
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index 11debd5569..3631c6620a 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -308,6 +308,7 @@ struct builtin_f_type
 {
   struct type *builtin_character;
   struct type *builtin_integer;
+  struct type *builtin_integer_s1;
   struct type *builtin_integer_s2;
   struct type *builtin_integer_s8;
   struct type *builtin_logical;
diff --git a/gdb/testsuite/gdb.fortran/type-kinds.exp b/gdb/testsuite/gdb.fortran/type-kinds.exp
index b054803a0b..47b788bf13 100644
--- a/gdb/testsuite/gdb.fortran/type-kinds.exp
+++ b/gdb/testsuite/gdb.fortran/type-kinds.exp
@@ -56,6 +56,7 @@ proc test_basic_parsing_of_type_kinds {} {
     test_cast_1_to_type_kind "logical" "8" "\\.TRUE\\." "8"
 
     test_cast_1_to_type_kind "integer" "" "1" "4"
+    test_cast_1_to_type_kind "integer" "1" "1" "1"
     test_cast_1_to_type_kind "integer" "2" "1" "2"
     test_cast_1_to_type_kind "integer" "4" "1" "4"
     test_cast_1_to_type_kind "integer" "8" "1" "8"
@@ -92,6 +93,7 @@ proc test_old_star_type_sizes {} {
     gdb_test "p ((logical*4) 1)" " = \\.TRUE\\."
     gdb_test "p ((logical*8) 1)" " = \\.TRUE\\."
 
+    gdb_test "p ((integer*1) 1)" " = 1"
     gdb_test "p ((integer*2) 1)" " = 1"
     gdb_test "p ((integer*4) 1)" " = 1"
     gdb_test "p ((integer*8) 1)" " = 1"
diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp
index 7bd51ca63a..625e02196a 100644
--- a/gdb/testsuite/gdb.fortran/types.exp
+++ b/gdb/testsuite/gdb.fortran/types.exp
@@ -74,7 +74,7 @@ proc test_float_literal_types_accepted {} {
 # Test the the primitive Fortran types, those that GDB should always
 # know, even if the program does not define them, are in fact, known.
 proc test_primitive_types_known {} {
-    foreach type {void character logical*1 integer*2 integer*8 \
+    foreach type {void character logical*1 integer*1 integer*2 integer*8 \
 		      logical*2 logical*8 integer logical*4 real \
 		      real*8 real*16} {
 	gdb_test "ptype $type" [string_to_regexp "type = $type"]
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 02/11] gdb/f-lang: remove hidden ^L characters
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
  2022-03-09 10:39 ` [PATCH 01/11] gdb/f-lang: add Integer*1 to Fortran builtin types Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:28   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types Nils-Christian Kempke
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

gdb/ChangeLog:
2022-01-20  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* gdb/f-lang.c: Remove ^L.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-lang.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 5f7a9e868c..6a561e618a 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -101,8 +101,6 @@ f_language::get_encoding (struct type *type)
   return encoding;
 }
 
-\f
-
 /* A helper function for the "bound" intrinsics that checks that TYPE
    is an array.  LBOUND_P is true for lower bound; this is used for
    the error message, if any.  */
@@ -219,7 +217,6 @@ fortran_bounds_for_dimension (bool lbound_p,
 
   gdb_assert_not_reached ("failed to find matching dimension");
 }
-\f
 
 /* Return the number of dimensions for a Fortran array or string.  */
 
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
  2022-03-09 10:39 ` [PATCH 01/11] gdb/f-lang: add Integer*1 to Fortran builtin types Nils-Christian Kempke
  2022-03-09 10:39 ` [PATCH 02/11] gdb/f-lang: remove hidden ^L characters Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:30   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 04/11] gdb/fortran: reformat build_fortran_types in f-lang.c Nils-Christian Kempke
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

Before this patch things like

  (gdb) ptype complex*8
  complex*16
  (gdb) ptype complex*4
  complex*8

were possible in GDB, which seems confusing for a user.  The reason
is a mixup in the implementation of the Fortran COMPLEX type.  In
Fortran the "*X" after a type would normally (I don't think this
is language required) specify the type's size in memory.  For the
COMPLEX type the kind parameters usually (at least for GNU, Intel, Flang)
specify not the size of the whole type but the size of the individual
two REALs used to form the COMPLEX.  Thus, a COMPLEX*4 will usually
consist of two REAL*4s.  Internally this type was represented by a
builtin_complex_s8 - but here I think the s8 actually meant the raw
size of the type.  This is confusing and I renamed the types (e.g.
builting_complex_s8 became builtin_complex_s4 according to its most
common useage) and their printed names to their language equivalent.
Additionally, I added the default COMPLEX type "COMPLEX" being the same
as a COMPLEX*4 (as is normally the case) and removed the latter.  I added
a few tests for this new behavior as well.

The new behavior is

  (gdb) ptype complex*8
  complex*8
  (gdb) ptype complex*4
  complex*4

gdb/ChangeLog:
2022-01-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* f-lang.h (builtin_f_type): Add builtin_complex and rename
	complex types.
	* f-lang.c (language_arch_info): Rename complex builtin types.
	(build_fortran_types): Replace builtin_complex_s4 with
	builtin_complex.  Use correct names for complex types.
	(f_language::language_arch_info): Add builtin_complex.
	* f-exp.y (tokens): Rename complex tokens.
	(typebase): Use builtin_complex over builtin_complex_s8.
	(convert_to_kind_type): Use builtin_complex as base type for
	conversions.
	(f77_keywords): Rename and order complex types together.

gdb/testsuite/ChangeLog:
2022-01-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* gdb.fortran/types.exp: Add complex tests.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-exp.y                         | 26 +++++++++++++-------------
 gdb/f-lang.c                        | 16 ++++++++--------
 gdb/f-lang.h                        |  2 +-
 gdb/testsuite/gdb.fortran/types.exp |  2 +-
 4 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index a17d02611b..f939efb5c4 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -171,7 +171,7 @@ static int parse_number (struct parser_state *, const char *, int,
 %token LOGICAL_S8_KEYWORD
 %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD 
 %token COMPLEX_KEYWORD
-%token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD 
+%token COMPLEX_S4_KEYWORD COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD
 %token BOOL_AND BOOL_OR BOOL_NOT   
 %token SINGLE DOUBLE PRECISION
 %token <lval> CHARACTER 
@@ -778,21 +778,21 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 	|	REAL_S16_KEYWORD
 			{ $$ = parse_f_type (pstate)->builtin_real_s16; }
 	|	COMPLEX_KEYWORD
-			{ $$ = parse_f_type (pstate)->builtin_complex_s8; }
+			{ $$ = parse_f_type (pstate)->builtin_complex; }
+	|	COMPLEX_S4_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_complex; }
 	|	COMPLEX_S8_KEYWORD
 			{ $$ = parse_f_type (pstate)->builtin_complex_s8; }
 	|	COMPLEX_S16_KEYWORD 
 			{ $$ = parse_f_type (pstate)->builtin_complex_s16; }
-	|	COMPLEX_S32_KEYWORD 
-			{ $$ = parse_f_type (pstate)->builtin_complex_s32; }
 	|	SINGLE PRECISION
 			{ $$ = parse_f_type (pstate)->builtin_real;}
 	|	DOUBLE PRECISION
 			{ $$ = parse_f_type (pstate)->builtin_real_s8;}
 	|	SINGLE COMPLEX_KEYWORD
-			{ $$ = parse_f_type (pstate)->builtin_complex_s8;}
+			{ $$ = parse_f_type (pstate)->builtin_complex;}
 	|	DOUBLE COMPLEX_KEYWORD
-			{ $$ = parse_f_type (pstate)->builtin_complex_s16;}
+			{ $$ = parse_f_type (pstate)->builtin_complex_s8;}
 	;
 
 nonempty_typelist
@@ -1017,14 +1017,14 @@ convert_to_kind_type (struct type *basetype, int kind)
       if (kind == 1)
 	return parse_f_type (pstate)->builtin_character;
     }
-  else if (basetype == parse_f_type (pstate)->builtin_complex_s8)
+  else if (basetype == parse_f_type (pstate)->builtin_complex)
     {
       if (kind == 4)
-	return parse_f_type (pstate)->builtin_complex_s8;
+	return parse_f_type (pstate)->builtin_complex;
       else if (kind == 8)
-	return parse_f_type (pstate)->builtin_complex_s16;
+	return parse_f_type (pstate)->builtin_complex_s8;
       else if (kind == 16)
-	return parse_f_type (pstate)->builtin_complex_s32;
+	return parse_f_type (pstate)->builtin_complex_s16;
     }
   else if (basetype == parse_f_type (pstate)->builtin_real)
     {
@@ -1127,18 +1127,18 @@ static const struct f77_boolean_val boolean_values[]  =
 static const struct token f77_keywords[] =
 {
   /* Historically these have always been lowercase only in GDB.  */
+  { "complex", COMPLEX_KEYWORD, OP_NULL, true },
+  { "complex_4", COMPLEX_S4_KEYWORD, OP_NULL, true },
+  { "complex_8", COMPLEX_S8_KEYWORD, OP_NULL, true },
   { "complex_16", COMPLEX_S16_KEYWORD, OP_NULL, true },
-  { "complex_32", COMPLEX_S32_KEYWORD, OP_NULL, true },
   { "character", CHARACTER, OP_NULL, true },
   { "integer_2", INT_S2_KEYWORD, OP_NULL, true },
   { "logical_1", LOGICAL_S1_KEYWORD, OP_NULL, true },
   { "logical_2", LOGICAL_S2_KEYWORD, OP_NULL, true },
   { "logical_8", LOGICAL_S8_KEYWORD, OP_NULL, true },
-  { "complex_8", COMPLEX_S8_KEYWORD, OP_NULL, true },
   { "integer", INT_KEYWORD, OP_NULL, true },
   { "logical", LOGICAL_KEYWORD, OP_NULL, true },
   { "real_16", REAL_S16_KEYWORD, OP_NULL, true },
-  { "complex", COMPLEX_KEYWORD, OP_NULL, true },
   { "sizeof", SIZEOF, OP_NULL, true },
   { "real_8", REAL_S8_KEYWORD, OP_NULL, true },
   { "real", REAL_KEYWORD, OP_NULL, true },
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 6a561e618a..4a66240e88 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1565,8 +1565,8 @@ f_language::language_arch_info (struct gdbarch *gdbarch,
   add (builtin->builtin_real);
   add (builtin->builtin_real_s8);
   add (builtin->builtin_real_s16);
+  add (builtin->builtin_complex);
   add (builtin->builtin_complex_s8);
-  add (builtin->builtin_complex_s16);
   add (builtin->builtin_void);
 
   lai->set_string_char_type (builtin->builtin_character);
@@ -1665,17 +1665,17 @@ build_fortran_types (struct gdbarch *gdbarch)
     builtin_f_type->builtin_real_s16
       = arch_type (gdbarch, TYPE_CODE_ERROR, 128, "real*16");
 
+  builtin_f_type->builtin_complex
+    = init_complex_type ("complex*4", builtin_f_type->builtin_real);
   builtin_f_type->builtin_complex_s8
-    = init_complex_type ("complex*8", builtin_f_type->builtin_real);
-  builtin_f_type->builtin_complex_s16
-    = init_complex_type ("complex*16", builtin_f_type->builtin_real_s8);
+    = init_complex_type ("complex*8", builtin_f_type->builtin_real_s8);
 
   if (builtin_f_type->builtin_real_s16->code () == TYPE_CODE_ERROR)
-    builtin_f_type->builtin_complex_s32
-      = arch_type (gdbarch, TYPE_CODE_ERROR, 256, "complex*32");
+    builtin_f_type->builtin_complex_s16
+      = arch_type (gdbarch, TYPE_CODE_ERROR, 256, "complex*16");
   else
-    builtin_f_type->builtin_complex_s32
-      = init_complex_type ("complex*32", builtin_f_type->builtin_real_s16);
+    builtin_f_type->builtin_complex_s16
+      = init_complex_type ("complex*16", builtin_f_type->builtin_real_s16);
 
   return builtin_f_type;
 }
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index 3631c6620a..e22b167c38 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -318,9 +318,9 @@ struct builtin_f_type
   struct type *builtin_real;
   struct type *builtin_real_s8;
   struct type *builtin_real_s16;
+  struct type *builtin_complex;
   struct type *builtin_complex_s8;
   struct type *builtin_complex_s16;
-  struct type *builtin_complex_s32;
   struct type *builtin_void;
 };
 
diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp
index 625e02196a..4205d308be 100644
--- a/gdb/testsuite/gdb.fortran/types.exp
+++ b/gdb/testsuite/gdb.fortran/types.exp
@@ -76,7 +76,7 @@ proc test_float_literal_types_accepted {} {
 proc test_primitive_types_known {} {
     foreach type {void character logical*1 integer*1 integer*2 integer*8 \
 		      logical*2 logical*8 integer logical*4 real \
-		      real*8 real*16} {
+		      real*8 real*16 complex*4 complex*8 complex*16} {
 	gdb_test "ptype $type" [string_to_regexp "type = $type"]
     }
 }
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 04/11] gdb/fortran: reformat build_fortran_types in f-lang.c
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
                   ` (2 preceding siblings ...)
  2022-03-09 10:39 ` [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:30   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 05/11] gdb/fortran: change default logical type to builtin_logical Nils-Christian Kempke
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

Add a few newlines after the type definitions and remove some
unnecessary linebreaks.

gdb/ChangeLog:
2022-01-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* f-lang.c (build_fortran_types): Reformat a bit.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-lang.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 4a66240e88..c8a0d66877 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1620,39 +1620,36 @@ build_fortran_types (struct gdbarch *gdbarch)
     = arch_boolean_type (gdbarch, TARGET_CHAR_BIT, 1, "logical*1");
 
   builtin_f_type->builtin_integer_s1
-    = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0,
-			 "integer*1");
+    = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "integer*1");
 
   builtin_f_type->builtin_integer_s2
-    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0,
-			 "integer*2");
+    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0, "integer*2");
 
   builtin_f_type->builtin_integer_s8
     = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), 0,
 			 "integer*8");
 
   builtin_f_type->builtin_logical_s2
-    = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1,
-			 "logical*2");
+    = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1, "logical*2");
 
   builtin_f_type->builtin_logical_s8
     = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
 			 "logical*8");
 
   builtin_f_type->builtin_integer
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0,
-			 "integer");
+    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "integer");
 
   builtin_f_type->builtin_logical
-    = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1,
-			 "logical*4");
+    = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "logical*4");
 
   builtin_f_type->builtin_real
     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
 		       "real", gdbarch_float_format (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);
   if (fmt != nullptr)
     builtin_f_type->builtin_real_s16
@@ -1667,6 +1664,7 @@ build_fortran_types (struct gdbarch *gdbarch)
 
   builtin_f_type->builtin_complex
     = init_complex_type ("complex*4", builtin_f_type->builtin_real);
+
   builtin_f_type->builtin_complex_s8
     = init_complex_type ("complex*8", builtin_f_type->builtin_real_s8);
 
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 05/11] gdb/fortran: change default logical type to builtin_logical
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
                   ` (3 preceding siblings ...)
  2022-03-09 10:39 ` [PATCH 04/11] gdb/fortran: reformat build_fortran_types in f-lang.c Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:32   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 06/11] gdb/fortran: clean-up Fortran intrinsic types Nils-Christian Kempke
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

According to the Fortran standard, logical is of the size of a
'single numeric storage unit' (just like real and integer). For
gfortran, flang and ifx/ifort this storage unit (or the default
logical type) is of size kind 4, actually occupying 4 bytes of
storage, and so the default type for logical expressions in
Fortran should probably also be Logical*4 and not Logical*2.  I
adapted GDB's behavior to be in line with
gfortran/ifort/ifx/flang.

gdb/ChangeLog:
2022-02-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* f-lang.c: Change Fortran default logical to builtin_logical.

gdb/testsuite/ChangeLog:
2022-02-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* gdb.fortran/types.exp: Adapt expected output.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-lang.c                        | 2 +-
 gdb/testsuite/gdb.fortran/types.exp | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index c8a0d66877..8e9af7661c 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1570,7 +1570,7 @@ f_language::language_arch_info (struct gdbarch *gdbarch,
   add (builtin->builtin_void);
 
   lai->set_string_char_type (builtin->builtin_character);
-  lai->set_bool_type (builtin->builtin_logical_s2, "logical");
+  lai->set_bool_type (builtin->builtin_logical, "logical");
 }
 
 /* See language.h.  */
diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp
index 4205d308be..8122cbcca3 100644
--- a/gdb/testsuite/gdb.fortran/types.exp
+++ b/gdb/testsuite/gdb.fortran/types.exp
@@ -48,10 +48,10 @@ proc test_logical_literal_types_accepted {} {
     # Test the only possible values for a logical, TRUE and FALSE (and
     # also true and false).
 
-    gdb_test "pt .TRUE." "type = logical\\*2"
-    gdb_test "pt .FALSE." "type = logical\\*2"
-    gdb_test "pt .true." "type = logical\\*2"
-    gdb_test "pt .false." "type = logical\\*2"
+    gdb_test "pt .TRUE." "type = logical\\*4"
+    gdb_test "pt .FALSE." "type = logical\\*4"
+    gdb_test "pt .true." "type = logical\\*4"
+    gdb_test "pt .false." "type = logical\\*4"
 }
 
 proc test_float_literal_types_accepted {} {
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 06/11] gdb/fortran: clean-up Fortran intrinsic types
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
                   ` (4 preceding siblings ...)
  2022-03-09 10:39 ` [PATCH 05/11] gdb/fortran: change default logical type to builtin_logical Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:33   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 07/11] gdb/fortran: Change GDB print for fortran default types Nils-Christian Kempke
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

The currently implemented intrinsic type handling for Fortran missed some
tokens and their parsing.  While still not all Fortran type kinds are
implemented this patch at least makes the currently handled types
consistent.  As an example for what this patch does, consider the
intrinsic type INTEGER.  GDB implemented the handling of the
keywords "integer" and "integer_2" but missed "integer_4" and "integer_8"
even though their corresponding internal types were already available as
the Fortran builtin types builtin_integer and builtin_integer_s8.
Similar problems applied to LOGICAL, REAL, and COMPLEX.  This patch adds
all missing tokens and their parsing.  Whenever a section containing the
type handling was touched, it also was reordered to be in a more easy to
grasp order.  All INTEGER/REAL/LOGICAL/COMPLEX types were grouped
together and ordered ascending in their size making a missing one more
easy to spot.

Before this change GDB would print the following when tyring to use the
INTEGER keywords:

   (gdb) set language fortran
   (gdb) ptype integer*1
   unsupported kind 1 for type integer
   (gdb) ptype integer_1
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer*2
   type = integer*2
   (gdb) ptype integer_2
   type = integer*2
   (gdb) ptype integer*4
   type = integer
   (gdb) ptype integer_4
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer*8
   type = integer*8
   (gdb) ptype integer_8
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer
   type = integer

With this patch all keywords are available and the GDB prints:

   (gdb) set language fortran
   (gdb) ptype integer*1
   type = integer*1
   (gdb) ptype integer_1
   type = integer*1
   (gdb) ptype integer*2
   type = integer*2
   (gdb) ptype integer_2
   type = integer*2
   (gdb) ptype integer*4
   type = integer*4
   (gdb) ptype integer_4
   type = integer*4
   (gdb) ptype integer*8
   type = integer*8
   (gdb) ptype integer_8
   type = integer*8
   (gdb) ptype integer
   type = integer

The described changes have been applied to INTEGER, REAL, COMPLEX,
and LOGICAL. Existing testcases have been adapted to reflect the
new behavior.  Tests for formerly missing types have been added.

gdb/ChangeLog:
2022-02-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* f-exp.y (tokens): Add missing INTEGER, REAL, COMPLEX, and
	LOGICAL tokens and reorder them.
	(typebase): Add parsing rules for new tokens and reorder the
	rules.
	(f77_keywords): Add missing keywords and reorder them.
	* f-lang.c (build_fortran_types): Reorder types.
	* f-lang.h (builtin_f_type): Reorder types.

gdb/testsuite/ChangeLog:
2022-02-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* types.exp: Add tests for default types.  Add tests for all
	Fortran type keywords.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-exp.y                         | 50 +++++++++++++++++++----------
 gdb/f-lang.c                        | 24 +++++++-------
 gdb/f-lang.h                        |  4 +--
 gdb/testsuite/gdb.fortran/types.exp | 31 +++++++++++++++---
 4 files changed, 74 insertions(+), 35 deletions(-)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index f939efb5c4..e07af7322a 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -167,11 +167,12 @@ static int parse_number (struct parser_state *, const char *, int,
 
 /* Special type cases, put in to allow the parser to distinguish different
    legal basetypes.  */
-%token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD 
+%token INT_S1_KEYWORD INT_S2_KEYWORD INT_KEYWORD INT_S4_KEYWORD INT_S8_KEYWORD
+%token LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD LOGICAL_KEYWORD LOGICAL_S4_KEYWORD
 %token LOGICAL_S8_KEYWORD
-%token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD 
-%token COMPLEX_KEYWORD
-%token COMPLEX_S4_KEYWORD COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD
+%token REAL_KEYWORD REAL_S4_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
+%token COMPLEX_KEYWORD COMPLEX_S4_KEYWORD COMPLEX_S8_KEYWORD
+%token COMPLEX_S16_KEYWORD
 %token BOOL_AND BOOL_OR BOOL_NOT   
 %token SINGLE DOUBLE PRECISION
 %token <lval> CHARACTER 
@@ -757,22 +758,32 @@ func_mod:	'(' ')'
 typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 	:	TYPENAME
 			{ $$ = $1.type; }
+	|	INT_S1_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_integer_s1; }
+	|	INT_S2_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_integer_s2; }
 	|	INT_KEYWORD
 			{ $$ = parse_f_type (pstate)->builtin_integer; }
-	|	INT_S2_KEYWORD 
-			{ $$ = parse_f_type (pstate)->builtin_integer_s2; }
+	|	INT_S4_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_integer; }
+	|	INT_S8_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_integer_s8; }
 	|	CHARACTER 
 			{ $$ = parse_f_type (pstate)->builtin_character; }
-	|	LOGICAL_S8_KEYWORD
-			{ $$ = parse_f_type (pstate)->builtin_logical_s8; }
-	|	LOGICAL_KEYWORD 
-			{ $$ = parse_f_type (pstate)->builtin_logical; }
-	|	LOGICAL_S2_KEYWORD
-			{ $$ = parse_f_type (pstate)->builtin_logical_s2; }
 	|	LOGICAL_S1_KEYWORD 
 			{ $$ = parse_f_type (pstate)->builtin_logical_s1; }
+	|	LOGICAL_S2_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_logical_s2; }
+	|	LOGICAL_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_logical; }
+	|	LOGICAL_S4_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_logical; }
+	|	LOGICAL_S8_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_logical_s8; }
 	|	REAL_KEYWORD 
 			{ $$ = parse_f_type (pstate)->builtin_real; }
+	|	REAL_S4_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_real; }
 	|       REAL_S8_KEYWORD
 			{ $$ = parse_f_type (pstate)->builtin_real_s8; }
 	|	REAL_S16_KEYWORD
@@ -1127,21 +1138,26 @@ static const struct f77_boolean_val boolean_values[]  =
 static const struct token f77_keywords[] =
 {
   /* Historically these have always been lowercase only in GDB.  */
+  { "character", CHARACTER, OP_NULL, true },
   { "complex", COMPLEX_KEYWORD, OP_NULL, true },
   { "complex_4", COMPLEX_S4_KEYWORD, OP_NULL, true },
   { "complex_8", COMPLEX_S8_KEYWORD, OP_NULL, true },
   { "complex_16", COMPLEX_S16_KEYWORD, OP_NULL, true },
-  { "character", CHARACTER, OP_NULL, true },
+  { "integer_1", INT_S1_KEYWORD, OP_NULL, true },
   { "integer_2", INT_S2_KEYWORD, OP_NULL, true },
+  { "integer_4", INT_S4_KEYWORD, OP_NULL, true },
+  { "integer", INT_KEYWORD, OP_NULL, true },
+  { "integer_8", INT_S8_KEYWORD, OP_NULL, true },
   { "logical_1", LOGICAL_S1_KEYWORD, OP_NULL, true },
   { "logical_2", LOGICAL_S2_KEYWORD, OP_NULL, true },
-  { "logical_8", LOGICAL_S8_KEYWORD, OP_NULL, true },
-  { "integer", INT_KEYWORD, OP_NULL, true },
   { "logical", LOGICAL_KEYWORD, OP_NULL, true },
+  { "logical_4", LOGICAL_S4_KEYWORD, OP_NULL, true },
+  { "logical_8", LOGICAL_S8_KEYWORD, OP_NULL, true },
+  { "real", REAL_KEYWORD, OP_NULL, true },
+  { "real_4", REAL_S4_KEYWORD, OP_NULL, true },
+  { "real_8", REAL_S8_KEYWORD, OP_NULL, true },
   { "real_16", REAL_S16_KEYWORD, OP_NULL, true },
   { "sizeof", SIZEOF, OP_NULL, true },
-  { "real_8", REAL_S8_KEYWORD, OP_NULL, true },
-  { "real", REAL_KEYWORD, OP_NULL, true },
   { "single", SINGLE, OP_NULL, true },
   { "double", DOUBLE, OP_NULL, true },
   { "precision", PRECISION, OP_NULL, true },
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 8e9af7661c..5a97beada2 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1619,28 +1619,28 @@ build_fortran_types (struct gdbarch *gdbarch)
   builtin_f_type->builtin_logical_s1
     = arch_boolean_type (gdbarch, TARGET_CHAR_BIT, 1, "logical*1");
 
-  builtin_f_type->builtin_integer_s1
-    = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "integer*1");
-
-  builtin_f_type->builtin_integer_s2
-    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0, "integer*2");
-
-  builtin_f_type->builtin_integer_s8
-    = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), 0,
-			 "integer*8");
-
   builtin_f_type->builtin_logical_s2
     = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1, "logical*2");
 
+  builtin_f_type->builtin_logical
+    = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "logical*4");
+
   builtin_f_type->builtin_logical_s8
     = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
 			 "logical*8");
 
+  builtin_f_type->builtin_integer_s1
+    = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "integer*1");
+
+  builtin_f_type->builtin_integer_s2
+    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0, "integer*2");
+
   builtin_f_type->builtin_integer
     = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "integer");
 
-  builtin_f_type->builtin_logical
-    = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "logical*4");
+  builtin_f_type->builtin_integer_s8
+    = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), 0,
+			 "integer*8");
 
   builtin_f_type->builtin_real
     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index e22b167c38..d8fad03e87 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -307,13 +307,13 @@ extern int calc_f77_array_dims (struct type *);
 struct builtin_f_type
 {
   struct type *builtin_character;
-  struct type *builtin_integer;
   struct type *builtin_integer_s1;
   struct type *builtin_integer_s2;
+  struct type *builtin_integer;
   struct type *builtin_integer_s8;
-  struct type *builtin_logical;
   struct type *builtin_logical_s1;
   struct type *builtin_logical_s2;
+  struct type *builtin_logical;
   struct type *builtin_logical_s8;
   struct type *builtin_real;
   struct type *builtin_real_s8;
diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp
index 8122cbcca3..5ab44b10a3 100644
--- a/gdb/testsuite/gdb.fortran/types.exp
+++ b/gdb/testsuite/gdb.fortran/types.exp
@@ -71,13 +71,35 @@ proc test_float_literal_types_accepted {} {
     gdb_test "pt 10e20" "type = real\\*\[0-9\]+"
 }
 
+# Test the default primitive Fortran types.
+proc test_default_types {} {
+    gdb_test "ptype integer*4" "type = integer"
+    gdb_test "ptype integer_4" "type = integer"
+
+    gdb_test "ptype logical" "type = logical*4"
+
+    gdb_test "ptype real*4" "type = real"
+    gdb_test "ptype real_4" "type = real"
+
+    gdb_test "ptype complex" "type = complex*4"
+}
+
 # Test the the primitive Fortran types, those that GDB should always
 # know, even if the program does not define them, are in fact, known.
 proc test_primitive_types_known {} {
-    foreach type {void character logical*1 integer*1 integer*2 integer*8 \
-		      logical*2 logical*8 integer logical*4 real \
-		      real*8 real*16 complex*4 complex*8 complex*16} {
-	gdb_test "ptype $type" [string_to_regexp "type = $type"]
+    foreach type {void character \
+		     integer*1 integer*2 integer integer*8 \
+		     integer_1 integer_2 integer_8 \
+		     logical*1 logical*2 logical*4 logical*8 \
+		     logical_1 logical_2 logical_4 logical_8 \
+		     real real*8 real*16 real_8 real_16 \
+		     complex*4 complex*8 complex*16 \
+		     complex_4 complex_8 complex_16} {
+
+	# While TYPE_KIND is allowed as input, GDB will always return the
+	# Fortran notation TYPE*KIND
+	regsub -all "_" $type "\*" type_res
+	gdb_test "ptype $type" [string_to_regexp "type = $type_res"]
     }
 }
 
@@ -91,6 +113,7 @@ gdb_test "set print sevenbit-strings" ""
 
 if [set_lang_fortran] then {
     test_primitive_types_known
+    test_default_types
     test_integer_literal_types_accepted
     test_integer_literal_types_rejected
     test_logical_literal_types_accepted
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 07/11] gdb/fortran: Change GDB print for fortran default types
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
                   ` (5 preceding siblings ...)
  2022-03-09 10:39 ` [PATCH 06/11] gdb/fortran: clean-up Fortran intrinsic types Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:37   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 08/11] gdb/fortran: rename f77_keywords to f_keywords Nils-Christian Kempke
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

Currently, when asking GDB to print the type of a Fortran default type
such as INTEGER or REAL, GDB will return the deafult name of that type,
e.g. "integer"/"real":

   (gdb) ptype integer
   type = integer
   (gdb) ptype real
   type = real

For LOGICAL and COMPLEX it would return the actual underlying types

   (gdb) ptype logical
   type = logical*4
   (gdb) ptype complex
   type = complex*4

Similarly, GDB would print the default integer type for the underlying
default type:

   (gdb) ptype integer*4
   type = integer
   (gdb) ptype real*4
   type = real
   (gdb) ptype logical
   type = logical*4
   (gdb) ptype complex*4
   type = complex*4

This is inconsistent and a bit confusing.  Both options somehow indicate
what the internal underlying type for the default type is - but I think
the logical/complex version is a bit clearer.

Consider again:

   (gdb) ptype integer
   type = integer

This indicates to a user that the type of "integer" is Fortran's default
integer type.  Without examining "ptype integer*4" I would expect, that
any variable declared integer in the actual code would also fit into a
GDB integer.  But, since we cannot adapt out internal types to the
compiler flags used at compiler time of a debugged binary, this might be
wrong.  Consider debugging Fortran code compiled with GNU and e.g. the
"-fdefault-integer-8" flag.  In this case the gfortran default integer
would be integer*8 while GDB internally still would use a builtin_integer,
so an integer of the size of an integer*4 type.  On the other hand having
GDB print

   (gdb) ptype integer
   type = integer*4

makes this clearer.  I would still be tempted to fit a variable declared
integer in the code into a GDB integer - but at least ptype would
directly tell me what is going on.  Note, that when debugging a binary
compiled with "-fdefault-integer-8" a user will always see the actual
underlying type of any variable declared "integer" in the Fortran code.
So having the code

   program test
     integer :: a = 5
     print *, a ! breakpt
   end program test

will, when breaking at breakpt print

   (gdb) ptype var
   type = integer(kind=4)

or

   (gdb) ptype var
   type = integer(kind=8)

depending on the compiler flag.

This patch changes the outputs for the REAL and INTEGER default types to
actually print the internally used type over the default type name.

The new behavior for the above examples is:

   (gdb) ptype integer
   type = integer*4
   (gdb) ptype integer*4
   type = integer*4

Existing testcases have been adapted to reflect the new behavior.

gdb/ChangeLog:
2022-03-02  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

        * f-lang.c (build_fortran_types): Change output for default
	types.

gdb/testsuite/ChangeLog:
2022-03-02  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

        * gdb.fortran/complex.exp: Change expected output for default
	types.
        * gdb.fortran/types.exp: Change test for default types.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-lang.c                          |  4 ++--
 gdb/testsuite/gdb.fortran/complex.exp |  4 ++--
 gdb/testsuite/gdb.fortran/types.exp   | 19 +++++++------------
 3 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 5a97beada2..bea24ce0ca 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1636,7 +1636,7 @@ build_fortran_types (struct gdbarch *gdbarch)
     = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0, "integer*2");
 
   builtin_f_type->builtin_integer
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "integer");
+    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "integer*4");
 
   builtin_f_type->builtin_integer_s8
     = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), 0,
@@ -1644,7 +1644,7 @@ build_fortran_types (struct gdbarch *gdbarch)
 
   builtin_f_type->builtin_real
     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
-		       "real", gdbarch_float_format (gdbarch));
+		       "real*4", gdbarch_float_format (gdbarch));
 
   builtin_f_type->builtin_real_s8
     = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
diff --git a/gdb/testsuite/gdb.fortran/complex.exp b/gdb/testsuite/gdb.fortran/complex.exp
index 60f7c8e255..f4a80fbf78 100644
--- a/gdb/testsuite/gdb.fortran/complex.exp
+++ b/gdb/testsuite/gdb.fortran/complex.exp
@@ -45,13 +45,13 @@ gdb_test "print c16" " = \\(-874,19\\)"
 gdb_test "whatis c" "type = $complex4"
 gdb_test "print \$_creal (c)" " = 1000"
 with_test_prefix "c" {
-    gdb_test "whatis \$" " = real"
+    gdb_test "whatis \$" " = real\\*4"
 }
 
 gdb_test "whatis c4" "type = $complex4"
 gdb_test "print \$_creal (c4)" " = 1000"
 with_test_prefix "c4" {
-    gdb_test "whatis \$" " = real"
+    gdb_test "whatis \$" " = real\\*4"
 }
 gdb_test "whatis c8" "type = $complex8"
 gdb_test "print \$_creal (c8)" " = 321"
diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp
index 5ab44b10a3..594276f3a7 100644
--- a/gdb/testsuite/gdb.fortran/types.exp
+++ b/gdb/testsuite/gdb.fortran/types.exp
@@ -73,26 +73,21 @@ proc test_float_literal_types_accepted {} {
 
 # Test the default primitive Fortran types.
 proc test_default_types {} {
-    gdb_test "ptype integer*4" "type = integer"
-    gdb_test "ptype integer_4" "type = integer"
-
-    gdb_test "ptype logical" "type = logical*4"
-
-    gdb_test "ptype real*4" "type = real"
-    gdb_test "ptype real_4" "type = real"
-
-    gdb_test "ptype complex" "type = complex*4"
+    gdb_test "ptype integer" "type = integer\\*4"
+    gdb_test "ptype logical" "type = logical\\*4"
+    gdb_test "ptype real" "type = real\\*4"
+    gdb_test "ptype complex" "type = complex\\*4"
 }
 
 # Test the the primitive Fortran types, those that GDB should always
 # know, even if the program does not define them, are in fact, known.
 proc test_primitive_types_known {} {
     foreach type {void character \
-		     integer*1 integer*2 integer integer*8 \
-		     integer_1 integer_2 integer_8 \
+		     integer*1 integer*2 integer*4 integer*8 \
+		     integer_1 integer_2 integer_4 integer_8 \
 		     logical*1 logical*2 logical*4 logical*8 \
 		     logical_1 logical_2 logical_4 logical_8 \
-		     real real*8 real*16 real_8 real_16 \
+		     real*4 real*8 real*16 real_4 real_8 real_16 \
 		     complex*4 complex*8 complex*16 \
 		     complex_4 complex_8 complex_16} {
 
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 08/11] gdb/fortran: rename f77_keywords to f_keywords
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
                   ` (6 preceding siblings ...)
  2022-03-09 10:39 ` [PATCH 07/11] gdb/fortran: Change GDB print for fortran default types Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:37   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads Nils-Christian Kempke
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

Rename f77_keywords to f_keywords since some of the introduced keywords
in the array are f90 only.

gdb/ChangeLog:
2022-03-02  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* f-exp.h (f77_keywords): Rename to f_keywords.
	(yylex): Rename f77_keywords.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-exp.y | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index e07af7322a..c062754ae4 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1135,7 +1135,7 @@ static const struct f77_boolean_val boolean_values[]  =
   { ".false.", 0 }
 };
 
-static const struct token f77_keywords[] =
+static const token f_keywords[] =
 {
   /* Historically these have always been lowercase only in GDB.  */
   { "character", CHARACTER, OP_NULL, true },
@@ -1470,7 +1470,7 @@ yylex (void)
   
   /* Catch specific keywords.  */
 
-  for (const auto &keyword : f77_keywords)
+  for (const auto &keyword : f_keywords)
     if (strlen (keyword.oper) == namelen
 	&& ((!keyword.case_sensitive
 	     && strncasecmp (tokstart, keyword.oper, namelen) == 0)
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
                   ` (7 preceding siblings ...)
  2022-03-09 10:39 ` [PATCH 08/11] gdb/fortran: rename f77_keywords to f_keywords Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:49   ` Tom Tromey
  2022-04-13  5:14   ` Tom de Vries
  2022-03-09 10:39 ` [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test Nils-Christian Kempke
  2022-03-09 10:39 ` [PATCH 11/11] gdb/doc: add section about fortran intrinsic functions and types Nils-Christian Kempke
  10 siblings, 2 replies; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND.  This
parameter determines the kind of the associated return value.  So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.

This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.

It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.

After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate.  E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function.  This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.

gdb/ChangeLog:
2022-03-02  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* f-exp.h (eval_op_f_ceil): New declaration for additional
	overload.
	(eval_op_f_floor): New declaration for additional overload.
	(eval_op_f_cmplx): New declarations for additional overloads.
	(eval_op_f_array_size): New declaration for additional overload.
	(binary_kind_ftype): New typedef.
	(fortran_kind_2arg): New operation template.
	(ternary_kind_ftype): New typedef.
	(fortran_kind_3arg): New operation template.
	(namespace::expr): Add new overloads to Fortran operations.
	(fortran_cmplx_operation): Deleted.  Replaced by dedicated CMPLX
	handling in f-lang.c.
	(fortran_bound_3arg): New class for bound operation overload with
	three arguments.
	* f-exp.y (wrap_unop_intrinsic): New method.
	(wrap_binop_intrinsic): New method.
	(wrap_ternop_intrinsic): New method.
	(fortran_wrap2_kind): New method.
	(fortran_wrap3_kind): New method.
	(UNOP_OR_BINOP_OR_TERNOP_INTRINSIC): New token.
	(UNOP_OR_BINOP_INTRINSIC): Use wrap_unop_intrinsic or
	wrap_binop_intrinsic depending on number of arguments.
	(UNOP_INTRINSIC): Rewrite expression handling to use
	wrap_unop_intrinsic.
	(BINOP_INTRINSIC): Rewrite expression handling to use
	wrap_binop_intrinsic.
	(UNOP_OR_BINOP_OR_TERNOP_INTRINSIC): New expression handling.
	(f_keywords): Change token of some intrinsics for optional
	kind argument.
	* f-lang.c (fortran_bounds_for_dimension): Change signature to
	accept a type to compute in.
	(fortran_array_size): Change signature to accept a type to
	compute in.
	(eval_op_f_array_size): New overload.
	(fortran_ceil_operation): New method.
	(eval_op_f_ceil): New overload.
	(fortran_bounds_all_dims): Adapt return type to builtin_integer.
	(fortran_floor_operation): New method.
	(eval_op_f_floor): New overload.
	(eval_op_f_cmplx): New overloads.
	(fortran_bound_2arg): Adapt for new fortran_bounds_for_dimension
	signature.
	(fortran_bound_3arg): New method.
	* std-operator.def: Adapt names of Fortran operators.

gdb/testsuite/ChangeLog:
2022-03-02  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* gdb.fortran/intrinsics.exp: Add tests for CEILING, FLOOR and
	CMPLEX with kind parameter and test for overflows and return
	types.
	* gdb.fortran/lbound-ubound.F90: Add arrays with possibly
	overflowing dimensions and add some test.
	* gdb.fortran/lbound-ubound.exp: Add LBOUND/UBOUND test for
	overflow in array dimensions when supplying the KIND parameter.
	* gdb.fortran/size.exp: Add tests for overflow when using the
	KIND parameter.
	* gdb.fortran/size.f90: Add compiled KIND parameter tests.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-exp.h                                 | 182 ++++++++++--
 gdb/f-exp.y                                 | 312 ++++++++++++++------
 gdb/f-lang.c                                | 212 ++++++++++---
 gdb/std-operator.def                        |  10 +-
 gdb/testsuite/gdb.fortran/intrinsics.exp    |  46 ++-
 gdb/testsuite/gdb.fortran/lbound-ubound.F90 |  49 ++-
 gdb/testsuite/gdb.fortran/lbound-ubound.exp |  27 +-
 gdb/testsuite/gdb.fortran/size.exp          |  84 +++++-
 gdb/testsuite/gdb.fortran/size.f90          | 213 ++++++++++---
 9 files changed, 900 insertions(+), 235 deletions(-)

diff --git a/gdb/f-exp.h b/gdb/f-exp.h
index d5d267e778..6b6bf61722 100644
--- a/gdb/f-exp.h
+++ b/gdb/f-exp.h
@@ -32,26 +32,85 @@ extern struct value *eval_op_f_mod (struct type *expect_type,
 				    enum noside noside,
 				    enum exp_opcode opcode,
 				    struct value *arg1, struct value *arg2);
+
+/* Implement expression evaluation for Fortran's CEILING intrinsic function
+   called with one argument.  For EXPECT_TYPE, EXP, and NOSIDE see
+   expression::evaluate (in expression.h).  OPCODE will always be
+   FORTRAN_CEILING and ARG1 is the argument passed to CEILING.  */
+
 extern struct value *eval_op_f_ceil (struct type *expect_type,
 				     struct expression *exp,
 				     enum noside noside,
 				     enum exp_opcode opcode,
 				     struct value *arg1);
+
+/* Implement expression evaluation for Fortran's CEILING intrinsic function
+   called with two arguments.  For EXPECT_TYPE, EXP, and NOSIDE see
+   expression::evaluate (in expression.h).  OPCODE will always be
+   FORTRAN_CEILING, ARG1 is the first argument passed to CEILING, and KIND_ARG
+   is the type corresponding to the KIND parameter passed to CEILING.  */
+
+extern value *eval_op_f_ceil (type *expect_type, expression *exp,
+			      noside noside, exp_opcode opcode, value *arg1,
+			      type *kind_arg);
+
+/* Implement expression evaluation for Fortran's FLOOR intrinsic function
+   called with one argument.  For EXPECT_TYPE, EXP, and NOSIDE see
+   expression::evaluate (in expression.h).  OPCODE will always be FORTRAN_FLOOR
+   and ARG1 is the argument passed to FLOOR.  */
+
 extern struct value *eval_op_f_floor (struct type *expect_type,
 				      struct expression *exp,
 				      enum noside noside,
 				      enum exp_opcode opcode,
 				      struct value *arg1);
+
+/* Implement expression evaluation for Fortran's FLOOR intrinsic function
+   called with two arguments.  For EXPECT_TYPE, EXP, and NOSIDE see
+   expression::evaluate (in expression.h).  OPCODE will always be
+   FORTRAN_FLOOR, ARG1 is the first argument passed to FLOOR, and KIND_ARG is
+   the type corresponding to the KIND parameter passed to FLOOR.  */
+
+extern value *eval_op_f_floor (type *expect_type, expression *exp,
+			       noside noside, exp_opcode opcode, value *arg1,
+			       type *kind_arg);
+
 extern struct value *eval_op_f_modulo (struct type *expect_type,
 				       struct expression *exp,
 				       enum noside noside,
 				       enum exp_opcode opcode,
 				       struct value *arg1, struct value *arg2);
+
+/* Implement expression evaluation for Fortran's CMPLX intrinsic function
+   called with one argument.  For EXPECT_TYPE, EXP, and NOSIDE see
+   expression::evaluate (in expression.h). OPCODE will always be
+   FORTRAN_CMPLX and ARG1 is the argument passed to CMPLX if.  */
+
+extern value *eval_op_f_cmplx (type *expect_type, expression *exp,
+			       noside noside, exp_opcode opcode, value *arg1);
+
+/* Implement expression evaluation for Fortran's CMPLX intrinsic function
+   called with two arguments.  For EXPECT_TYPE, EXP, and NOSIDE see
+   expression::evaluate (in expression.h).  OPCODE will always be
+   FORTRAN_CMPLX, ARG1 and ARG2 are the arguments passed to CMPLX.  */
+
 extern struct value *eval_op_f_cmplx (struct type *expect_type,
 				      struct expression *exp,
 				      enum noside noside,
 				      enum exp_opcode opcode,
 				      struct value *arg1, struct value *arg2);
+
+/* Implement expression evaluation for Fortran's CMPLX intrinsic function
+   called with three arguments.  For EXPECT_TYPE, EXP, and NOSIDE see
+   expression::evaluate (in expression.h).  OPCODE will always be
+   FORTRAN_CMPLX, ARG1 and ARG2 are real and imaginary part passed to CMPLX,
+   and KIND_ARG is the type corresponding to the KIND parameter passed to
+   CMPLX.  */
+
+extern value *eval_op_f_cmplx (type *expect_type, expression *exp,
+			       noside noside, exp_opcode opcode, value *arg1,
+			       value *arg2, type *kind_arg);
+
 extern struct value *eval_op_f_kind (struct type *expect_type,
 				     struct expression *exp,
 				     enum noside noside,
@@ -92,7 +151,7 @@ extern struct value *eval_op_f_rank (struct type *expect_type,
 
 /* Implement expression evaluation for Fortran's SIZE keyword. For
    EXPECT_TYPE, EXP, and NOSIDE see expression::evaluate (in
-   expression.h).  OP will always for FORTRAN_ARRAY_SIZE.  ARG1 is the
+   expression.h).  OPCODE will always for FORTRAN_ARRAY_SIZE.  ARG1 is the
    value passed to SIZE if it is only passed a single argument.  For the
    two argument form see the overload of this function below.  */
 
@@ -113,6 +172,16 @@ extern struct value *eval_op_f_array_size (struct type *expect_type,
 					   struct value *arg1,
 					   struct value *arg2);
 
+/* Implement expression evaluation for Fortran's SIZE intrinsic function called
+   with three arguments.  For EXPECT_TYPE, EXP, and NOSIDE see
+   expression::evaluate (in expression.h).  OPCODE will always be
+   FORTRAN_ARRAY_SIZE, ARG1 and ARG2 the first two values passed to SIZE, and
+   KIND_ARG is the type corresponding to the KIND parameter passed to SIZE.  */
+
+extern value *eval_op_f_array_size (type *expect_type, expression *exp,
+				    noside noside, exp_opcode opcode,
+				    value *arg1, value *arg2, type *kind_arg);
+
 /* Implement the evaluation of Fortran's SHAPE keyword.  EXPECTED_TYPE,
    EXP, and NOSIDE are as for expression::evaluate (see expression.h).  OP
    will always be UNOP_FORTRAN_SHAPE, and ARG1 is the argument being passed
@@ -127,11 +196,68 @@ extern struct value *eval_op_f_array_shape (struct type *expect_type,
 namespace expr
 {
 
+/* Function prototype for Fortran intrinsic functions taking one argument and
+   one kind argument.  */
+typedef value *binary_kind_ftype (type *expect_type, expression *exp,
+				  noside noside, exp_opcode op, value *arg1,
+				  type *kind_arg);
+
+/* Two-argument operation with the second argument being a kind argument.  */
+template<exp_opcode OP, binary_kind_ftype FUNC>
+class fortran_kind_2arg
+  : public tuple_holding_operation<operation_up, type*>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (type *expect_type, expression *exp, noside noside) override
+  {
+    value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+    type *kind_arg = std::get<1> (m_storage);
+    return FUNC (expect_type, exp, noside, OP, arg1, kind_arg);
+  }
+
+  exp_opcode opcode () const override
+  { return OP; }
+};
+
+/* Function prototype for Fortran intrinsic functions taking two arguments and
+   one kind argument.  */
+typedef value *ternary_kind_ftype (type *expect_type, expression *exp,
+				   noside noside, exp_opcode op, value *arg1,
+				   value *arg2, type *kind_arg);
+
+/* Three-argument operation with the third argument being a kind argument.  */
+template<exp_opcode OP, ternary_kind_ftype FUNC>
+class fortran_kind_3arg
+  : public tuple_holding_operation<operation_up, operation_up, type *>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (type *expect_type, expression *exp, noside noside) override
+  {
+    value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+    value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+    type *kind_arg = std::get<2> (m_storage);
+    return FUNC (expect_type, exp, noside, OP, arg1, arg2, kind_arg);
+  }
+
+  exp_opcode opcode () const override
+  { return OP; }
+};
+
 using fortran_abs_operation = unop_operation<UNOP_ABS, eval_op_f_abs>;
-using fortran_ceil_operation = unop_operation<UNOP_FORTRAN_CEILING,
-					      eval_op_f_ceil>;
-using fortran_floor_operation = unop_operation<UNOP_FORTRAN_FLOOR,
-					       eval_op_f_floor>;
+using fortran_ceil_operation_1arg = unop_operation<FORTRAN_CEILING,
+						   eval_op_f_ceil>;
+using fortran_ceil_operation_2arg = fortran_kind_2arg<FORTRAN_CEILING,
+						      eval_op_f_ceil>;
+using fortran_floor_operation_1arg = unop_operation<FORTRAN_FLOOR,
+						    eval_op_f_floor>;
+using fortran_floor_operation_2arg = fortran_kind_2arg<FORTRAN_FLOOR,
+						       eval_op_f_floor>;
 using fortran_kind_operation = unop_operation<UNOP_FORTRAN_KIND,
 					      eval_op_f_kind>;
 using fortran_allocated_operation = unop_operation<UNOP_FORTRAN_ALLOCATED,
@@ -152,31 +278,16 @@ using fortran_array_size_1arg = unop_operation<FORTRAN_ARRAY_SIZE,
 					       eval_op_f_array_size>;
 using fortran_array_size_2arg = binop_operation<FORTRAN_ARRAY_SIZE,
 						eval_op_f_array_size>;
+using fortran_array_size_3arg = fortran_kind_3arg<FORTRAN_ARRAY_SIZE,
+						  eval_op_f_array_size>;
 using fortran_array_shape_operation = unop_operation<UNOP_FORTRAN_SHAPE,
 						     eval_op_f_array_shape>;
-
-/* The Fortran "complex" operation.  */
-class fortran_cmplx_operation
-  : public tuple_holding_operation<operation_up, operation_up>
-{
-public:
-
-  using tuple_holding_operation::tuple_holding_operation;
-
-  value *evaluate (struct type *expect_type,
-		   struct expression *exp,
-		   enum noside noside) override
-  {
-    value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
-    value *arg2 = std::get<1> (m_storage)->evaluate (value_type (arg1),
-						     exp, noside);
-    return eval_op_f_cmplx (expect_type, exp, noside, BINOP_FORTRAN_CMPLX,
-			    arg1, arg2);
-  }
-
-  enum exp_opcode opcode () const override
-  { return BINOP_FORTRAN_CMPLX; }
-};
+using fortran_cmplx_operation_1arg = unop_operation<FORTRAN_CMPLX,
+						    eval_op_f_cmplx>;
+using fortran_cmplx_operation_2arg = binop_operation<FORTRAN_CMPLX,
+						     eval_op_f_cmplx>;
+using fortran_cmplx_operation_3arg = fortran_kind_3arg<FORTRAN_CMPLX,
+						     eval_op_f_cmplx>;
 
 /* OP_RANGE for Fortran.  */
 class fortran_range_operation
@@ -273,6 +384,21 @@ class fortran_bound_2arg
   { return std::get<0> (m_storage); }
 };
 
+/* Three-argument form of Fortran ubound/lbound intrinsics.  */
+class fortran_bound_3arg
+  : public tuple_holding_operation<exp_opcode, operation_up, operation_up,
+				   type *>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (type *expect_type, expression *exp, noside noside) override;
+
+  exp_opcode opcode () const override
+  { return std::get<0> (m_storage); }
+};
+
 /* Implement STRUCTOP_STRUCT for Fortran.  */
 class fortran_structop_operation
   : public structop_base_operation
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index c062754ae4..38b94d4340 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -90,6 +90,18 @@ static void push_kind_type (LONGEST val, struct type *type);
 
 static struct type *convert_to_kind_type (struct type *basetype, int kind);
 
+static void wrap_unop_intrinsic (exp_opcode opcode);
+
+static void wrap_binop_intrinsic (exp_opcode opcode);
+
+static void wrap_ternop_intrinsic (exp_opcode opcode);
+
+template<typename T>
+static void fortran_wrap2_kind (type *base_type);
+
+template<typename T>
+static void fortran_wrap3_kind (type *base_type);
+
 using namespace expr;
 %}
 
@@ -181,7 +193,7 @@ static int parse_number (struct parser_state *, const char *, int,
 
 %token <opcode> ASSIGN_MODIFY
 %token <opcode> UNOP_INTRINSIC BINOP_INTRINSIC
-%token <opcode> UNOP_OR_BINOP_INTRINSIC
+%token <opcode> UNOP_OR_BINOP_INTRINSIC UNOP_OR_BINOP_OR_TERNOP_INTRINSIC
 
 %left ','
 %left ABOVE_COMMA
@@ -248,54 +260,6 @@ exp	:	KIND '(' exp ')'       %prec UNARY
 			{ pstate->wrap<fortran_kind_operation> (); }
 	;
 
-exp	:	UNOP_OR_BINOP_INTRINSIC '('
-			{ pstate->start_arglist (); }
-		one_or_two_args ')'
-			{
-			  int n = pstate->end_arglist ();
-			  gdb_assert (n == 1 || n == 2);
-			  if ($1 == FORTRAN_ASSOCIATED)
-			    {
-			      if (n == 1)
-				pstate->wrap<fortran_associated_1arg> ();
-			      else
-				pstate->wrap2<fortran_associated_2arg> ();
-			    }
-			  else if ($1 == FORTRAN_ARRAY_SIZE)
-			    {
-			      if (n == 1)
-				pstate->wrap<fortran_array_size_1arg> ();
-			      else
-				pstate->wrap2<fortran_array_size_2arg> ();
-			    }
-			  else
-			    {
-			      std::vector<operation_up> args
-				= pstate->pop_vector (n);
-			      gdb_assert ($1 == FORTRAN_LBOUND
-					  || $1 == FORTRAN_UBOUND);
-			      operation_up op;
-			      if (n == 1)
-				op.reset
-				  (new fortran_bound_1arg ($1,
-							   std::move (args[0])));
-			      else
-				op.reset
-				  (new fortran_bound_2arg ($1,
-							   std::move (args[0]),
-							   std::move (args[1])));
-			      pstate->push (std::move (op));
-			    }
-			}
-	;
-
-one_or_two_args
-	:	exp
-			{ pstate->arglist_len = 1; }
-	|	exp ',' exp
-			{ pstate->arglist_len = 2; }
-	;
-
 /* No more explicit array operators, we treat everything in F77 as 
    a function call.  The disambiguation as to whether we are 
    doing a subscript operation or a function call is done 
@@ -314,50 +278,56 @@ exp	:	exp '('
 
 exp	:	UNOP_INTRINSIC '(' exp ')'
 			{
-			  switch ($1)
+			  wrap_unop_intrinsic ($1);
+			}
+	;
+
+exp	:	BINOP_INTRINSIC '(' exp ',' exp ')'
+			{
+			  wrap_binop_intrinsic ($1);
+			}
+	;
+
+exp	:	UNOP_OR_BINOP_INTRINSIC '('
+			{ pstate->start_arglist (); }
+		arglist ')'
+			{
+			  const int n = pstate->end_arglist ();
+
+			  switch (n)
 			    {
-			    case UNOP_ABS:
-			      pstate->wrap<fortran_abs_operation> ();
-			      break;
-			    case UNOP_FORTRAN_FLOOR:
-			      pstate->wrap<fortran_floor_operation> ();
-			      break;
-			    case UNOP_FORTRAN_CEILING:
-			      pstate->wrap<fortran_ceil_operation> ();
+			    case 1:
+			      wrap_unop_intrinsic ($1);
 			      break;
-			    case UNOP_FORTRAN_ALLOCATED:
-			      pstate->wrap<fortran_allocated_operation> ();
-			      break;
-			    case UNOP_FORTRAN_RANK:
-			      pstate->wrap<fortran_rank_operation> ();
-			      break;
-			    case UNOP_FORTRAN_SHAPE:
-			      pstate->wrap<fortran_array_shape_operation> ();
-			      break;
-			    case UNOP_FORTRAN_LOC:
-			      pstate->wrap<fortran_loc_operation> ();
+			    case 2:
+			      wrap_binop_intrinsic ($1);
 			      break;
 			    default:
-			      gdb_assert_not_reached ("unhandled intrinsic");
+			      gdb_assert_not_reached
+				("wrong number of arguments for intrinsics");
 			    }
 			}
-	;
 
-exp	:	BINOP_INTRINSIC '(' exp ',' exp ')'
+exp	:	UNOP_OR_BINOP_OR_TERNOP_INTRINSIC '('
+			{ pstate->start_arglist (); }
+		arglist ')'
 			{
-			  switch ($1)
+			  const int n = pstate->end_arglist ();
+
+			  switch (n)
 			    {
-			    case BINOP_MOD:
-			      pstate->wrap2<fortran_mod_operation> ();
+			    case 1:
+			      wrap_unop_intrinsic ($1);
 			      break;
-			    case BINOP_FORTRAN_MODULO:
-			      pstate->wrap2<fortran_modulo_operation> ();
+			    case 2:
+			      wrap_binop_intrinsic ($1);
 			      break;
-			    case BINOP_FORTRAN_CMPLX:
-			      pstate->wrap2<fortran_cmplx_operation> ();
+			    case 3:
+			      wrap_ternop_intrinsic ($1);
 			      break;
 			    default:
-			      gdb_assert_not_reached ("unhandled intrinsic");
+			      gdb_assert_not_reached
+				("wrong number of arguments for intrinsics");
 			    }
 			}
 	;
@@ -835,6 +805,176 @@ name_not_typename :	NAME
 
 %%
 
+/* Called to match intrinsic function calls with one argument to their
+   respective implementation and push the operation.  */
+
+static void
+wrap_unop_intrinsic (exp_opcode code)
+{
+  switch (code)
+    {
+    case UNOP_ABS:
+      pstate->wrap<fortran_abs_operation> ();
+      break;
+    case FORTRAN_FLOOR:
+      pstate->wrap<fortran_floor_operation_1arg> ();
+      break;
+    case FORTRAN_CEILING:
+      pstate->wrap<fortran_ceil_operation_1arg> ();
+      break;
+    case UNOP_FORTRAN_ALLOCATED:
+      pstate->wrap<fortran_allocated_operation> ();
+      break;
+    case UNOP_FORTRAN_RANK:
+      pstate->wrap<fortran_rank_operation> ();
+      break;
+    case UNOP_FORTRAN_SHAPE:
+      pstate->wrap<fortran_array_shape_operation> ();
+      break;
+    case UNOP_FORTRAN_LOC:
+      pstate->wrap<fortran_loc_operation> ();
+      break;
+    case FORTRAN_ASSOCIATED:
+      pstate->wrap<fortran_associated_1arg> ();
+      break;
+    case FORTRAN_ARRAY_SIZE:
+      pstate->wrap<fortran_array_size_1arg> ();
+      break;
+    case FORTRAN_CMPLX:
+      pstate->wrap<fortran_cmplx_operation_1arg> ();
+      break;
+    case FORTRAN_LBOUND:
+    case FORTRAN_UBOUND:
+      pstate->push_new<fortran_bound_1arg>
+	(code, pstate->pop ());
+	break;
+    default:
+      gdb_assert_not_reached ("unhandled intrinsic");
+    }
+}
+
+/* Called to match intrinsic function calls with two arguments to their
+   respective implementation and push the operation.  */
+
+static void
+wrap_binop_intrinsic (exp_opcode code)
+{
+  switch (code)
+    {
+    case FORTRAN_FLOOR:
+      fortran_wrap2_kind<fortran_floor_operation_2arg>
+	(parse_f_type (pstate)->builtin_integer);
+      break;
+    case FORTRAN_CEILING:
+      fortran_wrap2_kind<fortran_ceil_operation_2arg>
+	(parse_f_type (pstate)->builtin_integer);
+      break;
+    case BINOP_MOD:
+      pstate->wrap2<fortran_mod_operation> ();
+      break;
+    case BINOP_FORTRAN_MODULO:
+      pstate->wrap2<fortran_modulo_operation> ();
+      break;
+    case FORTRAN_CMPLX:
+      pstate->wrap2<fortran_cmplx_operation_2arg> ();
+      break;
+    case FORTRAN_ASSOCIATED:
+      pstate->wrap2<fortran_associated_2arg> ();
+      break;
+    case FORTRAN_ARRAY_SIZE:
+      pstate->wrap2<fortran_array_size_2arg> ();
+      break;
+    case FORTRAN_LBOUND:
+    case FORTRAN_UBOUND:
+      pstate->push_new<fortran_bound_2arg>
+	(code, pstate->pop (), pstate->pop ());
+      break;
+    default:
+      gdb_assert_not_reached ("unhandled intrinsic");
+    }
+}
+
+/* Called to match intrinsic function calls with three arguments to their
+   respective implementation and push the operation.  */
+
+static void
+wrap_ternop_intrinsic (exp_opcode code)
+{
+  switch (code)
+    {
+    case FORTRAN_LBOUND:
+    case FORTRAN_UBOUND:
+      {
+	operation_up kind_arg = pstate->pop ();
+	operation_up arg2 = pstate->pop ();
+	operation_up arg1 = pstate->pop ();
+
+	value *val = kind_arg->evaluate (nullptr, pstate->expout.get (),
+					 EVAL_AVOID_SIDE_EFFECTS);
+	gdb_assert (val != nullptr);
+
+	type *follow_type
+	  = convert_to_kind_type (parse_f_type (pstate)->builtin_integer,
+				  value_as_long (val));
+
+	pstate->push_new<fortran_bound_3arg> (code, std::move (arg1),
+					      std::move (arg2), follow_type);
+      }
+      break;
+    case FORTRAN_ARRAY_SIZE:
+      fortran_wrap3_kind<fortran_array_size_3arg>
+	(parse_f_type (pstate)->builtin_integer);
+      break;
+    case FORTRAN_CMPLX:
+      fortran_wrap3_kind<fortran_cmplx_operation_3arg>
+	(parse_f_type (pstate)->builtin_complex);
+      break;
+    default:
+      gdb_assert_not_reached ("unhandled intrinsic");
+    }
+}
+
+/* A helper that pops two operations (similar to wrap2), evaluates the last one
+   assuming it is a kind parameter, and wraps them in some other operation
+   pushing it to the stack.  */
+
+template<typename T>
+static void
+fortran_wrap2_kind (type *base_type)
+{
+  operation_up kind_arg = pstate->pop ();
+  operation_up arg = pstate->pop ();
+
+  value *val = kind_arg->evaluate (nullptr, pstate->expout.get (),
+				   EVAL_AVOID_SIDE_EFFECTS);
+  gdb_assert (val != nullptr);
+
+  type *follow_type = convert_to_kind_type (base_type, value_as_long (val));
+
+  pstate->push_new<T> (std::move (arg), follow_type);
+}
+
+/* A helper that pops three operations, evaluates the last one assuming it is a
+   kind parameter, and wraps them in some other operation pushing it to the
+   stack.  */
+
+template<typename T>
+static void
+fortran_wrap3_kind (type *base_type)
+{
+  operation_up kind_arg = pstate->pop ();
+  operation_up arg2 = pstate->pop ();
+  operation_up arg1 = pstate->pop ();
+
+  value *val = kind_arg->evaluate (nullptr, pstate->expout.get (),
+				   EVAL_AVOID_SIDE_EFFECTS);
+  gdb_assert (val != nullptr);
+
+  type *follow_type = convert_to_kind_type (base_type, value_as_long (val));
+
+  pstate->push_new<T> (std::move (arg1), std::move (arg2), follow_type);
+}
+
 /* Take care of parsing a number (anything that starts with a digit).
    Set yylval and return the token type; update lexptr.
    LEN is the number of characters in it.  */
@@ -1166,16 +1306,16 @@ static const token f_keywords[] =
   { "kind", KIND, OP_NULL, false },
   { "abs", UNOP_INTRINSIC, UNOP_ABS, false },
   { "mod", BINOP_INTRINSIC, BINOP_MOD, false },
-  { "floor", UNOP_INTRINSIC, UNOP_FORTRAN_FLOOR, false },
-  { "ceiling", UNOP_INTRINSIC, UNOP_FORTRAN_CEILING, false },
+  { "floor", UNOP_OR_BINOP_INTRINSIC, FORTRAN_FLOOR, false },
+  { "ceiling", UNOP_OR_BINOP_INTRINSIC, FORTRAN_CEILING, false },
   { "modulo", BINOP_INTRINSIC, BINOP_FORTRAN_MODULO, false },
-  { "cmplx", BINOP_INTRINSIC, BINOP_FORTRAN_CMPLX, false },
-  { "lbound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_LBOUND, false },
-  { "ubound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_UBOUND, false },
+  { "cmplx", UNOP_OR_BINOP_OR_TERNOP_INTRINSIC, FORTRAN_CMPLX, false },
+  { "lbound", UNOP_OR_BINOP_OR_TERNOP_INTRINSIC, FORTRAN_LBOUND, false },
+  { "ubound", UNOP_OR_BINOP_OR_TERNOP_INTRINSIC, FORTRAN_UBOUND, false },
   { "allocated", UNOP_INTRINSIC, UNOP_FORTRAN_ALLOCATED, false },
   { "associated", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ASSOCIATED, false },
   { "rank", UNOP_INTRINSIC, UNOP_FORTRAN_RANK, false },
-  { "size", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ARRAY_SIZE, false },
+  { "size", UNOP_OR_BINOP_OR_TERNOP_INTRINSIC, FORTRAN_ARRAY_SIZE, false },
   { "shape", UNOP_INTRINSIC, UNOP_FORTRAN_SHAPE, false },
   { "loc", UNOP_INTRINSIC, UNOP_FORTRAN_LOC, false },
 };
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index bea24ce0ca..20af3096b1 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -133,9 +133,9 @@ fortran_bounds_all_dims (bool lbound_p,
   /* Allocate a result value of the correct type.  */
   struct type *range
     = create_static_range_type (nullptr,
-				builtin_type (gdbarch)->builtin_int,
+				builtin_f_type (gdbarch)->builtin_integer,
 				1, ndimensions);
-  struct type *elm_type = builtin_type (gdbarch)->builtin_long_long;
+  struct type *elm_type = builtin_f_type (gdbarch)->builtin_integer;
   struct type *result_type = create_array_type (nullptr, elm_type, range);
   struct value *result = allocate_value (result_type);
 
@@ -170,13 +170,12 @@ fortran_bounds_all_dims (bool lbound_p,
 
 /* Return the lower bound (when LBOUND_P is true) or the upper bound (when
    LBOUND_P is false) for dimension DIM_VAL (which must be an integer) of
-   ARRAY (which must be an array).  GDBARCH is the current architecture.  */
+   ARRAY (which must be an array).  RESULT_TYPE corresponds to the type kind
+   the function should be evaluated in.  */
 
-static struct value *
-fortran_bounds_for_dimension (bool lbound_p,
-			      struct gdbarch *gdbarch,
-			      struct value *array,
-			      struct value *dim_val)
+static value *
+fortran_bounds_for_dimension (bool lbound_p, value *array, value *dim_val,
+			      type* result_type)
 {
   /* Check the requested dimension is valid for this array.  */
   type *array_type = check_typedef (value_type (array));
@@ -190,9 +189,6 @@ fortran_bounds_for_dimension (bool lbound_p,
 	error (_("UBOUND dimension must be from 1 to %d"), ndimensions);
     }
 
-  /* The type for the result.  */
-  struct type *bound_type = builtin_type (gdbarch)->builtin_long_long;
-
   /* Walk the dimensions backwards, due to the ordering in which arrays are
      laid out the first dimension is the most inner.  */
   for (int i = ndimensions - 1; i >= 0; --i)
@@ -208,7 +204,7 @@ fortran_bounds_for_dimension (bool lbound_p,
 	  else
 	    b = f77_get_upperbound (array_type);
 
-	  return value_from_longest (bound_type, b);
+	  return value_from_longest (result_type, b);
 	}
 
       /* Peel off another dimension of the array.  */
@@ -578,8 +574,8 @@ eval_op_f_associated (struct type *expect_type,
 }
 
 /* Implement FORTRAN_ARRAY_SIZE expression, this corresponds to the 'SIZE'
-   keyword.  Both GDBARCH and LANG are extracted from the expression being
-   evaluated.  ARRAY is the value that should be an array, though this will
+   keyword.  RESULT_TYPE corresponds to the type kind the function should be
+   evaluated in, ARRAY is the value that should be an array, though this will
    not have been checked before calling this function.  DIM is optional, if
    present then it should be an integer identifying a dimension of the
    array to ask about.  As with ARRAY the validity of DIM is not checked
@@ -588,9 +584,8 @@ eval_op_f_associated (struct type *expect_type,
    Return either the total number of elements in ARRAY (when DIM is
    nullptr), or the number of elements in dimension DIM.  */
 
-static struct value *
-fortran_array_size (struct gdbarch *gdbarch, const language_defn *lang,
-		    struct value *array, struct value *dim_val = nullptr)
+static value *
+fortran_array_size (value *array, value *dim_val, type *result_type)
 {
   /* Check that ARRAY is the correct type.  */
   struct type *array_type = check_typedef (value_type (array));
@@ -642,8 +637,6 @@ fortran_array_size (struct gdbarch *gdbarch, const language_defn *lang,
       array_type = TYPE_TARGET_TYPE (array_type);
     }
 
-  struct type *result_type
-    = builtin_f_type (gdbarch)->builtin_integer;
   return value_from_longest (result_type, result);
 }
 
@@ -657,7 +650,9 @@ eval_op_f_array_size (struct type *expect_type,
 		      struct value *arg1)
 {
   gdb_assert (opcode == FORTRAN_ARRAY_SIZE);
-  return fortran_array_size (exp->gdbarch, exp->language_defn, arg1);
+
+  type *result_type = builtin_f_type (exp->gdbarch)->builtin_integer;
+  return fortran_array_size (arg1, nullptr, result_type);
 }
 
 /* See f-exp.h.  */
@@ -671,7 +666,21 @@ eval_op_f_array_size (struct type *expect_type,
 		      struct value *arg2)
 {
   gdb_assert (opcode == FORTRAN_ARRAY_SIZE);
-  return fortran_array_size (exp->gdbarch, exp->language_defn, arg1, arg2);
+
+  type *result_type = builtin_f_type (exp->gdbarch)->builtin_integer;
+  return fortran_array_size (arg1, arg2, result_type);
+}
+
+/* See f-exp.h.  */
+
+value *eval_op_f_array_size (type *expect_type, expression *exp, noside noside,
+			     exp_opcode opcode, value *arg1, value *arg2,
+			     type *kind_arg)
+{
+  gdb_assert (opcode == FORTRAN_ARRAY_SIZE);
+  gdb_assert (kind_arg->code () == TYPE_CODE_INT);
+
+  return fortran_array_size (arg1, arg2, kind_arg);
 }
 
 /* Implement UNOP_FORTRAN_SHAPE expression.  Both GDBARCH and LANG are
@@ -820,7 +829,22 @@ eval_op_f_mod (struct type *expect_type, struct expression *exp,
   error (_("MOD of type %s not supported"), TYPE_SAFE_NAME (type));
 }
 
-/* A helper function for UNOP_FORTRAN_CEILING.  */
+/* A helper function for the different FORTRAN_CEILING overloads.  Calculates
+   CEILING for ARG1 (a float type) and returns it in the requested kind type
+   RESULT_TYPE.  */
+
+static value *
+fortran_ceil_operation (value *arg1, type *result_type)
+{
+  if (value_type (arg1)->code () != TYPE_CODE_FLT)
+    error (_("argument to CEILING must be of type float"));
+  double val = target_float_to_host_double (value_contents (arg1).data (),
+					    value_type (arg1));
+  val = ceil (val);
+  return value_from_longest (result_type, val);
+}
+
+/* A helper function for FORTRAN_CEILING.  */
 
 struct value *
 eval_op_f_ceil (struct type *expect_type, struct expression *exp,
@@ -828,32 +852,59 @@ eval_op_f_ceil (struct type *expect_type, struct expression *exp,
 		enum exp_opcode opcode,
 		struct value *arg1)
 {
-  struct type *type = value_type (arg1);
-  if (type->code () != TYPE_CODE_FLT)
-    error (_("argument to CEILING must be of type float"));
-  double val
-    = target_float_to_host_double (value_contents (arg1).data (),
-				   value_type (arg1));
-  val = ceil (val);
-  return value_from_host_double (type, val);
+  gdb_assert (opcode == FORTRAN_CEILING);
+  type *result_type = builtin_f_type (exp->gdbarch)->builtin_integer;
+  return fortran_ceil_operation (arg1, result_type);
 }
 
-/* A helper function for UNOP_FORTRAN_FLOOR.  */
+/* A helper function for FORTRAN_CEILING.  */
 
-struct value *
-eval_op_f_floor (struct type *expect_type, struct expression *exp,
-		 enum noside noside,
-		 enum exp_opcode opcode,
-		 struct value *arg1)
+value *
+eval_op_f_ceil (type *expect_type, expression *exp, noside noside,
+		exp_opcode opcode, value *arg1, type *kind_arg)
 {
-  struct type *type = value_type (arg1);
-  if (type->code () != TYPE_CODE_FLT)
+  gdb_assert (opcode == FORTRAN_CEILING);
+  gdb_assert (kind_arg->code () == TYPE_CODE_INT);
+  return fortran_ceil_operation (arg1, kind_arg);
+}
+
+/* A helper function for the different FORTRAN_FLOOR overloads.  Calculates
+   FLOOR for ARG1 (a float type) and returns it in the requested kind type
+   RESULT_TYPE.  */
+
+static value *
+fortran_floor_operation (value *arg1, type *result_type)
+{
+  if (value_type (arg1)->code () != TYPE_CODE_FLT)
     error (_("argument to FLOOR must be of type float"));
-  double val
-    = target_float_to_host_double (value_contents (arg1).data (),
-				   value_type (arg1));
+  double val = target_float_to_host_double (value_contents (arg1).data (),
+					    value_type (arg1));
   val = floor (val);
-  return value_from_host_double (type, val);
+  return value_from_longest (result_type, val);
+}
+
+/* A helper function for FORTRAN_FLOOR.  */
+
+struct value *
+eval_op_f_floor (struct type *expect_type, struct expression *exp,
+		enum noside noside,
+		enum exp_opcode opcode,
+		struct value *arg1)
+{
+  gdb_assert (opcode == FORTRAN_FLOOR);
+  type *result_type = builtin_f_type (exp->gdbarch)->builtin_integer;
+  return fortran_floor_operation (arg1, result_type);
+}
+
+/* A helper function for FORTRAN_FLOOR.  */
+
+struct value *
+eval_op_f_floor (type *expect_type, expression *exp, noside noside,
+		 exp_opcode opcode, value *arg1, type *kind_arg)
+{
+  gdb_assert (opcode == FORTRAN_FLOOR);
+  gdb_assert (kind_arg->code () == TYPE_CODE_INT);
+  return fortran_floor_operation (arg1, kind_arg);
 }
 
 /* A helper function for BINOP_FORTRAN_MODULO.  */
@@ -896,7 +947,25 @@ eval_op_f_modulo (struct type *expect_type, struct expression *exp,
   error (_("MODULO of type %s not supported"), TYPE_SAFE_NAME (type));
 }
 
-/* A helper function for BINOP_FORTRAN_CMPLX.  */
+/* A helper function for FORTRAN_CMPLX.  */
+
+value *
+eval_op_f_cmplx (type *expect_type, expression *exp, noside noside,
+		 exp_opcode opcode, value *arg1)
+{
+  gdb_assert (opcode == FORTRAN_CMPLX);
+
+  type *result_type = builtin_f_type (exp->gdbarch)->builtin_complex;
+
+  if (value_type (arg1)->code () == TYPE_CODE_COMPLEX)
+    return value_cast (result_type, arg1);
+  else
+    return value_literal_complex (arg1,
+				  value_zero (value_type (arg1), not_lval),
+				  result_type);
+}
+
+/* A helper function for FORTRAN_CMPLX.  */
 
 struct value *
 eval_op_f_cmplx (struct type *expect_type, struct expression *exp,
@@ -904,8 +973,28 @@ eval_op_f_cmplx (struct type *expect_type, struct expression *exp,
 		 enum exp_opcode opcode,
 		 struct value *arg1, struct value *arg2)
 {
-  struct type *type = builtin_f_type(exp->gdbarch)->builtin_complex_s16;
-  return value_literal_complex (arg1, arg2, type);
+  if (value_type (arg1)->code () == TYPE_CODE_COMPLEX
+      || value_type (arg2)->code () == TYPE_CODE_COMPLEX)
+    error (_("Types of arguments for CMPLX called with more then one argument "
+	     "must be REAL or INTEGER"));
+
+  type *result_type = builtin_f_type (exp->gdbarch)->builtin_complex;
+  return value_literal_complex (arg1, arg2, result_type);
+}
+
+/* A helper function for FORTRAN_CMPLX.  */
+
+value *
+eval_op_f_cmplx (type *expect_type, expression *exp, noside noside,
+		 exp_opcode opcode, value *arg1, value *arg2, type *kind_arg)
+{
+  gdb_assert (kind_arg->code () == TYPE_CODE_COMPLEX);
+  if (value_type (arg1)->code () == TYPE_CODE_COMPLEX
+      || value_type (arg2)->code () == TYPE_CODE_COMPLEX)
+    error (_("Types of arguments for CMPLX called with more then one argument "
+	     "must be REAL or INTEGER"));
+
+  return value_literal_complex (arg1, arg2, kind_arg);
 }
 
 /* A helper function for UNOP_FORTRAN_KIND.  */
@@ -1478,8 +1567,8 @@ fortran_bound_2arg::evaluate (struct type *expect_type,
 
   /* User asked for the bounds of a specific dimension of the array.  */
   value *arg2 = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
-  struct type *type = check_typedef (value_type (arg2));
-  if (type->code () != TYPE_CODE_INT)
+  type *type_arg2 = check_typedef (value_type (arg2));
+  if (type_arg2->code () != TYPE_CODE_INT)
     {
       if (lbound_p)
 	error (_("LBOUND second argument should be an integer"));
@@ -1487,7 +1576,34 @@ fortran_bound_2arg::evaluate (struct type *expect_type,
 	error (_("UBOUND second argument should be an integer"));
     }
 
-  return fortran_bounds_for_dimension (lbound_p, exp->gdbarch, arg1, arg2);
+  type *result_type = builtin_f_type (exp->gdbarch)->builtin_integer;
+  return fortran_bounds_for_dimension (lbound_p, arg1, arg2, result_type);
+}
+
+value *
+fortran_bound_3arg::evaluate (type *expect_type,
+			      expression *exp,
+			      noside noside)
+{
+  const bool lbound_p = std::get<0> (m_storage) == FORTRAN_LBOUND;
+  value *arg1 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+  fortran_require_array (value_type (arg1), lbound_p);
+
+  /* User asked for the bounds of a specific dimension of the array.  */
+  value *arg2 = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+  type *type_arg2 = check_typedef (value_type (arg2));
+  if (type_arg2->code () != TYPE_CODE_INT)
+    {
+      if (lbound_p)
+	error (_("LBOUND second argument should be an integer"));
+      else
+	error (_("UBOUND second argument should be an integer"));
+    }
+
+  type *kind_arg = std::get<3> (m_storage);
+  gdb_assert (kind_arg->code () == TYPE_CODE_INT);
+
+  return fortran_bounds_for_dimension (lbound_p, arg1, arg2, kind_arg);
 }
 
 /* Implement STRUCTOP_STRUCT for Fortran.  See operation::evaluate in
diff --git a/gdb/std-operator.def b/gdb/std-operator.def
index baaa5947e2..a5c990c704 100644
--- a/gdb/std-operator.def
+++ b/gdb/std-operator.def
@@ -375,19 +375,21 @@ OP (OP_F77_UNDETERMINED_ARGLIST)
 
 /* Single operand builtins.  */
 OP (UNOP_FORTRAN_KIND)
-OP (UNOP_FORTRAN_FLOOR)
-OP (UNOP_FORTRAN_CEILING)
 OP (UNOP_FORTRAN_ALLOCATED)
 OP (UNOP_FORTRAN_RANK)
 OP (UNOP_FORTRAN_SHAPE)
 OP (UNOP_FORTRAN_LOC)
 
 /* Two operand builtins.  */
-OP (BINOP_FORTRAN_CMPLX)
 OP (BINOP_FORTRAN_MODULO)
 
 /* Builtins that take one or two operands.  */
+OP (FORTRAN_CEILING)
+OP (FORTRAN_FLOOR)
+OP (FORTRAN_ASSOCIATED)
+
+/* Builtins that take one, two or three operands.  */
 OP (FORTRAN_LBOUND)
 OP (FORTRAN_UBOUND)
-OP (FORTRAN_ASSOCIATED)
+OP (FORTRAN_CMPLX)
 OP (FORTRAN_ARRAY_SIZE)
diff --git a/gdb/testsuite/gdb.fortran/intrinsics.exp b/gdb/testsuite/gdb.fortran/intrinsics.exp
index c4020737c1..29cff35c55 100644
--- a/gdb/testsuite/gdb.fortran/intrinsics.exp
+++ b/gdb/testsuite/gdb.fortran/intrinsics.exp
@@ -61,15 +61,37 @@ gdb_test "p mod (-8, 5)" " = -3"
 gdb_test "p mod (8, -5)" " = 3"
 gdb_test "p mod (-8, -5)" " = -3"
 
-# Test CEILING
+# Test CEILING and FLOOR.
 
+gdb_test "p floor (3.7)" " = 3"
 gdb_test "p ceiling (3.7)" " = 4"
-gdb_test "p ceiling (-3.7)" " = -3"
 
-# Test FLOOR
-
-gdb_test "p floor (3.7)" " = 3"
 gdb_test "p floor (-3.7)" " = -4"
+gdb_test "p ceiling (-3.7)" " = -3"
+
+gdb_test "p ceiling (3)" "argument to CEILING must be of type float"
+gdb_test "p floor (1)" "argument to FLOOR must be of type float"
+
+foreach op {floor ceiling} {
+    gdb_test "ptype ${op} (3.7)" "integer\\*4"
+    gdb_test "ptype ${op} (-1.1, 1)" "type = integer\\*1"
+    gdb_test "ptype ${op} (-1.1, 2)" "type = integer\\*2"
+    gdb_test "ptype ${op} (-1.1, 3)" "unsupported kind 3 for type integer\\*4"
+    gdb_test "ptype ${op} (-1.1, 4)" "type = integer\\*4"
+    gdb_test "ptype ${op} (-1.1, 8)" "type = integer\\*8"
+
+    # The actual overflow behavior differs in ifort/ifx/gfortran - this tests
+    # the GDB internal overflow behavior - not a compiler dependent one.
+    gdb_test "p ${op} (129.0,1)" " = -127"
+    gdb_test "p ${op} (129.0,2)" " = 129"
+    gdb_test "p ${op} (-32770.0,1)" " = -2"
+    gdb_test "p ${op} (-32770.0,2)" " = 32766"
+    gdb_test "p ${op} (-32770.0,4)" " = -32770"
+    gdb_test "p ${op} (2147483652.0,1)" " = 4"
+    gdb_test "p ${op} (2147483652.0,2)" " = 4"
+    gdb_test "p ${op} (2147483652.0,4)" " = -2147483644"
+    gdb_test "p ${op} (2147483652.0,8)" " = 2147483652"
+}
 
 # Test MODULO
 
@@ -85,6 +107,20 @@ gdb_test "ptype MODULO (3.0,2.0)" "type = real\\*8"
 
 gdb_test "p CMPLX (4.1, 2.0)" " = \\(4.$decimal,2\\)"
 
+gdb_test "p cmplx (4,4)" "= \\(4,4\\)"
+gdb_test "ptype cmplx (4,4)" "= complex\\*4"
+gdb_test "p cmplx (-14,-4)" "= \\(-14,-4\\)"
+gdb_test "p cmplx (4,4,4)" "\\(4,4\\)"
+gdb_test "p cmplx (4,4,8)" "\\(4,4\\)"
+gdb_test "p cmplx (4,4,16)" "\\(4,4\\)"
+gdb_test "ptype cmplx (4,4,4)" "= complex\\*4"
+gdb_test "ptype cmplx (4,4,8)" "= complex\\*8"
+gdb_test "ptype cmplx (4,4,16)" "= complex\\*16"
+
+gdb_test "p cmplx (4,4,1)" "unsupported kind 1 for type complex\\*4"
+gdb_test "p cmplx (4,4,-1)" "unsupported kind -1 for type complex\\*4"
+gdb_test "p cmplx (4,4,2)" "unsupported kind 2 for type complex\\*4"
+
 # Test LOC
 
 gdb_test "p/x LOC(l)" "= $hex"
diff --git a/gdb/testsuite/gdb.fortran/lbound-ubound.F90 b/gdb/testsuite/gdb.fortran/lbound-ubound.F90
index 37145724a3..aa5be85bb5 100644
--- a/gdb/testsuite/gdb.fortran/lbound-ubound.F90
+++ b/gdb/testsuite/gdb.fortran/lbound-ubound.F90
@@ -17,8 +17,8 @@
   call do_test (lbound (ARRAY), ubound (ARRAY))
 
 subroutine do_test (lb, ub)
-  integer, dimension (:) :: lb
-  integer, dimension (:) :: ub
+  integer*4, dimension (:) :: lb
+  integer*4, dimension (:) :: ub
 
   print *, ""
   print *, "Expected GDB Output:"
@@ -51,8 +51,8 @@ end subroutine do_test
 program test
   interface
      subroutine do_test (lb, ub)
-       integer, dimension (:) :: lb
-       integer, dimension (:) :: ub
+       integer*4, dimension (:) :: lb
+       integer*4, dimension (:) :: ub
      end subroutine do_test
   end interface
 
@@ -70,11 +70,34 @@ program test
 
   integer, dimension (:), pointer :: pointer1d => null()
 
+  integer, parameter :: b1 = 127 - 10
+  integer, parameter :: b1_o = 127 + 2
+  integer, parameter :: b2 = 32767 - 10
+  integer, parameter :: b2_o = 32767 + 3
+  integer*8, parameter :: b4 = 2147483647 - 10
+  integer*8, parameter :: b4_o = 2147483647 + 5
+
+  integer, allocatable :: array_1d_1bytes_overflow (:)
+  integer, allocatable :: array_1d_2bytes_overflow (:)
+  integer, allocatable :: array_1d_4bytes_overflow (:)
+  integer, allocatable :: array_2d_1byte_overflow (:,:)
+  integer, allocatable :: array_2d_2bytes_overflow (:,:)
+  integer, allocatable :: array_3d_1byte_overflow (:,:,:)
+
   ! Allocate or associate any variables as needed.
   allocate (other (-5:4, -2:7))
   pointer2d => tarray
   pointer1d => array (3, 2:5)
 
+  allocate (array_1d_1bytes_overflow (-b1_o:-b1))
+  allocate (array_1d_2bytes_overflow (b2:b2_o))
+  allocate (array_1d_4bytes_overflow (-b4_o:-b4))
+
+  allocate (array_2d_1byte_overflow (-b1_o:-b1,b1:b1_o))
+  allocate (array_2d_2bytes_overflow (b2:b2_o,-b2_o:b2))
+
+  allocate (array_3d_1byte_overflow (-b1_o:-b1,b1:b1_o,-b1_o:-b1))
+
   DO_TEST (neg_array)
   DO_TEST (neg_array (-7:-3,-5:-4))
   DO_TEST (array)
@@ -90,9 +113,27 @@ program test
   DO_TEST (pointer2d)
   DO_TEST (tarray)
 
+  DO_TEST (array_1d_1bytes_overflow)
+  DO_TEST (array_1d_2bytes_overflow)
+
+  DO_TEST (array_1d_4bytes_overflow)
+  DO_TEST (array_2d_1byte_overflow)
+  DO_TEST (array_2d_2bytes_overflow)
+  DO_TEST (array_3d_1byte_overflow)
+
   ! All done.  Deallocate.
+  print *, "" ! Breakpoint before deallocate.
   deallocate (other)
 
+  deallocate (array_3d_1byte_overflow)
+
+  deallocate (array_2d_2bytes_overflow)
+  deallocate (array_2d_1byte_overflow)
+
+  deallocate (array_1d_4bytes_overflow)
+  deallocate (array_1d_2bytes_overflow)
+  deallocate (array_1d_1bytes_overflow)
+
   ! GDB catches this final breakpoint to indicate the end of the test.
   print *, "" ! Final Breakpoint.
 
diff --git a/gdb/testsuite/gdb.fortran/lbound-ubound.exp b/gdb/testsuite/gdb.fortran/lbound-ubound.exp
index 671b251c79..38b6d46e22 100644
--- a/gdb/testsuite/gdb.fortran/lbound-ubound.exp
+++ b/gdb/testsuite/gdb.fortran/lbound-ubound.exp
@@ -42,9 +42,10 @@ if {![gdb_is_target_native]} {
 gdb_test_no_output "nosharedlibrary"
 
 gdb_breakpoint [gdb_get_line_number "Test Breakpoint"]
+gdb_breakpoint [gdb_get_line_number "Breakpoint before deallocate\."]
 gdb_breakpoint [gdb_get_line_number "Final Breakpoint"]
 
-set found_final_breakpoint false
+set found_dealloc_breakpoint false
 
 # We place a limit on the number of tests that can be run, just in
 # case something goes wrong, and GDB gets stuck in an loop here.
@@ -68,8 +69,8 @@ while { $test_count < 500 } {
 		set func_name "show_elem"
 		exp_continue
 	    }
-	    -re "! Final Breakpoint" {
-		set found_final_breakpoint true
+	    -re "! Breakpoint before deallocate" {
+		set found_dealloc_breakpoint true
 		exp_continue
 	    }
 	    -re "$gdb_prompt $" {
@@ -77,7 +78,7 @@ while { $test_count < 500 } {
 	    }
 	}
 
-	if ($found_final_breakpoint) {
+	if ($found_dealloc_breakpoint) {
 	    break
 	}
 
@@ -194,10 +195,26 @@ while { $test_count < 500 } {
     }
 }
 
+gdb_assert {$found_dealloc_breakpoint} "ran all compiled in tests"
+
+# Test the kind parameter of ubound and lbound a few times.
+gdb_test "p lbound(array_1d_1bytes_overflow, 1, 1)" "= 127"
+gdb_test "p lbound(array_1d_1bytes_overflow, 1, 2)" "= -129"
+gdb_test "p ubound(array_1d_1bytes_overflow, 1, 1)" "= -117"
+
+gdb_test "p lbound(array_1d_2bytes_overflow, 1, 2)" "= 32757"
+gdb_test "p ubound(array_1d_2bytes_overflow, 1, 2)" "= -32766"
+gdb_test "p ubound(array_1d_2bytes_overflow, 1, 4)" "= 32770"
+
+gdb_test "p lbound(array_1d_4bytes_overflow, 1, 4)" "= 2147483644"
+gdb_test "p lbound(array_1d_4bytes_overflow, 1, 8)" "= -2147483652"
+gdb_test "p ubound(array_1d_4bytes_overflow, 1, 4)" "= -2147483637"
+gdb_test "p lbound(array_1d_4bytes_overflow)" "= \\(2147483644\\)"
+
 # Ensure we reached the final breakpoint.  If more tests have been added
 # to the test script, and this starts failing, then the safety 'while'
 # loop above might need to be increased.
-gdb_assert {$found_final_breakpoint} "reached final breakpoint"
+gdb_continue_to_breakpoint "Final Breakpoint"
 
 # Now for some final tests.  This is mostly testing that GDB gives the
 # correct errors in certain cases.
diff --git a/gdb/testsuite/gdb.fortran/size.exp b/gdb/testsuite/gdb.fortran/size.exp
index 81b58405cf..fb49e286e5 100644
--- a/gdb/testsuite/gdb.fortran/size.exp
+++ b/gdb/testsuite/gdb.fortran/size.exp
@@ -29,28 +29,33 @@ if ![fortran_runto_main] {
     return -1
 }
 
-gdb_breakpoint [gdb_get_line_number "Test Breakpoint"]
+gdb_breakpoint [gdb_get_line_number "Test Breakpoint 1"]
+gdb_breakpoint [gdb_get_line_number "Test Breakpoint 2"]
+gdb_breakpoint [gdb_get_line_number "Test Breakpoint 3"]
+gdb_breakpoint [gdb_get_line_number "Test Breakpoint 4"]
+
+gdb_breakpoint [gdb_get_line_number "Breakpoint before deallocate\."]
 gdb_breakpoint [gdb_get_line_number "Final Breakpoint"]
 
 # We place a limit on the number of tests that can be run, just in
 # case something goes wrong, and GDB gets stuck in an loop here.
-set found_final_breakpoint false
+set found_dealloc_breakpoint false
 set test_count 0
-while { $test_count < 500 } {
+while { $test_count < 600 } {
     with_test_prefix "test $test_count" {
 	incr test_count
 
 	gdb_test_multiple "continue" "continue" {
-	    -re -wrap "! Test Breakpoint" {
+	    -re -wrap "! Test Breakpoint \[0-9\]" {
 		# We can run a test from here.
 	    }
-	    -re -wrap "! Final Breakpoint" {
+	    -re -wrap "! Breakpoint before deallocate\." {
 		# We're done with the tests.
-		set found_final_breakpoint true
+		set found_dealloc_breakpoint true
 	    }
 	}
 
-	if ($found_final_breakpoint) {
+	if ($found_dealloc_breakpoint) {
 	    break
 	}
 
@@ -61,26 +66,81 @@ while { $test_count < 500 } {
 	# as a test.
 	set command ""
 	gdb_test_multiple "up" "up" {
-	    -re -wrap "\r\n\[0-9\]+\[ \t\]+call test_size \\((\[^\r\n\]+)\\)" {
+	    -re -wrap "\r\n\[0-9\]+\[ \t\]+call test_size_\[0-9\]* \\((\[^\r\n\]+)\\)" {
 		set command $expect_out(1,string)
 	    }
 	}
 
 	gdb_assert { ![string equal $command ""] } "found a command to run"
 
-	gdb_test "p $command" " = $answer"
+	gdb_test_multiple "p $command" "p $command" {
+	    -re -wrap " = $answer" {
+		pass $gdb_test_name
+	    }
+	    -re -wrap "SIZE can only be applied to arrays" {
+		# Because of ifort's DWARF pointer representation we need to
+		# aditionally de-reference Fortran pointers.
+		regsub -all "\\(" $command "\(\*" command_deref
+		gdb_test "p $command_deref" " = $answer"
+		pass $gdb_test_name
+	    }
+	}
+    }
+}
+
+# Since the behavior of size (array_1d, 2) differs for different compilers and
+# neither of them seem to behave as expected (gfortran prints apparently random
+# things, ifort would print 0), we test for GDB's error message instead.
+gdb_assert {$found_dealloc_breakpoint} "ran all compiled in tests"
+
+foreach var {array_1d_p array_2d_p allocatable_array_1d \
+		 allocatable_array_2d} {
+    gdb_test_multiple "p size ($var, 3)" "p size ($var, 3)" {
+	-re -wrap "DIM argument to SIZE must be between 1 and \[1-2\]" {
+	    pass $gdb_test_name
+	}
+	-re -wrap "SIZE can only be applied to arrays" {
+	    # Because of ifort's DWARF pointer representation we need to
+	    # aditionally de-reference Fortran pointers.
+	    gdb_test "p size (*$var, 3)" \
+		"DIM argument to SIZE must be between 1 and \[1-2\]"
+	    pass $gdb_test_name
+	}
     }
 }
 
+# For wrong kind parameters GBD and compiler behavior differs.  Here,
+# gfortran/ifort/ifx would already throw a compiler error - a user might still
+# try and call size with something like -3 as kind parameter, so we test GDB's
+# error handling here.
+
+foreach var {array_1d_p array_2d_p allocatable_array_1d \
+		 allocatable_array_2d} {
+    gdb_test "p size ($var, 1, -10)" \
+	"unsupported kind -10 for type integer\\*4"
+    gdb_test "p size ($var, 1, 123)" \
+	"unsupported kind 123 for type integer\\*4"
+}
+
 # Ensure we reached the final breakpoint.  If more tests have been added
 # to the test script, and this starts failing, then the safety 'while'
 # loop above might need to be increased.
-gdb_assert {$found_final_breakpoint} "ran all compiled in tests"
+gdb_continue_to_breakpoint "Final Breakpoint"
 
 foreach var {array_1d_p array_2d_p allocatable_array_1d \
 		 allocatable_array_2d} {
-    gdb_test "p size ($var)" \
-	"SIZE can only be used on allocated/associated arrays"
+    gdb_test_multiple "p size ($var)" "p size ($var)" {
+	-re -wrap "SIZE can only be used on allocated/associated arrays" {
+	    pass $gdb_test_name
+	}
+	-re -wrap "SIZE can only be applied to arrays" {
+	    # Because of ifort's DWARF pointer representation we need to
+	    # aditionally de-reference Fortran pointers.
+	    gdb_test "p size (*$var)" \
+		"Attempt to take contents of a not associated pointer\."
+	    pass $gdb_test_name
+	}
+    }
 }
 
 foreach var {an_integer a_real} {
diff --git a/gdb/testsuite/gdb.fortran/size.f90 b/gdb/testsuite/gdb.fortran/size.f90
index 76f71ab60f..c924d84673 100644
--- a/gdb/testsuite/gdb.fortran/size.f90
+++ b/gdb/testsuite/gdb.fortran/size.f90
@@ -28,74 +28,184 @@ program test
   integer, allocatable :: allocatable_array_1d (:)
   integer, allocatable :: allocatable_array_2d (:,:)
 
+  integer, parameter :: b1_o = 127 + 1
+  integer, parameter :: b2_o = 32767 + 3
+  integer*8, parameter :: b4_o = 2147483647 + 5
+
+  integer, allocatable :: array_1d_1byte_overflow (:)
+  integer, allocatable :: array_1d_2bytes_overflow (:)
+  integer, allocatable :: array_1d_4bytes_overflow (:)
+  integer, allocatable :: array_2d_1byte_overflow (:,:)
+  integer, allocatable :: array_2d_2bytes_overflow (:,:)
+  integer, allocatable :: array_3d_1byte_overflow (:,:,:)
+
   ! Loop counters.
   integer :: s1, s2
 
+  allocate (array_1d_1byte_overflow (1:b1_o))
+  allocate (array_1d_2bytes_overflow (1:b2_o))
+  allocate (array_1d_4bytes_overflow (1:b4_o))
+
+  allocate (array_2d_1byte_overflow (1:b1_o, 1:b1_o))
+  allocate (array_2d_2bytes_overflow (1:b2_o, 1:b2_o))
+
+  allocate (array_3d_1byte_overflow (1:b1_o, 1:b1_o, 1:b1_o))
+
+
   ! The start of the tests.
-  call test_size (size (array_1d))
-  call test_size (size (array_1d, 1))
+  call test_size_4 (size (array_1d))
+  call test_size_4 (size (array_1d, 1))
   do s1=1, SIZE (array_1d, 1), 1
-     call test_size (size (array_1d (1:10:s1)))
-     call test_size (size (array_1d (1:10:s1), 1))
-     call test_size (size (array_1d (10:1:-s1)))
-     call test_size (size (array_1d (10:1:-s1), 1))
+     call test_size_4 (size (array_1d (1:10:s1)))
+     call test_size_4 (size (array_1d (1:10:s1), 1))
+     call test_size_4 (size (array_1d (10:1:-s1)))
+     call test_size_4 (size (array_1d (10:1:-s1), 1))
   end do
 
   do s2=1, SIZE (array_2d, 2), 1
      do s1=1, SIZE (array_2d, 1), 1
-        call test_size (size (array_2d (1:4:s1, 1:3:s2)))
-        call test_size (size (array_2d (4:1:-s1, 1:3:s2)))
-        call test_size (size (array_2d (1:4:s1, 3:1:-s2)))
-        call test_size (size (array_2d (4:1:-s1, 3:1:-s2)))
-
-        call test_size (size (array_2d (1:4:s1, 1:3:s2), 1))
-        call test_size (size (array_2d (4:1:-s1, 1:3:s2), 1))
-        call test_size (size (array_2d (1:4:s1, 3:1:-s2), 1))
-        call test_size (size (array_2d (4:1:-s1, 3:1:-s2), 1))
-
-        call test_size (size (array_2d (1:4:s1, 1:3:s2), 2))
-        call test_size (size (array_2d (4:1:-s1, 1:3:s2), 2))
-        call test_size (size (array_2d (1:4:s1, 3:1:-s2), 2))
-        call test_size (size (array_2d (4:1:-s1, 3:1:-s2), 2))
+        call test_size_4 (size (array_2d (1:4:s1, 1:3:s2)))
+        call test_size_4 (size (array_2d (4:1:-s1, 1:3:s2)))
+        call test_size_4 (size (array_2d (1:4:s1, 3:1:-s2)))
+        call test_size_4 (size (array_2d (4:1:-s1, 3:1:-s2)))
+
+        call test_size_4 (size (array_2d (1:4:s1, 1:3:s2), 1))
+        call test_size_4 (size (array_2d (4:1:-s1, 1:3:s2), 1))
+        call test_size_4 (size (array_2d (1:4:s1, 3:1:-s2), 1))
+        call test_size_4 (size (array_2d (4:1:-s1, 3:1:-s2), 1))
+
+        call test_size_4 (size (array_2d (1:4:s1, 1:3:s2), 2))
+        call test_size_4 (size (array_2d (4:1:-s1, 1:3:s2), 2))
+        call test_size_4 (size (array_2d (1:4:s1, 3:1:-s2), 2))
+        call test_size_4 (size (array_2d (4:1:-s1, 3:1:-s2), 2))
      end do
   end do
 
   allocate (allocatable_array_1d (-10:-5))
-  call test_size (size (allocatable_array_1d))
+  call test_size_4 (size (allocatable_array_1d))
   do s1=1, SIZE (allocatable_array_1d, 1), 1
-     call test_size (size (allocatable_array_1d (-10:-5:s1)))
-     call test_size (size (allocatable_array_1d (-5:-10:-s1)))
+     call test_size_4 (size (allocatable_array_1d (-10:-5:s1)))
+     call test_size_4 (size (allocatable_array_1d (-5:-10:-s1)))
 
-     call test_size (size (allocatable_array_1d (-10:-5:s1), 1))
-     call test_size (size (allocatable_array_1d (-5:-10:-s1), 1))
+     call test_size_4 (size (allocatable_array_1d (-10:-5:s1), 1))
+     call test_size_4 (size (allocatable_array_1d (-5:-10:-s1), 1))
   end do
 
   allocate (allocatable_array_2d (-3:3, 8:12))
   do s2=1, SIZE (allocatable_array_2d, 2), 1
      do s1=1, SIZE (allocatable_array_2d, 1), 1
-        call test_size (size (allocatable_array_2d (-3:3:s1, 8:12:s2)))
-        call test_size (size (allocatable_array_2d (3:-3:-s1, 8:12:s2)))
-        call test_size (size (allocatable_array_2d (-3:3:s1, 12:8:-s2)))
-        call test_size (size (allocatable_array_2d (3:-3:-s1, 12:8:-s2)))
-
-        call test_size (size (allocatable_array_2d (-3:3:s1, 8:12:s2), 1))
-        call test_size (size (allocatable_array_2d (3:-3:-s1, 8:12:s2), 2))
-        call test_size (size (allocatable_array_2d (-3:3:s1, 12:8:-s2), 1))
-        call test_size (size (allocatable_array_2d (3:-3:-s1, 12:8:-s2), 2))
+        call test_size_4 (size (allocatable_array_2d (-3:3:s1, 8:12:s2)))
+        call test_size_4 (size (allocatable_array_2d (3:-3:-s1, 8:12:s2)))
+        call test_size_4 (size (allocatable_array_2d (-3:3:s1, 12:8:-s2)))
+        call test_size_4 (size (allocatable_array_2d (3:-3:-s1, 12:8:-s2)))
+
+        call test_size_4 (size (allocatable_array_2d (-3:3:s1, 8:12:s2), 1))
+        call test_size_4 (size (allocatable_array_2d (3:-3:-s1, 8:12:s2), 2))
+        call test_size_4 (size (allocatable_array_2d (-3:3:s1, 12:8:-s2), 1))
+        call test_size_4 (size (allocatable_array_2d (3:-3:-s1, 12:8:-s2), 2))
      end do
   end do
 
   array_1d_p => array_1d
-  call test_size (size (array_1d_p))
-  call test_size (size (array_1d_p, 1))
+  call test_size_4 (size (array_1d_p))
+  call test_size_4 (size (array_1d_p, 1))
 
   array_2d_p => array_2d
-  call test_size (size (array_2d_p))
-  call test_size (size (array_2d_p, 1))
-  call test_size (size (array_2d_p, 2))
+  call test_size_4 (size (array_2d_p))
+  call test_size_4 (size (array_2d_p, 1))
+  call test_size_4 (size (array_2d_p, 2))
+
+  ! Test kind parameters - compiler requires these to be compile time constant
+  ! so sadly there cannot be a loop over the kinds 1, 2, 4, 8.
+  call test_size_4 (size (array_1d_1byte_overflow))
+  call test_size_4 (size (array_1d_2bytes_overflow))
+
+  call test_size_4 (size (array_1d_1byte_overflow, 1))
+  call test_size_4 (size (array_1d_2bytes_overflow, 1))
+
+  call test_size_4 (size (array_1d_4bytes_overflow))
+  call test_size_4 (size (array_1d_4bytes_overflow, 1))
+
+  call test_size_4 (size (array_2d_1byte_overflow, 1))
+  call test_size_4 (size (array_2d_1byte_overflow, 2))
+  call test_size_4 (size (array_2d_2bytes_overflow, 1))
+  call test_size_4 (size (array_2d_2bytes_overflow, 2))
+
+  call test_size_4 (size (array_3d_1byte_overflow, 1))
+  call test_size_4 (size (array_3d_1byte_overflow, 2))
+  call test_size_4 (size (array_3d_1byte_overflow, 3))
+
+  ! Kind 1.
+
+  call test_size_1 (size (array_1d_1byte_overflow, 1, 1))
+  call test_size_1 (size (array_1d_2bytes_overflow, 1, 1))
+  call test_size_1 (size (array_1d_4bytes_overflow, 1, 1))
+
+  call test_size_1 (size (array_2d_1byte_overflow, 1, 1))
+  call test_size_1 (size (array_2d_1byte_overflow, 2, 1))
+  call test_size_1 (size (array_2d_2bytes_overflow, 1, 1))
+  call test_size_1 (size (array_2d_2bytes_overflow, 2, 1))
+
+  call test_size_1 (size (array_3d_1byte_overflow, 1, 1))
+  call test_size_1 (size (array_3d_1byte_overflow, 2, 1))
+  call test_size_1 (size (array_3d_1byte_overflow, 3, 1))
+
+  ! Kind 2.
+  call test_size_2 (size (array_1d_1byte_overflow, 1, 2))
+  call test_size_2 (size (array_1d_2bytes_overflow, 1, 2))
+  call test_size_2 (size (array_1d_4bytes_overflow, 1, 2))
+
+  call test_size_2 (size (array_2d_1byte_overflow, 1, 2))
+  call test_size_2 (size (array_2d_1byte_overflow, 2, 2))
+  call test_size_2 (size (array_2d_2bytes_overflow, 1, 2))
+  call test_size_2 (size (array_2d_2bytes_overflow, 2, 2))
+
+  call test_size_2 (size (array_3d_1byte_overflow, 1, 2))
+  call test_size_2 (size (array_3d_1byte_overflow, 2, 2))
+  call test_size_2 (size (array_3d_1byte_overflow, 3, 2))
+
+  ! Kind 4.
+  call test_size_4 (size (array_1d_1byte_overflow, 1, 4))
+  call test_size_4 (size (array_1d_2bytes_overflow, 1, 4))
+  call test_size_4 (size (array_1d_4bytes_overflow, 1, 4))
+
+  call test_size_4 (size (array_2d_1byte_overflow, 1, 4))
+  call test_size_4 (size (array_2d_1byte_overflow, 2, 4))
+  call test_size_4 (size (array_2d_2bytes_overflow, 1, 4))
+  call test_size_4 (size (array_2d_2bytes_overflow, 2, 4))
+
+  call test_size_4 (size (array_3d_1byte_overflow, 1, 4))
+  call test_size_4 (size (array_3d_1byte_overflow, 2, 4))
+  call test_size_4 (size (array_3d_1byte_overflow, 3, 4))
+
+  ! Kind 8.
+  call test_size_8 (size (array_1d_1byte_overflow, 1, 8))
+  call test_size_8 (size (array_1d_2bytes_overflow, 1, 8))
+  call test_size_8 (size (array_1d_4bytes_overflow, 1, 8))
+
+  call test_size_8 (size (array_2d_1byte_overflow, 1, 8))
+  call test_size_8 (size (array_2d_1byte_overflow, 2, 8))
+  call test_size_8 (size (array_2d_2bytes_overflow, 1, 8))
+  call test_size_8 (size (array_2d_2bytes_overflow, 2, 8))
+
+  call test_size_8 (size (array_3d_1byte_overflow, 1, 8))
+  call test_size_8 (size (array_3d_1byte_overflow, 2, 8))
+  call test_size_8 (size (array_3d_1byte_overflow, 3, 8))
+
+  print *, "" ! Breakpoint before deallocate.
 
   deallocate (allocatable_array_1d)
   deallocate (allocatable_array_2d)
+
+  deallocate (array_3d_1byte_overflow)
+
+  deallocate (array_2d_2bytes_overflow)
+  deallocate (array_2d_1byte_overflow)
+
+  deallocate (array_1d_4bytes_overflow)
+  deallocate (array_1d_2bytes_overflow)
+  deallocate (array_1d_1byte_overflow)
+
   array_1d_p => null ()
   array_2d_p => null ()
 
@@ -108,11 +218,28 @@ program test
   print *, allocated (allocatable_array_2d)
 
 contains
+  subroutine test_size_1 (answer)
+    integer*1 :: answer
+
+    print *, answer	! Test Breakpoint 1
+  end subroutine test_size_1
+
+  subroutine test_size_2 (answer)
+    integer*2 :: answer
+
+    print *, answer	! Test Breakpoint 2
+  end subroutine test_size_2
+
+  subroutine test_size_4 (answer)
+    integer*4 :: answer
+
+    print *, answer	! Test Breakpoint 3
+  end subroutine test_size_4
 
-  subroutine test_size (answer)
-    integer :: answer
+  subroutine test_size_8 (answer)
+    integer*8 :: answer
 
-    print *,answer	! Test Breakpoint
-  end subroutine test_size
+    print *, answer	! Test Breakpoint 4
+  end subroutine test_size_8
 
 end program test
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
                   ` (8 preceding siblings ...)
  2022-03-09 10:39 ` [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-04-07 14:49   ` Tom Tromey
  2022-04-07 14:50   ` Tom Tromey
  2022-03-09 10:39 ` [PATCH 11/11] gdb/doc: add section about fortran intrinsic functions and types Nils-Christian Kempke
  10 siblings, 2 replies; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

When working on the files I noted that there was no actual test for a
COMPLEX built from two INTEGERS.  I added that now for completion.

gdb/testsuite/ChangeLog:
2022-03-02  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* gdb.fortran/complex.exp: Test complex from integer.
	* gdb.fortran/complex.f90: Dito.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/testsuite/gdb.fortran/complex.exp | 6 ++++++
 gdb/testsuite/gdb.fortran/complex.f90 | 7 ++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.fortran/complex.exp b/gdb/testsuite/gdb.fortran/complex.exp
index f4a80fbf78..ca41c81236 100644
--- a/gdb/testsuite/gdb.fortran/complex.exp
+++ b/gdb/testsuite/gdb.fortran/complex.exp
@@ -41,6 +41,7 @@ gdb_test "print c8" " = \\(321,-22\\)"
 gdb_test "print dc" " = \\(321,-22\\)"
 
 gdb_test "print c16" " = \\(-874,19\\)"
+gdb_test "print ci" " = \\(-4,12\\)"
 
 gdb_test "whatis c" "type = $complex4"
 gdb_test "print \$_creal (c)" " = 1000"
@@ -70,3 +71,8 @@ with_test_prefix "c16" {
     gdb_test "whatis \$" " = real\\*16"
 }
 
+gdb_test "whatis ci" "type = $complex4"
+gdb_test "print \$_creal (ci)" " = -4"
+with_test_prefix "ci" {
+    gdb_test "whatis \$" " = real\\*4"
+}
diff --git a/gdb/testsuite/gdb.fortran/complex.f90 b/gdb/testsuite/gdb.fortran/complex.f90
index 5c9491df02..cd1acecad5 100644
--- a/gdb/testsuite/gdb.fortran/complex.f90
+++ b/gdb/testsuite/gdb.fortran/complex.f90
@@ -17,8 +17,9 @@ program test_complex
   real*4 r4a, r4b
   real*8 r8a, r8b
   real*16 r16a, r16b
+  integer ia, ib
 
-  complex c
+  complex c, ci
   complex(kind=4) c4
   complex(kind=8) c8
   double complex dc
@@ -30,15 +31,19 @@ program test_complex
   r8b = -22
   r16a = -874
   r16b = 19
+  ia = -4
+  ib = 12
 
   c = cmplx(r4a,r4b)
   c4 = cmplx(r4a,r4b)
   c8 = cmplx(r8a, r8b)
   dc = cmplx(r8a, r8b)
   c16 = cmplx(r16a, r16b)
+  ci = cmplx(ia, ib)
 
   print *, c, c4, c8, dc, c16	! stop
   print *, r4a, r4b
   print *, r8a, r8b
   print *, r16a, r16b
+  print *, ia, ib
 end program test_complex
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* [PATCH 11/11] gdb/doc: add section about fortran intrinsic functions and types
  2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
                   ` (9 preceding siblings ...)
  2022-03-09 10:39 ` [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test Nils-Christian Kempke
@ 2022-03-09 10:39 ` Nils-Christian Kempke
  2022-03-09 12:49   ` Eli Zaretskii
  10 siblings, 1 reply; 28+ messages in thread
From: Nils-Christian Kempke @ 2022-03-09 10:39 UTC (permalink / raw)
  To: gdb-patches

The earlier version of this document had no sections about the
available Fortran intrinsic functions or the Fortran builtin types.

I added two sections 'Fortran intrinsics' and 'Fortran types' to
document the available Fortran language features.

gdb/doc/ChangeLog:
2022-03-03  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* gdb.texinfo (Fortran): Add sections about Fortran builtin
	types and Fortran intrinsic functions.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/doc/gdb.texinfo | 138 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 128 insertions(+), 10 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 132b94c648..1f10a77c25 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17174,8 +17174,8 @@ vector data types.
 @subsection Fortran
 @cindex Fortran-specific support in @value{GDBN}
 
-@value{GDBN} can be used to debug programs written in Fortran, but it
-currently supports only the features of Fortran 77 language.
+@value{GDBN} can be used to debug programs written in Fortran.  Note, that not
+all Fortran language features are available yet.
 
 @cindex trailing underscore, in Fortran symbols
 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
@@ -17185,11 +17185,68 @@ will need to refer to variables and functions with a trailing
 underscore.
 
 @menu
-* Fortran Operators::           Fortran operators and expressions
 * Fortran Defaults::            Default settings for Fortran
+* Fortran Types::               Fortran builtin types
+* Fortran Operators::           Fortran operators and expressions
+* Fortran Intrinsics::          Fortran intrinsic functions
 * Special Fortran Commands::    Special @value{GDBN} commands for Fortran
 @end menu
 
+@node Fortran Defaults
+@subsubsection Fortran Defaults
+
+@cindex Fortran Defaults
+
+Fortran symbols are usually case-insensitive, so @value{GDBN} by
+default uses case-insensitive matches for Fortran symbols.  You can
+change that with the @samp{set case-insensitive} command, see
+@ref{Symbols}, for the details.
+
+@node Fortran Types
+@subsubsection Fortran Types
+
+@cindex Fortran Types
+
+In Fortran the primitive data-types have an associated KIND type parameter,
+written as 'TYPE*KINDPARAM', 'TYPE(KIND=KINDPARAM)', or in the
+@value{GDBN}-only dialect 'TYPE_KINDPARAM'.  A concrete example would be
+'REAL*4', 'REAL(KIND=4)', and 'REAL_4'.  The kind of a type can be retrieved by
+using the intrinsic function KIND(), see @ref{Fortran Intrinsics}.
+
+Generally, the actual implementation of the KIND type parameter is compiler
+specific.  In @value{GDBN} the kind parameter is implemented in accordance to
+its use in the @sc{gnu} gfortran compiler.  Here, the kind parameter for a
+given TYPE specifies its size in memory - a Fortran Integer*4 or
+Integer(kind=4) would be an integer type occupying 4 bytes of memory.  An
+exception to this rule is the COMPLEX type for which the kind of the type
+does not specify its entire size, but the size of each of the two REAL's it is
+composed of.  A COMPLEX*4 would thus consist of two REAL*4s and occupy 8 bytes
+of memory.
+
+For every type there is also a default kind associated with it, e.g. 'Integer'
+in @value{GDBN} will internally be an Integer*4 (see the table below for
+default types).  The default types are the same as in @sc{gnu} compilers but
+note, that the @sc{gnu} default types can actually be changed by compiler flags
+such as '-fdefault-integer-8' and '-fdefault-real-8'.
+
+Not every kind parameter is valid for every type and in @value{GDBN} the
+following type kinds are available.
+
+@table @code
+@item INTEGER
+Integer*1, Integer*2, Integer*4, Integer*8, and Integer = Integer*4.
+
+@item LOGICAL
+Locigal*1, Locigal*2, Locigal*4, Locigal*8, and Locigal = Locigal*4.
+
+@item REAL
+Real*4, Real*8, Real*16, and Real = Real*4.
+
+@item COMPLEX
+Complex*4, Complex*8, Complex*16, and Complex = Complex*4.
+
+@end table
+
 @node Fortran Operators
 @subsubsection Fortran Operators and Expressions
 
@@ -17219,15 +17276,76 @@ to set breakpoints on subroutines nested in modules or in other
 subroutines (internal subroutines).
 @end table
 
-@node Fortran Defaults
-@subsubsection Fortran Defaults
+@node Fortran Intrinsics
+@subsubsection Fortran Intrinsics
 
-@cindex Fortran Defaults
+@cindex Fortran Intrinsics
 
-Fortran symbols are usually case-insensitive, so @value{GDBN} by
-default uses case-insensitive matches for Fortran symbols.  You can
-change that with the @samp{set case-insensitive} command, see
-@ref{Symbols}, for the details.
+Fortran provides a large set of intrinsic procedures.  @value{GDBN} implements
+an incomplete subset of those procedures and their overloads.  Some of these
+procedures take an optional KIND parameter, see @ref{Fortran Types}.
+
+@table @code
+@item ABS(A)
+Computes the absolut value of its operand A.  Currently not supported for
+COMPLEX arguments.
+
+@item ALLOCATE(ARRAY)
+Returns whether ARRAY is allocated or not.
+
+@item ASSOCIATED(POINTER [, TARGET])
+Returns the association status of the pointer POINTER or if TARGET is present
+whether POINTER is associated with the target TARGET.
+
+@item CEILING(A [, KIND])
+Computes the least integer greater than or equal to A.  The optional parameter
+KIND specifies the kind of the return type INTEGER(KIND).
+
+@item CMPLX(X [, Y [, KIND]])
+Returns a complex number where X is converted to the real component.  If Y is
+present it is converted to the imaginary component.  If Y is not present then
+the imaginary component is set to 0.0 except if X itself is of COMPLEX type.
+The optional parameter KIND specifies the kind of the return type
+COMPLEX(KIND).
+
+@item FLOOR(A [, KIND])
+Computes the greatest integer less than or equal to A.  The optional parameter
+KIND specifies the kind of the return type INTEGER(KIND).
+
+@item KIND(A)
+Returns the kind value of the argument A, see @ref{Fortran Types}.
+
+@item LBOUND(ARRAY [, DIM [, KIND]])
+Returns the lower bounds of an array, or a single lower bound along the DIM
+dimension if present.  The optional parameter KIND specifies the kind of the
+return type INTEGER(KIND).
+
+@item LOC(X)
+Returns the address of X as an Integer.
+
+@item MOD(A, P)
+Computes the remainder of the division of A by P.
+
+@item MODULO(A,P)
+Computes the A modulo P.
+
+@item RANK(A)
+Returns the rank of a scalar or array (scalars have rank 0).
+
+@item SHAPE(A)
+Returns the shape of a scalar or array (scalars have shape '()').
+
+@item SIZE(ARRAY[, DIM [, KIND]])
+Returns the extent of ARRAY along a specified dimension DIM, or the total
+number of elements in ARRAY if DIM is absent.  The optional parameter KIND
+specifies the kind of the return type INTEGER(KIND).
+
+@item UBOUND(ARRAY [, DIM [, KIND]])
+Returns the upper bounds of an array, or a single lower bound along the DIM
+dimension if present.  The optional parameter KIND specifies the kind of the
+return type INTEGER(KIND).
+
+@end table
 
 @node Special Fortran Commands
 @subsubsection Special Fortran Commands
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* Re: [PATCH 11/11] gdb/doc: add section about fortran intrinsic functions and types
  2022-03-09 10:39 ` [PATCH 11/11] gdb/doc: add section about fortran intrinsic functions and types Nils-Christian Kempke
@ 2022-03-09 12:49   ` Eli Zaretskii
  2022-03-09 17:01     ` Kempke, Nils-Christian
  0 siblings, 1 reply; 28+ messages in thread
From: Eli Zaretskii @ 2022-03-09 12:49 UTC (permalink / raw)
  To: Nils-Christian Kempke; +Cc: gdb-patches

> Date: Wed,  9 Mar 2022 11:39:22 +0100
> From: Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org>
> 
> The earlier version of this document had no sections about the
> available Fortran intrinsic functions or the Fortran builtin types.
> 
> I added two sections 'Fortran intrinsics' and 'Fortran types' to
> document the available Fortran language features.

Thanks, see some comments below, mostly about markup.

> +In Fortran the primitive data-types have an associated KIND type parameter,
> +written as 'TYPE*KINDPARAM', 'TYPE(KIND=KINDPARAM)', or in the
> +@value{GDBN}-only dialect 'TYPE_KINDPARAM'.  A concrete example would be
> +'REAL*4', 'REAL(KIND=4)', and 'REAL_4'.  The kind of a type can be retrieved by
> +using the intrinsic function KIND(), see @ref{Fortran Intrinsics}.

Some of the words you wrote in CAPS are actually meta-syntactic
variables, i.e. they aren't literal symbols, but rather stand for some
symbol.  Those should have the @var markup in Texinfo, and should be
spelled in lower-case letter.  In this case, I think the correct
markup will be this:

  In Fortran the primitive data-types have an associated @code{KIND}
  type parameter, written as @samp{@var{type}*@var{kindparam}},
  @samp{@var{type}(KIND=@var{kindparam})}, or in the @value{GDBN}-only
  dialect @samp{@var{type}_@var{kindparam}}.  A concrete example would
  be @samp{REAL*4}, @samp{REAL(KIND=4)}, and @samp{REAL_4}.  The kind
  of a type can be retrieved by using the intrinsic function @code{KIND},
  see @ref{Fortran Intrinsics}.

The above also fixes other issues with markup:

  . use @samp instead of manual quoting 'like this'
  . use @code{funcname} instead of funcname() to reference to a
    function (the latter looks like a call to the function with no
    arguments, which is not what you meant)

Please make such fixes elsewhere in the patch, there are other such
places.

> +Generally, the actual implementation of the KIND type parameter is compiler
> +specific.  In @value{GDBN} the kind parameter is implemented in accordance to
> +its use in the @sc{gnu} gfortran compiler.  Here, the kind parameter for a
> +given TYPE specifies its size in memory - a Fortran Integer*4 or
> +Integer(kind=4) would be an integer type occupying 4 bytes of
> memory.

Since "Integer*4" and Integer(kind=4) are literal pieces of code
(AFAIU), they should be in @code.

>                                                        An
> +exception to this rule is the COMPLEX type for which the kind of the type
> +does not specify its entire size, but the size of each of the two REAL's it is
> +composed of.  A COMPLEX*4 would thus consist of two REAL*4s and occupy 8 bytes
> +of memory.

Same here with the other data types.

> +note, that the @sc{gnu} default types can actually be changed by compiler flags
> +such as '-fdefault-integer-8' and '-fdefault-real-8'.

Instead of quoting command-line options by hand, please use the
@option markup.

> +Computes the absolut value of its operand A.  Currently not supported for
                ^^^^^^^
Typo: should be "absolute".  Also, I thing "argument" is better than
"operand" here.

"A" should be @var{a}, according to the same methodology as explained
above.

> +@item ALLOCATE(ARRAY)
> +Returns whether ARRAY is allocated or not.

@var{array}

> +@item ASSOCIATED(POINTER [, TARGET])
> +Returns the association status of the pointer POINTER or if TARGET is present
> +whether POINTER is associated with the target TARGET.

POINTER and TARGET should b @var{pointer} and @var{target}.

Same in other similar situations in your patch.

> +@item CMPLX(X [, Y [, KIND]])
> +Returns a complex number where X is converted to the real component.  If Y is
> +present it is converted to the imaginary component.  If Y is not present then
> +the imaginary component is set to 0.0 except if X itself is of COMPLEX type.
> +The optional parameter KIND specifies the kind of the return type
> +COMPLEX(KIND).

"0.0" should be in @code.

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

* RE: [PATCH 11/11] gdb/doc: add section about fortran intrinsic functions and types
  2022-03-09 12:49   ` Eli Zaretskii
@ 2022-03-09 17:01     ` Kempke, Nils-Christian
  0 siblings, 0 replies; 28+ messages in thread
From: Kempke, Nils-Christian @ 2022-03-09 17:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Hi Eli,

Yes I see, sorry for that, thanks!
I'll update this locally and wait for a review on the rest of the patch
before sending it as V2.

-Nils

> -----Original Message-----
> From: Eli Zaretskii <eliz@gnu.org>
> Sent: Wednesday, March 9, 2022 1:49 PM
> To: Kempke, Nils-Christian <nils-christian.kempke@intel.com>
> Cc: gdb-patches@sourceware.org
> Subject: Re: [PATCH 11/11] gdb/doc: add section about fortran intrinsic
> functions and types
> 
> > Date: Wed,  9 Mar 2022 11:39:22 +0100
> > From: Nils-Christian Kempke via Gdb-patches <gdb-
> patches@sourceware.org>
> >
> > The earlier version of this document had no sections about the
> > available Fortran intrinsic functions or the Fortran builtin types.
> >
> > I added two sections 'Fortran intrinsics' and 'Fortran types' to
> > document the available Fortran language features.
> 
> Thanks, see some comments below, mostly about markup.
> 
> > +In Fortran the primitive data-types have an associated KIND type
> parameter,
> > +written as 'TYPE*KINDPARAM', 'TYPE(KIND=KINDPARAM)', or in the
> > +@value{GDBN}-only dialect 'TYPE_KINDPARAM'.  A concrete example
> would be
> > +'REAL*4', 'REAL(KIND=4)', and 'REAL_4'.  The kind of a type can be
> retrieved by
> > +using the intrinsic function KIND(), see @ref{Fortran Intrinsics}.
> 
> Some of the words you wrote in CAPS are actually meta-syntactic
> variables, i.e. they aren't literal symbols, but rather stand for some
> symbol.  Those should have the @var markup in Texinfo, and should be
> spelled in lower-case letter.  In this case, I think the correct
> markup will be this:
> 
>   In Fortran the primitive data-types have an associated @code{KIND}
>   type parameter, written as @samp{@var{type}*@var{kindparam}},
>   @samp{@var{type}(KIND=@var{kindparam})}, or in the @value{GDBN}-
> only
>   dialect @samp{@var{type}_@var{kindparam}}.  A concrete example would
>   be @samp{REAL*4}, @samp{REAL(KIND=4)}, and @samp{REAL_4}.  The
> kind
>   of a type can be retrieved by using the intrinsic function @code{KIND},
>   see @ref{Fortran Intrinsics}.
> 
> The above also fixes other issues with markup:
> 
>   . use @samp instead of manual quoting 'like this'
>   . use @code{funcname} instead of funcname() to reference to a
>     function (the latter looks like a call to the function with no
>     arguments, which is not what you meant)
> 
> Please make such fixes elsewhere in the patch, there are other such
> places.
> 
> > +Generally, the actual implementation of the KIND type parameter is
> compiler
> > +specific.  In @value{GDBN} the kind parameter is implemented in
> accordance to
> > +its use in the @sc{gnu} gfortran compiler.  Here, the kind parameter for a
> > +given TYPE specifies its size in memory - a Fortran Integer*4 or
> > +Integer(kind=4) would be an integer type occupying 4 bytes of
> > memory.
> 
> Since "Integer*4" and Integer(kind=4) are literal pieces of code
> (AFAIU), they should be in @code.
> 
> >                                                        An
> > +exception to this rule is the COMPLEX type for which the kind of the type
> > +does not specify its entire size, but the size of each of the two REAL's it is
> > +composed of.  A COMPLEX*4 would thus consist of two REAL*4s and
> occupy 8 bytes
> > +of memory.
> 
> Same here with the other data types.
> 
> > +note, that the @sc{gnu} default types can actually be changed by compiler
> flags
> > +such as '-fdefault-integer-8' and '-fdefault-real-8'.
> 
> Instead of quoting command-line options by hand, please use the
> @option markup.
> 
> > +Computes the absolut value of its operand A.  Currently not supported for
>                 ^^^^^^^
> Typo: should be "absolute".  Also, I thing "argument" is better than
> "operand" here.
> 
> "A" should be @var{a}, according to the same methodology as explained
> above.
> 
> > +@item ALLOCATE(ARRAY)
> > +Returns whether ARRAY is allocated or not.
> 
> @var{array}
> 
> > +@item ASSOCIATED(POINTER [, TARGET])
> > +Returns the association status of the pointer POINTER or if TARGET is
> present
> > +whether POINTER is associated with the target TARGET.
> 
> POINTER and TARGET should b @var{pointer} and @var{target}.
> 
> Same in other similar situations in your patch.
> 
> > +@item CMPLX(X [, Y [, KIND]])
> > +Returns a complex number where X is converted to the real component.
> If Y is
> > +present it is converted to the imaginary component.  If Y is not present
> then
> > +the imaginary component is set to 0.0 except if X itself is of COMPLEX
> type.
> > +The optional parameter KIND specifies the kind of the return type
> > +COMPLEX(KIND).
> 
> "0.0" should be in @code.
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* Re: [PATCH 01/11] gdb/f-lang: add Integer*1 to Fortran builtin types
  2022-03-09 10:39 ` [PATCH 01/11] gdb/f-lang: add Integer*1 to Fortran builtin types Nils-Christian Kempke
@ 2022-04-07 14:28   ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:28 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> Add builtin_integer_s1 of size TARGET_CHAR_BIT to Fortran builtin types.

Looks good, but remember to drop the ChangeLog entries.

Tom

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

* Re: [PATCH 02/11] gdb/f-lang: remove hidden ^L characters
  2022-03-09 10:39 ` [PATCH 02/11] gdb/f-lang: remove hidden ^L characters Nils-Christian Kempke
@ 2022-04-07 14:28   ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:28 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> 	* gdb/f-lang.c: Remove ^L.

This is ok.  Normally these are for the benefit of Emacs users but the
code's also obviously fine without them.

Tom

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

* Re: [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types
  2022-03-09 10:39 ` [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types Nils-Christian Kempke
@ 2022-04-07 14:30   ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:30 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> The new behavior is

>   (gdb) ptype complex*8
>   complex*8
>   (gdb) ptype complex*4
>   complex*4

This looks good to me.  Thank you.

Tom

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

* Re: [PATCH 04/11] gdb/fortran: reformat build_fortran_types in f-lang.c
  2022-03-09 10:39 ` [PATCH 04/11] gdb/fortran: reformat build_fortran_types in f-lang.c Nils-Christian Kempke
@ 2022-04-07 14:30   ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:30 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> Add a few newlines after the type definitions and remove some
> unnecessary linebreaks.

Ok.

Tom

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

* Re: [PATCH 05/11] gdb/fortran: change default logical type to builtin_logical
  2022-03-09 10:39 ` [PATCH 05/11] gdb/fortran: change default logical type to builtin_logical Nils-Christian Kempke
@ 2022-04-07 14:32   ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:32 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> According to the Fortran standard, logical is of the size of a
> 'single numeric storage unit' (just like real and integer). For
> gfortran, flang and ifx/ifort this storage unit (or the default
> logical type) is of size kind 4, actually occupying 4 bytes of
> storage, and so the default type for logical expressions in
> Fortran should probably also be Logical*4 and not Logical*2.  I
> adapted GDB's behavior to be in line with
> gfortran/ifort/ifx/flang.

Looks good.

> -  lai->set_bool_type (builtin->builtin_logical_s2, "logical");
> +  lai->set_bool_type (builtin->builtin_logical, "logical");

Normally I'd suggest a comment here but the code seems more natural
after the patch.

Tom

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

* Re: [PATCH 06/11] gdb/fortran: clean-up Fortran intrinsic types
  2022-03-09 10:39 ` [PATCH 06/11] gdb/fortran: clean-up Fortran intrinsic types Nils-Christian Kempke
@ 2022-04-07 14:33   ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:33 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> This patch adds
> all missing tokens and their parsing.  Whenever a section containing the
> type handling was touched, it also was reordered to be in a more easy to
> grasp order.  All INTEGER/REAL/LOGICAL/COMPLEX types were grouped
> together and ordered ascending in their size making a missing one more
> easy to spot.

Nice.  Thank you, this is ok.

Tom

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

* Re: [PATCH 07/11] gdb/fortran: Change GDB print for fortran default types
  2022-03-09 10:39 ` [PATCH 07/11] gdb/fortran: Change GDB print for fortran default types Nils-Christian Kempke
@ 2022-04-07 14:37   ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:37 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> Currently, when asking GDB to print the type of a Fortran default type

Typo in the commit message, "default".

> This patch changes the outputs for the REAL and INTEGER default types to
> actually print the internally used type over the default type name.

Thanks.  This makes sense to me.  The patch looks good.

I've often thought that the general gdb behavior for primitive types:

(gdb) ptype int
type = int

... could be improved.  Normally if I'm asking gdb this, I probably want
to know more, like the type's size and signed-ness, or something like
that -- I already know it's name.

Tom

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

* Re: [PATCH 08/11] gdb/fortran: rename f77_keywords to f_keywords
  2022-03-09 10:39 ` [PATCH 08/11] gdb/fortran: rename f77_keywords to f_keywords Nils-Christian Kempke
@ 2022-04-07 14:37   ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:37 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> Rename f77_keywords to f_keywords since some of the introduced keywords
> in the array are f90 only.

Ok.

Tom

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

* Re: [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads
  2022-03-09 10:39 ` [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads Nils-Christian Kempke
@ 2022-04-07 14:49   ` Tom Tromey
  2022-04-08 12:49     ` Kempke, Nils-Christian
  2022-04-13  5:14   ` Tom de Vries
  1 sibling, 1 reply; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:49 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

Thanks for the patch.
I found one minor problem in this one.  You don't have to resubmit after
fixing it, though.

> After adding more overloads to the intrinsics handling, some of the
> operation names were no longer accurate.  E.g. UNOP_FORTRAN_CEILING
> has been renamed to FORTRAN_CEILING as it is no longer a purely unary
> intrinsic function.

Eventually I'd like to get rid of this operator enum entirely, but it's
also fine to make the names more correct in the meantime.

> +    case FORTRAN_LBOUND:
> +    case FORTRAN_UBOUND:
> +      pstate->push_new<fortran_bound_2arg>
> +	(code, pstate->pop (), pstate->pop ());

I don't think you can rely on the order of evaluation here.  (C++ did
change this, but after C++11, I think.)  Instead you need to introduce
temporaries to control the ordering.

Tom

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

* Re: [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test
  2022-03-09 10:39 ` [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test Nils-Christian Kempke
@ 2022-04-07 14:49   ` Tom Tromey
  2022-04-07 14:50   ` Tom Tromey
  1 sibling, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:49 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> When working on the files I noted that there was no actual test for a
> COMPLEX built from two INTEGERS.  I added that now for completion.

Looks good.

Tom

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

* Re: [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test
  2022-03-09 10:39 ` [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test Nils-Christian Kempke
  2022-04-07 14:49   ` Tom Tromey
@ 2022-04-07 14:50   ` Tom Tromey
  1 sibling, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2022-04-07 14:50 UTC (permalink / raw)
  To: Nils-Christian Kempke via Gdb-patches

>>>>> Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org> writes:

> When working on the files I noted that there was no actual test for a
> COMPLEX built from two INTEGERS.  I added that now for completion.

I meant to mention -- when working on Rust, something I tried is built
gdb with code coverage enabled, then ran the test suite.  This let me
find the parts of the language support that were untested.

Tom

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

* RE: [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads
  2022-04-07 14:49   ` Tom Tromey
@ 2022-04-08 12:49     ` Kempke, Nils-Christian
  0 siblings, 0 replies; 28+ messages in thread
From: Kempke, Nils-Christian @ 2022-04-08 12:49 UTC (permalink / raw)
  To: Tom Tromey, Nils-Christian Kempke via Gdb-patches

> From: Tom Tromey <tom@tromey.com>
> Sent: Thursday, April 7, 2022 4:49 PM

> Thanks for the patch.
> I found one minor problem in this one.  You don't have to resubmit after
> fixing it, though.
> 
> > After adding more overloads to the intrinsics handling, some of the
> > operation names were no longer accurate.  E.g. UNOP_FORTRAN_CEILING
> > has been renamed to FORTRAN_CEILING as it is no longer a purely unary
> > intrinsic function.
> 
> Eventually I'd like to get rid of this operator enum entirely, but it's
> also fine to make the names more correct in the meantime.

Thanks for the review!

I also thought about this while doing the changes..  But I did not want the series
to become even more invasive.  Should I touch the Fortran intrinsics handling 
in the new future again I'll do that, too (probably while checking the intrinsics code
test coverage..).

> 
> > +    case FORTRAN_LBOUND:
> > +    case FORTRAN_UBOUND:
> > +      pstate->push_new<fortran_bound_2arg>
> > +	(code, pstate->pop (), pstate->pop ());
> 
> I don't think you can rely on the order of evaluation here.  (C++ did
> change this, but after C++11, I think.)  Instead you need to introduce
> temporaries to control the ordering.
> 

Good spot, thanks!

I'll resubmit patch [PATCH 11/11] only then.

Cheers, Nils
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* Re: [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads
  2022-03-09 10:39 ` [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads Nils-Christian Kempke
  2022-04-07 14:49   ` Tom Tromey
@ 2022-04-13  5:14   ` Tom de Vries
  2022-04-20 16:10     ` Kempke, Nils-Christian
  1 sibling, 1 reply; 28+ messages in thread
From: Tom de Vries @ 2022-04-13  5:14 UTC (permalink / raw)
  To: Nils-Christian Kempke, gdb-patches

On 3/9/22 11:39, Nils-Christian Kempke via Gdb-patches wrote:
> 	* gdb.fortran/lbound-ubound.F90: Add arrays with possibly
> 	overflowing dimensions and add some test.
> 	* gdb.fortran/lbound-ubound.exp: Add LBOUND/UBOUND test for
> 	overflow in array dimensions when supplying the KIND parameter.
> 	* gdb.fortran/size.exp: Add tests for overflow when using the
> 	KIND parameter.
> 	* gdb.fortran/size.f90: Add compiled KIND parameter tests.

This caused some fails / regressions with target board unix/-m32, see:
- https://sourceware.org/bugzilla/show_bug.cgi?id=29053
   PR29053 - [m32] FAIL: gdb.fortran/lbound-ubound.exp: test 12: check
   value of lbound ('array_1d_4bytes_overflow') expression
- https://sourceware.org/bugzilla/show_bug.cgi?id=29054
   PR29054 - [gdb/testsuite] Compilation failure of gdb.fortran/size.f90
   with -m32

Thanks,
- Tom

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

* RE: [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads
  2022-04-13  5:14   ` Tom de Vries
@ 2022-04-20 16:10     ` Kempke, Nils-Christian
  0 siblings, 0 replies; 28+ messages in thread
From: Kempke, Nils-Christian @ 2022-04-20 16:10 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

We are working on a fix here which should be available soon,
sorry for this - somehow it slipped though.

Thanks!
Nils

> -----Original Message-----
> From: Tom de Vries <tdevries@suse.de>
> Sent: Wednesday, April 13, 2022 7:15 AM
> To: Kempke, Nils-Christian <nils-christian.kempke@intel.com>; gdb-
> patches@sourceware.org
> Subject: Re: [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add
> some missing overloads
> 
> On 3/9/22 11:39, Nils-Christian Kempke via Gdb-patches wrote:
> > 	* gdb.fortran/lbound-ubound.F90: Add arrays with possibly
> > 	overflowing dimensions and add some test.
> > 	* gdb.fortran/lbound-ubound.exp: Add LBOUND/UBOUND test for
> > 	overflow in array dimensions when supplying the KIND parameter.
> > 	* gdb.fortran/size.exp: Add tests for overflow when using the
> > 	KIND parameter.
> > 	* gdb.fortran/size.f90: Add compiled KIND parameter tests.
> 
> This caused some fails / regressions with target board unix/-m32, see:
> - https://sourceware.org/bugzilla/show_bug.cgi?id=29053
>    PR29053 - [m32] FAIL: gdb.fortran/lbound-ubound.exp: test 12: check
>    value of lbound ('array_1d_4bytes_overflow') expression
> - https://sourceware.org/bugzilla/show_bug.cgi?id=29054
>    PR29054 - [gdb/testsuite] Compilation failure of gdb.fortran/size.f90
>    with -m32
> 
> Thanks,
> - Tom
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

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

end of thread, other threads:[~2022-04-20 16:20 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
2022-03-09 10:39 ` [PATCH 01/11] gdb/f-lang: add Integer*1 to Fortran builtin types Nils-Christian Kempke
2022-04-07 14:28   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 02/11] gdb/f-lang: remove hidden ^L characters Nils-Christian Kempke
2022-04-07 14:28   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types Nils-Christian Kempke
2022-04-07 14:30   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 04/11] gdb/fortran: reformat build_fortran_types in f-lang.c Nils-Christian Kempke
2022-04-07 14:30   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 05/11] gdb/fortran: change default logical type to builtin_logical Nils-Christian Kempke
2022-04-07 14:32   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 06/11] gdb/fortran: clean-up Fortran intrinsic types Nils-Christian Kempke
2022-04-07 14:33   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 07/11] gdb/fortran: Change GDB print for fortran default types Nils-Christian Kempke
2022-04-07 14:37   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 08/11] gdb/fortran: rename f77_keywords to f_keywords Nils-Christian Kempke
2022-04-07 14:37   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads Nils-Christian Kempke
2022-04-07 14:49   ` Tom Tromey
2022-04-08 12:49     ` Kempke, Nils-Christian
2022-04-13  5:14   ` Tom de Vries
2022-04-20 16:10     ` Kempke, Nils-Christian
2022-03-09 10:39 ` [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test Nils-Christian Kempke
2022-04-07 14:49   ` Tom Tromey
2022-04-07 14:50   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 11/11] gdb/doc: add section about fortran intrinsic functions and types Nils-Christian Kempke
2022-03-09 12:49   ` Eli Zaretskii
2022-03-09 17:01     ` Kempke, Nils-Christian

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).