From patchwork Wed Nov 29 23:33:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 24611 Received: (qmail 58747 invoked by alias); 29 Nov 2017 23:33:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 58726 invoked by uid 89); 29 Nov 2017 23:33:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Pushed X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Nov 2017 23:33:40 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0D7991169B4 for ; Wed, 29 Nov 2017 18:33:39 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id HfjLaUoNEyVe for ; Wed, 29 Nov 2017 18:33:38 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id F307D116992 for ; Wed, 29 Nov 2017 18:33:38 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id EF2DF175; Wed, 29 Nov 2017 18:33:38 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed/Ada] preserve type length in ada-lang.c::to_fixed_range_type Date: Wed, 29 Nov 2017 18:33:33 -0500 Message-Id: <1511998413-64211-1-git-send-email-brobecker@adacore.com> Hello, This patch fixes a potential issue which was noticed by code inspection: ada-lang.c::to_fixed_range_type uses gdbtypes.c::create_static_range_type to create most of the range type, which relies on create_range_type to do most of the work. The latter has the following piece of code which sets the length of the range type to match the length of the index_type: if (TYPE_STUB (index_type)) TYPE_TARGET_STUB (result_type) = 1; else TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); In Ada, it is actually possible to have a range type whose size is smaller than its base type. For instance, with: type Unsigned2_T is range 0 .. 2 ** 16 - 1; for Unsigned2_T'SIZE use 16; The compiler generates the following DWARF: .uleb128 0x3 # (DIE (0x4e) DW_TAG_subrange_type) .byte 0x2 # DW_AT_byte_size .byte 0 # DW_AT_lower_bound .value 0xffff # DW_AT_upper_bound .long .LASF64 # DW_AT_name: "try__unsigned2_t___XDLU_0__65535" .long 0x616 # DW_AT_type ... which points to the following base type... .uleb128 0x1d # (DIE (0x616) DW_TAG_base_type) .byte 0x4 # DW_AT_byte_size .byte 0x5 # DW_AT_encoding .long .LASF57 # DW_AT_name: "try__Tunsigned2_tB" # DW_AT_artificial ... which has a size of 4 bytes. With a type like this one, create_range_type returns a type whose size is 4 bytes, instead of 2, which is not what we we would normally expect. Currently, this function is only used to handle array index types, so the length of the type actually does not matter and there should not be any user-visible consequences of the current behavior. But it seems best to plug this latent bug now, rather than wait for it to surface.... gdb/ChangeLog: * ada-lang.c (to_fixed_range_type): Make sure that the size of the range type being returned is the same as the size of the range type being fixed. Tested on x86_64-linux, no regression. Pushed to master. Thanks, diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 567cc00..ca8c5df 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2017-11-29 Joel Brobecker + + * ada-lang.c (to_fixed_range_type): Make sure that the size + of the range type being returned is the same as the size + of the range type being fixed. + 2017-11-29 Pedro Alves PR c++/19436 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 38d1ce6..8e35ee6 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -11688,6 +11688,10 @@ to_fixed_range_type (struct type *raw_type, struct value *dval) type = create_static_range_type (alloc_type_copy (raw_type), base_type, L, U); + /* create_static_range_type alters the resulting type's length + to match the size of the base_type, which is not what we want. + Set it back to the original range type's length. */ + TYPE_LENGTH (type) = TYPE_LENGTH (raw_type); TYPE_NAME (type) = name; return type; }