From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by sourceware.org (Postfix) with ESMTPS id E4D673851C1F for ; Mon, 22 Jun 2020 17:25:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E4D673851C1F Received: by mail-qk1-x72b.google.com with SMTP id k18so7105509qke.4 for ; Mon, 22 Jun 2020 10:25:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=cA1P7+k6T1qDEODA+b5uQ4AxP3QMzXEMKecrZgMc0wY=; b=bVXpin8XNMPmip2yGs3bd5DshzML2EHO7r0kGlV8L0W82kvHmSDf+a3lF0XD537Wzc RAQlawGtKJDtwx0y1LeIcFpMayL/p1IkyZ20hOuw0y9anYPE4dKVD+tf5PsDUUH+xvkX hA/wyeHDIScL94twd71jo/HcxzFfsP+HC4EBjiC/kyA8jc1L+w8ZO5N8GaLzOZXLUUKP QeLWQvCQUaMkaao/rWjaIZvYREWQtrGOOSEuiltVJw+Dcus+O/ebGj+0jFXxkRBLkc8g 5nWNEUqIExBUFWvU5GZSZ/e2/1O3nPDmS2V3yGSQUTFMeBET5tzcDaaKiquAEXuNIAA+ hong== X-Gm-Message-State: AOAM533h1VYX1ouPF5B9uf2tmDYle/ChGVbFaJccvca1a4NkDn+cHLtG 3TzkhptcJnCovh2obikoGsk= X-Google-Smtp-Source: ABdhPJy9MgHRWptKF8F+LVTAg4ofIcXI1hC0FkNfl3L0YwJyOOLVPpqGlVT9micyN0r/v534+q/xiQ== X-Received: by 2002:a05:620a:20d3:: with SMTP id f19mr5087673qka.165.1592846753490; Mon, 22 Jun 2020 10:25:53 -0700 (PDT) Received: from [192.168.0.41] (184-96-233-25.hlrn.qwest.net. [184.96.233.25]) by smtp.gmail.com with ESMTPSA id d17sm14093263qke.101.2020.06.22.10.25.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jun 2020 10:25:52 -0700 (PDT) To: gcc-patches , Jason Merrill From: Martin Sebor Subject: [PATCH] handle MEM_REF with void* arguments (PR c++/95768) Message-ID: Date: Mon, 22 Jun 2020 11:25:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F157E4FFF3BFAF9411B06CC6" Content-Language: en-US X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Jun 2020 17:25:55 -0000 This is a multi-part message in MIME format. --------------F157E4FFF3BFAF9411B06CC6 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit The attached fix parallels the one for the equivalent C bug 95580 where the pretty printers don't correctly handle MEM_REF arguments with type void* or other pointers to an incomplete type. The incorrect handling was exposed by the recent change to -Wuninitialized which includes such expressions in diagnostics. Martin --------------F157E4FFF3BFAF9411B06CC6 Content-Type: text/x-patch; name="gcc-95768.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-95768.diff" PR c++/95768 - pretty-printer ICE on -Wuninitialized with allocated storage gcc/cp/ChangeLog: PR c++/95768 * error.c (dump_expr): Handle sizeless operand types such as void*. gcc/testsuite/ChangeLog: PR c++/95768 * g++.dg/pr95768.C: New test. diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 0d6375e5e14..3a7254fdce1 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -2374,32 +2374,37 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags) break; case MEM_REF: - if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR - && integer_zerop (TREE_OPERAND (t, 1))) - dump_expr (pp, TREE_OPERAND (TREE_OPERAND (t, 0), 0), flags); - else - { - pp_cxx_star (pp); - if (!integer_zerop (TREE_OPERAND (t, 1))) - { - pp_cxx_left_paren (pp); - if (!integer_onep (TYPE_SIZE_UNIT - (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)))))) - { - pp_cxx_left_paren (pp); - dump_type (pp, ptr_type_node, flags); - pp_cxx_right_paren (pp); - } - } - dump_expr (pp, TREE_OPERAND (t, 0), flags); - if (!integer_zerop (TREE_OPERAND (t, 1))) - { - pp_cxx_ws_string (pp, "+"); - dump_expr (pp, fold_convert (ssizetype, TREE_OPERAND (t, 1)), - flags); - pp_cxx_right_paren (pp); - } - } + { + tree arg = TREE_OPERAND (t, 0); + tree offset = TREE_OPERAND (t, 1); + + if (TREE_CODE (arg) == ADDR_EXPR + && integer_zerop (offset)) + dump_expr (pp, TREE_OPERAND (arg, 0), flags); + else + { + pp_cxx_star (pp); + if (!integer_zerop (offset)) + { + pp_cxx_left_paren (pp); + tree argtype = TREE_TYPE (arg); + if (tree size = TYPE_SIZE_UNIT (TREE_TYPE (argtype))) + if (!integer_onep (size)) + { + pp_cxx_left_paren (pp); + dump_type (pp, ptr_type_node, flags); + pp_cxx_right_paren (pp); + } + } + dump_expr (pp, arg, flags); + if (!integer_zerop (offset)) + { + pp_cxx_ws_string (pp, "+"); + dump_expr (pp, fold_convert (ssizetype, offset), flags); + pp_cxx_right_paren (pp); + } + } + } break; case NEGATE_EXPR: diff --git a/gcc/testsuite/g++.dg/pr95768.C b/gcc/testsuite/g++.dg/pr95768.C new file mode 100644 index 00000000000..babfcb49bf8 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr95768.C @@ -0,0 +1,32 @@ +/* PR c++/95768 - pretty-printer ICE on -Wuninitialized with allocated storage + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +extern "C" void *malloc (__SIZE_TYPE__); + +struct f +{ + int i; + static int e (int); + void operator= (int) { e (i); } +}; + +struct m { + int i; + f length; +}; + +struct n { + m *o() { return (m *)this; } +}; + +struct p { + n *header; + p () { + header = (n *)malloc (0); + m b = *header->o(); // { dg-warning "-Wuninitialized" } + b.length = 0; + } +}; + +void detach2() { p(); } --------------F157E4FFF3BFAF9411B06CC6--