From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway32.websitewelcome.com (gateway32.websitewelcome.com [192.185.145.119]) by sourceware.org (Postfix) with ESMTPS id D6061387703A for ; Fri, 20 Mar 2020 21:53:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D6061387703A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 777F1A8D2A5 for ; Fri, 20 Mar 2020 16:53:42 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id FPaIjfidkSl8qFPaIjE8bE; Fri, 20 Mar 2020 16:53:42 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=PC+zDbeEfOiENfZU3mr7NpMpdTSwmopCRuqKDAxNoq4=; b=ST0CCKdtHIFBgE3UDExg52WLal Ic6D76QDW0/XGPpQDGJLEmMFfkKsuzzYswKKgfwMmDliXXNqTpz+3tmlgIUP+GWH9btcMSCuj//g2 vODntPdWwRmUMr9HRPi9L5VH2; Received: from 97-118-117-21.hlrn.qwest.net ([97.118.117.21]:35792 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jFPaI-003c6k-8B; Fri, 20 Mar 2020 15:53:42 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 1/7] Change how complex types are created Date: Fri, 20 Mar 2020 15:53:34 -0600 Message-Id: <20200320215340.16749-2-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200320215340.16749-1-tom@tromey.com> References: <20200320215340.16749-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.118.117.21 X-Source-L: No X-Exim-ID: 1jFPaI-003c6k-8B X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-117-21.hlrn.qwest.net (bapiya.Home) [97.118.117.21]:35792 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-19.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, URIBL_CSS, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2020 21:53:44 -0000 This patch changes how complex types are created. init_complex_type and arch_complex_type are unified, and complex types are reused, by attaching them to the underlying scalar type. gdb/ChangeLog 2020-03-20 Tom Tromey * stabsread.c (rs6000_builtin_type, read_sun_floating_type) (read_range_type): Update. * mdebugread.c (basic_type): Update. * go-lang.c (build_go_types): Use init_complex_type. * gdbtypes.h (struct main_type) : New member. (init_complex_type): Update. (arch_complex_type): Don't declare. * gdbtypes.c (init_complex_type): Remove "objfile" parameter. Make name if none given. Use alloc_type_copy. Look for cached complex type. (arch_complex_type): Remove. (gdbtypes_post_init): Use init_complex_type. * f-lang.c (build_fortran_types): Use init_complex_type. * dwarf2/read.c (read_base_type): Update. * d-lang.c (build_d_types): Use init_complex_type. * ctfread.c (read_base_type): Update. --- gdb/ChangeLog | 19 ++++++++++++++++ gdb/ctfread.c | 2 +- gdb/d-lang.c | 9 +++----- gdb/dwarf2/read.c | 2 +- gdb/f-lang.c | 9 +++----- gdb/gdbtypes.c | 58 +++++++++++++++++++++++++---------------------- gdb/gdbtypes.h | 9 ++++---- gdb/go-lang.c | 6 ++--- gdb/mdebugread.c | 6 ++--- gdb/stabsread.c | 8 +++---- 10 files changed, 71 insertions(+), 57 deletions(-) diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 241d0b6da94..7784e9d35d6 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -553,7 +553,7 @@ read_base_type (struct ctf_context *ccp, ctf_id_t tid) { struct type *t = ctf_init_float_type (of, cet.cte_bits / 2, NULL, name); - type = init_complex_type (of, name, t); + type = init_complex_type (name, t); } } else diff --git a/gdb/d-lang.c b/gdb/d-lang.c index f50c31a018e..951e664ceda 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -314,14 +314,11 @@ build_d_types (struct gdbarch *gdbarch) = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch), "ireal", gdbarch_long_double_format (gdbarch)); builtin_d_type->builtin_cfloat - = arch_complex_type (gdbarch, "cfloat", - builtin_d_type->builtin_float); + = init_complex_type ("cfloat", builtin_d_type->builtin_float); builtin_d_type->builtin_cdouble - = arch_complex_type (gdbarch, "cdouble", - builtin_d_type->builtin_double); + = init_complex_type ("cdouble", builtin_d_type->builtin_double); builtin_d_type->builtin_creal - = arch_complex_type (gdbarch, "creal", - builtin_d_type->builtin_real); + = init_complex_type ("creal", builtin_d_type->builtin_real); /* Character types. */ builtin_d_type->builtin_char diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 0e879e08a0c..59aa230d0fb 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -17015,7 +17015,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) case DW_ATE_complex_float: type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name, byte_order); - type = init_complex_type (objfile, name, type); + type = init_complex_type (name, type); break; case DW_ATE_decimal_float: type = init_decfloat_type (objfile, bits, name); diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 75a131d76d8..2ce4ad43610 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -741,14 +741,11 @@ build_fortran_types (struct gdbarch *gdbarch) = arch_type (gdbarch, TYPE_CODE_ERROR, 128, "real*16"); builtin_f_type->builtin_complex_s8 - = arch_complex_type (gdbarch, "complex*8", - builtin_f_type->builtin_real); + = init_complex_type ("complex*8", builtin_f_type->builtin_real); builtin_f_type->builtin_complex_s16 - = arch_complex_type (gdbarch, "complex*16", - builtin_f_type->builtin_real_s8); + = init_complex_type ("complex*16", builtin_f_type->builtin_real_s8); builtin_f_type->builtin_complex_s32 - = arch_complex_type (gdbarch, "complex*32", - builtin_f_type->builtin_real_s16); + = init_complex_type ("complex*32", builtin_f_type->builtin_real_s16); return builtin_f_type; } diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index d89df9f7409..f23def1ff71 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -3025,19 +3025,40 @@ init_decfloat_type (struct objfile *objfile, int bit, const char *name) return t; } -/* Allocate a TYPE_CODE_COMPLEX type structure associated with OBJFILE. - NAME is the type name. TARGET_TYPE is the component float type. */ +/* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type + name. TARGET_TYPE is the component type. */ struct type * -init_complex_type (struct objfile *objfile, - const char *name, struct type *target_type) +init_complex_type (const char *name, struct type *target_type) { struct type *t; - t = init_type (objfile, TYPE_CODE_COMPLEX, - 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name); - TYPE_TARGET_TYPE (t) = target_type; - return t; + gdb_assert (TYPE_CODE (target_type) == TYPE_CODE_INT + || TYPE_CODE (target_type) == TYPE_CODE_FLT); + + if (TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type == nullptr) + { + if (name == nullptr) + { + char *new_name + = (char *) TYPE_ALLOC (target_type, + strlen (TYPE_NAME (target_type)) + + strlen ("_Complex ") + 1); + strcpy (new_name, "_Complex "); + strcat (new_name, TYPE_NAME (target_type)); + name = new_name; + } + + t = alloc_type_copy (target_type); + set_type_code (t, TYPE_CODE_COMPLEX); + TYPE_LENGTH (t) = 2 * TYPE_LENGTH (target_type); + TYPE_NAME (t) = name; + + TYPE_TARGET_TYPE (t) = target_type; + TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type = t; + } + + return TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type; } /* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE. @@ -5259,21 +5280,6 @@ arch_decfloat_type (struct gdbarch *gdbarch, int bit, const char *name) return t; } -/* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH. - NAME is the type name. TARGET_TYPE is the component float type. */ - -struct type * -arch_complex_type (struct gdbarch *gdbarch, - const char *name, struct type *target_type) -{ - struct type *t; - - t = arch_type (gdbarch, TYPE_CODE_COMPLEX, - 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name); - TYPE_TARGET_TYPE (t) = target_type; - return t; -} - /* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH. BIT is the pointer type size in bits. NAME is the type name. TARGET_TYPE is the pointer target type. Always sets the pointer type's @@ -5497,11 +5503,9 @@ gdbtypes_post_init (struct gdbarch *gdbarch) = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch), "long double", gdbarch_long_double_format (gdbarch)); builtin_type->builtin_complex - = arch_complex_type (gdbarch, "complex", - builtin_type->builtin_float); + = init_complex_type ("complex", builtin_type->builtin_float); builtin_type->builtin_double_complex - = arch_complex_type (gdbarch, "double complex", - builtin_type->builtin_double); + = init_complex_type ("double complex", builtin_type->builtin_double); builtin_type->builtin_string = arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string"); builtin_type->builtin_bool diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index cb674dbc1e8..77cc92e419d 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -803,6 +803,10 @@ struct main_type struct range_bounds *bounds; + /* If this is a scalar type, then this is its corresponding + complex type. */ + struct type *complex_type; + } flds_bnds; /* * Slot to point to additional language-specific fields of this @@ -1841,8 +1845,7 @@ extern struct type *init_float_type (struct objfile *, int, const char *, const struct floatformat **, enum bfd_endian = BFD_ENDIAN_UNKNOWN); extern struct type *init_decfloat_type (struct objfile *, int, const char *); -extern struct type *init_complex_type (struct objfile *, const char *, - struct type *); +extern struct type *init_complex_type (const char *, struct type *); extern struct type *init_pointer_type (struct objfile *, int, const char *, struct type *); @@ -1858,8 +1861,6 @@ extern struct type *arch_boolean_type (struct gdbarch *, int, int, extern struct type *arch_float_type (struct gdbarch *, int, const char *, const struct floatformat **); extern struct type *arch_decfloat_type (struct gdbarch *, int, const char *); -extern struct type *arch_complex_type (struct gdbarch *, const char *, - struct type *); extern struct type *arch_pointer_type (struct gdbarch *, int, const char *, struct type *); diff --git a/gdb/go-lang.c b/gdb/go-lang.c index 53e342963d9..03dc986ab6a 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -665,11 +665,9 @@ build_go_types (struct gdbarch *gdbarch) builtin_go_type->builtin_float64 = arch_float_type (gdbarch, 64, "float64", floatformats_ieee_double); builtin_go_type->builtin_complex64 - = arch_complex_type (gdbarch, "complex64", - builtin_go_type->builtin_float32); + = init_complex_type ("complex64", builtin_go_type->builtin_float32); builtin_go_type->builtin_complex128 - = arch_complex_type (gdbarch, "complex128", - builtin_go_type->builtin_float64); + = init_complex_type ("complex128", builtin_go_type->builtin_float64); return builtin_go_type; } diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 5d2fbcd2749..7fcd29cb6b1 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -1429,13 +1429,11 @@ basic_type (int bt, struct objfile *objfile) break; case btComplex: - tp = init_complex_type (objfile, "complex", - basic_type (btFloat, objfile)); + tp = init_complex_type ("complex", basic_type (btFloat, objfile)); break; case btDComplex: - tp = init_complex_type (objfile, "double complex", - basic_type (btFloat, objfile)); + tp = init_complex_type ("double complex", basic_type (btFloat, objfile)); break; case btFixedDec: diff --git a/gdb/stabsread.c b/gdb/stabsread.c index a23ebf6b606..068ece2ff53 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -2186,12 +2186,12 @@ rs6000_builtin_type (int typenum, struct objfile *objfile) break; case 25: /* Complex type consisting of two IEEE single precision values. */ - rettype = init_complex_type (objfile, "complex", + rettype = init_complex_type ("complex", rs6000_builtin_type (12, objfile)); break; case 26: /* Complex type consisting of two IEEE double precision values. */ - rettype = init_complex_type (objfile, "double complex", + rettype = init_complex_type ("double complex", rs6000_builtin_type (13, objfile)); break; case 27: @@ -3805,7 +3805,7 @@ read_sun_floating_type (const char **pp, int typenums[2], || details == NF_COMPLEX32) { rettype = dbx_init_float_type (objfile, nbits / 2); - return init_complex_type (objfile, NULL, rettype); + return init_complex_type (NULL, rettype); } return dbx_init_float_type (objfile, nbits); @@ -4099,7 +4099,7 @@ read_range_type (const char **pp, int typenums[2], int type_size, = dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT); if (self_subrange) - return init_complex_type (objfile, NULL, float_type); + return init_complex_type (NULL, float_type); else return float_type; } -- 2.17.2