From patchwork Sun Jul 29 22:41:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 28675 Received: (qmail 125556 invoked by alias); 29 Jul 2018 22:41:53 -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 125547 invoked by uid 89); 29 Jul 2018 22:41:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-HELO:sk:mail-wr, H*r:sk:mail-wr, Hx-spam-relays-external:sk:mail-wr, H*RU:sk:mail-wr X-HELO: mail-wr1-f50.google.com Received: from mail-wr1-f50.google.com (HELO mail-wr1-f50.google.com) (209.85.221.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 29 Jul 2018 22:41:49 +0000 Received: by mail-wr1-f50.google.com with SMTP id h14-v6so10729569wrw.13 for ; Sun, 29 Jul 2018 15:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=Z/WQg+FUrR72JFyVgxi6wl2U+cPIltQmaC2bHrdFi8Y=; b=CMINAh7yRqpeOhbAFPF14YS6/5EuQJqXQ3jlI+XezzVYEvNKCMUvFK6+qSPB40/8Cf G2wjQgeSol3+vgdkMgp1pSKnLr9tUp/gqsydZQFFkjKF5PxGYIlnbm8IJMvRsKR4YrTb cno4SOoiV0ElYWdkpyL7H5ucF6acICgYivqboYX6GRVM3PO8hoFl4cvJzYZGmOfgWb1t +oALUtAmvXFma+7te4tRkUZB1FXvN13g5IKFbqnM6q20JV/klH7BD6Hkr052FoyqxMF1 MgRTKy8xrWFbgiTgl0cy4bigTIfwYaEe5oSfHaewcGDqau5ZrDL0Eoo6pCnMJfEYxj8v oeqw== Return-Path: Received: from localhost (host109-147-66-79.range109-147.btcentralplus.com. [109.147.66.79]) by smtp.gmail.com with ESMTPSA id r140-v6sm21447708wmd.7.2018.07.29.15.41.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Jul 2018 15:41:46 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Tom de Vries , Andrew Burgess Subject: [PATCH] gdb: Fix sizeof for dynamic types other than arrays Date: Sun, 29 Jul 2018 23:41:37 +0100 Message-Id: <20180729224137.27121-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes In commit: commit 37cc0caeca4c9a8552370040f4cfeaeceaa03369 Date: Wed Jul 18 13:38:35 2018 +0200 [gdb/exp] Interpret size of vla with unknown size as All dynamic types are treated as arrays in the 'sizeof' code path, which means that structures can incorrectly be treated as arrays. This can cause a failure in the gdb.base/vla-datatypes.exp test script. This commit adds a check that we do have an array before checking the array bounds, and I also check that the array index type is dynamic too. This second check probably isn't strictly necessary, but shouldn't hurt, a non-dynamic index type shouldn't have undefined high bound. gdb/ChangeLog: * eval.c (evaluate_subexp_for_sizeof): Check for array type before checking array bounds are defined. --- gdb/ChangeLog | 5 +++++ gdb/eval.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gdb/eval.c b/gdb/eval.c index 0495a11bfd7..2e08e9355f5 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -3145,7 +3145,9 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos, { val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL); type = value_type (val); - if (TYPE_HIGH_BOUND_UNDEFINED (TYPE_INDEX_TYPE (type))) + if (TYPE_CODE (type) == TYPE_CODE_ARRAY + && is_dynamic_type (TYPE_INDEX_TYPE (type)) + && TYPE_HIGH_BOUND_UNDEFINED (TYPE_INDEX_TYPE (type))) return allocate_optimized_out_value (size_type); } else