public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Nils-Christian Kempke <nils-christian.kempke@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types
Date: Wed,  9 Mar 2022 11:39:14 +0100	[thread overview]
Message-ID: <20220309103922.3257803-4-nils-christian.kempke@intel.com> (raw)
In-Reply-To: <20220309103922.3257803-1-nils-christian.kempke@intel.com>

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


  parent reply	other threads:[~2022-03-09 10:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Nils-Christian Kempke [this message]
2022-04-07 14:30   ` [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220309103922.3257803-4-nils-christian.kempke@intel.com \
    --to=nils-christian.kempke@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).