From patchwork Fri May 31 19:56:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1108551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-502115-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="EMaZvp2O"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JtuuQtBg"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45FwFd1Wq7z9s5c for ; Sat, 1 Jun 2019 05:56:50 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=PdltgDuEA2mcIL+fx9eg97tpotViyzfRn5d+8uFa0+KcJCv61f yfPsGCfZjrULec2B4vebJYUE0vmMo+eYk0sKY7uomphsJrOOXxg8Rs1awmLz823a YOdIeRh9V80JL6XSw0dt7j0nJ6tgkNYevqP1MguWAj7JQU/n2UTlYyPJ4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=nthOUibtIX2DdwgqlWDG/0w+0Ys=; b=EMaZvp2OKecNwjGElhTG kGoHjrG0GRicEQFH0ErkWWAthrwlnAoM7sWF/4F+wo/MwURRubNObEQs0lUoTNdH YOOkHY+7yCyWs9iaHSkEaNB1TfOn6XYvh/Tjs7Sy2yy2ijRw+cqgSufM2a3btD3B ssBzOAcnvGMSONh4Z9ChAlw= Received: (qmail 38806 invoked by alias); 31 May 2019 19:56:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 38797 invoked by uid 89); 31 May 2019 19:56:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-ot1-f47.google.com Received: from mail-ot1-f47.google.com (HELO mail-ot1-f47.google.com) (209.85.210.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 31 May 2019 19:56:42 +0000 Received: by mail-ot1-f47.google.com with SMTP id l17so10430237otq.1 for ; Fri, 31 May 2019 12:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=bYiLD3X8ekBzZ6nNeszSzM/9Crla/AXzJ7RVldTO/zc=; b=JtuuQtBgyVuBkASDwDu9nUzebF4WyHnxgAif9j1mnDPYQ5HtTflSdgtmCb2EclIc9H dQV8fWZOSK260jYQ10hDEmdfaL3IPDMMzr/uY1zbvEdyOZvjqMXagoFdwF6ihPfuLN3F OahtA2F6C+Dmby3Fcd4HKB2F84Ng3pgv3JwSpgQpkN/x0HlyK1yl9oZ2hx/+sJAWCKff OKtC/jgAAdGERDEA9QE6mFfesn1FeJNCBiodgOyPktZFSOxONX9oZ/Jwkwisq9gMAJCT StHemVLC7vIe62tjtOr1qD4lm1o2A22PeTUEUT+N+nSaBO+ZcuajyJjfDmIHErBHcFA+ 5c/A== Received: from [192.168.0.41] (97-118-125-210.hlrn.qwest.net. [97.118.125.210]) by smtp.gmail.com with ESMTPSA id b9sm2319492oti.43.2019.05.31.12.56.39 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Fri, 31 May 2019 12:56:39 -0700 (PDT) To: gcc-patches From: Martin Sebor Subject: [PATCH] correct the representation of ADDR_EXPR involving pointer to array [PR 90694] Message-ID: <46673e65-eefd-68d5-088b-1a9723a84a9c@gmail.com> Date: Fri, 31 May 2019 13:56:38 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 X-IsSubscribed: yes Given a poiner to array p, tree dumps for expressions like &(*p)[2] actually show &*p[2]. That's not right -- the parentheses are important to differentiate indexing into the array the pointer points to from indexing into the pointer. The attached patch adjusts the tree pretty printer to add the parens when the pointer points to an array. Tested on x86_64-linux. Martin PR middle-end/90694 - incorrect representation of ADDR_EXPR involving a pointer to array gcc/ChangeLog: PR middle-end/90694 * tree-pretty-print.c (dump_generic_node): Add parentheses. gcc/testsuite/ChangeLog: PR middle-end/90694 * gcc.dg/tree-ssa/dump-5.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dump-5.c b/gcc/testsuite/gcc.dg/tree-ssa/dump-5.c new file mode 100644 index 00000000000..6807b5e9ef4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/dump-5.c @@ -0,0 +1,15 @@ +/* PR middle-end/90694 - incorrect representation of ADDR_EXPR involving + a pointer to array + { dg-do compile } + { dg-options "-fdump-tree-original" } */ + +typedef char A8[8]; + +unsigned f (A8 *pa) +{ + return __builtin_strlen (&(*pa)[2]); +} + +/* Veriy the expression is correct in the dump: + { dg-final { scan-tree-dump-not "\\\&\\\*pa\\\[2\\\]" "original" } } + { dg-final { scan-tree-dump "\\\&\\\(\\\*pa\\\)\\\[2\\\]" "original" } } */ diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 6645a646617..30d1d65e6bc 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -1676,9 +1676,17 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, { if (TREE_CODE (TREE_OPERAND (node, 0)) != ADDR_EXPR) { + /* Enclose pointers to arrays in parentheses. */ + tree op0 = TREE_OPERAND (node, 0); + tree op0type = TREE_TYPE (op0); + if (POINTER_TYPE_P (op0type) + && TREE_CODE (TREE_TYPE (op0type)) == ARRAY_TYPE) + pp_left_paren (pp); pp_star (pp); - dump_generic_node (pp, TREE_OPERAND (node, 0), - spc, flags, false); + dump_generic_node (pp, op0, spc, flags, false); + if (POINTER_TYPE_P (op0type) + && TREE_CODE (TREE_TYPE (op0type)) == ARRAY_TYPE) + pp_right_paren (pp); } else dump_generic_node (pp,