From patchwork Thu Jan 7 21:29:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1423494 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=A1TAzUJy; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DBfX85Nqkz9sVb for ; Fri, 8 Jan 2021 08:29:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D158A386F450; Thu, 7 Jan 2021 21:29:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D158A386F450 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1610054995; bh=a2mjo7/H0XmGuKgQLvCfKRlZYRLvu6J9WZGMQsRUwIw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=A1TAzUJyfTqRNSzeRNFz8C+N2Ou9WdIB7ZCIkyFjTaDIGhev5ruykdIOeakoppRIz +mjEKnz9vhLXPokFQTa9bcofX/+X3Ox+UKDeJQcocZwY97JpOg2WpmbYfMM7xODvgj kyOd9sM1cT2ebHs6XxVCVYZNuq5Sf6GXSwmuxRCQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 77E60386F03C for ; Thu, 7 Jan 2021 21:29:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 77E60386F03C Received: by mail-pg1-x535.google.com with SMTP id z21so6074746pgj.4 for ; Thu, 07 Jan 2021 13:29:53 -0800 (PST) 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=a2mjo7/H0XmGuKgQLvCfKRlZYRLvu6J9WZGMQsRUwIw=; b=f6wd0NawnsjZm4vdbx9CsrmgwHV7C7dfjbmUafQu/RDg4yuBJoq4IVt322MRsK8KzR 9D/aJ6cQmwI+9wEAuZPAw1sGUMU27K+7o1hEObptjZgIlmmijNQhlLuhmwSgXlUDgsKG v23qIxGDGER34zUJ9fhCyll3FslUUxTN5poVIOU3lkPIm7SD5MNYVqmhZP+mDh32Gqjr 5ElSO1SS7HB1H9XEJpK/H86mvsLj6WIxzBzhHlFRKDMAr0C4kHjXwlwW+wPuV1F+6jf5 HEAgpafwnZfe4XoyqYdTYYw/KTZA0QTSMAWKJeIyVixuRGsIVARCrYj9wZtPGNxRuwfs oe+A== X-Gm-Message-State: AOAM530TSEE3f+VYMdZ0O1I+TltZx4/BYVucWEmYSFXOl8teUKUH4V7C rALRBsx+aVMQC7Y+MKAFz8aQHLdFs2g= X-Google-Smtp-Source: ABdhPJxmtJSZhJzgcho0/WdPOFiB/tFIx83xU4ycP+Ei646T6Cd2L5kLvZTNK8LGhvJ4/26l8TGygw== X-Received: by 2002:a63:1e56:: with SMTP id p22mr3793341pgm.70.1610054992317; Thu, 07 Jan 2021 13:29:52 -0800 (PST) Received: from [192.168.0.41] (75-166-96-128.hlrn.qwest.net. [75.166.96.128]) by smtp.gmail.com with ESMTPSA id z23sm6448258pfn.202.2021.01.07.13.29.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Jan 2021 13:29:51 -0800 (PST) To: gcc-patches Subject: [committed] fix another ICE in MEM_REF formatting (PR 98578) Message-ID: <12069778-e6af-6fb9-13d4-a3c555c70a29@gmail.com> Date: Thu, 7 Jan 2021 14:29:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.4 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-Patchwork-Original-From: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Fixing the ICE in MEM_REF formatting (or the enhancements that came along with the fix) introduced another, ICE plus a plugin test failure. I have committed the attached simple patch to fix both. Martin PS There are outstanding bugs to fix/improvements to be made to the MEM_REF formatting (though hopefully no more ICEs) that I found while testing the attached fix. I xfailed the tests and opened the referenced bugs to keep track of them. commit 178f0afce3611282170de380fcea9db9d6e3ff0c Author: Martin Sebor Date: Thu Jan 7 14:20:39 2021 -0700 PR middle-end/98578 - ICE warning on uninitialized VLA access gcc/c-family/ChangeLog: PR middle-end/98578 * c-pretty-print.c (print_mem_ref): Strip array from access type. Avoid assuming acces type's size is constant. Correct condition guarding the printing of a parenthesis. gcc/testsuite/ChangeLog: PR middle-end/98578 * gcc.dg/plugin/gil-1.c: Adjust expected output. * gcc.dg/uninit-pr98578.c: New test. diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index e963cf53091..87301a2091c 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -1844,22 +1844,25 @@ print_mem_ref (c_pretty_printer *pp, tree e) } } - const tree access_type = TREE_TYPE (e); + tree access_type = TREE_TYPE (e); + if (TREE_CODE (access_type) == ARRAY_TYPE) + access_type = TREE_TYPE (access_type); tree arg_type = TREE_TYPE (TREE_TYPE (arg)); if (TREE_CODE (arg_type) == ARRAY_TYPE) arg_type = TREE_TYPE (arg_type); if (tree access_size = TYPE_SIZE_UNIT (access_type)) - { - /* For naturally aligned accesses print the nonzero offset - in units of the accessed type, in the form of an index. - For unaligned accesses also print the residual byte offset. */ - offset_int asize = wi::to_offset (access_size); - offset_int szlg2 = wi::floor_log2 (asize); - - elt_idx = byte_off >> szlg2; - byte_off = byte_off - (elt_idx << szlg2); - } + if (TREE_CODE (access_size) == INTEGER_CST) + { + /* For naturally aligned accesses print the nonzero offset + in units of the accessed type, in the form of an index. + For unaligned accesses also print the residual byte offset. */ + offset_int asize = wi::to_offset (access_size); + offset_int szlg2 = wi::floor_log2 (asize); + + elt_idx = byte_off >> szlg2; + byte_off = byte_off - (elt_idx << szlg2); + } /* True to include a cast to the accessed type. */ const bool access_cast = VOID_TYPE_P (arg_type) @@ -1924,9 +1927,9 @@ print_mem_ref (c_pretty_printer *pp, tree e) } if (elt_idx != 0) { - if (byte_off == 0 && char_cast) + if (access_cast || char_cast) pp_c_right_paren (pp); - pp_c_right_paren (pp); + if (addr) { pp_space (pp); diff --git a/gcc/testsuite/gcc.dg/plugin/gil-1.c b/gcc/testsuite/gcc.dg/plugin/gil-1.c index 4e8f535ba85..66872f07466 100644 --- a/gcc/testsuite/gcc.dg/plugin/gil-1.c +++ b/gcc/testsuite/gcc.dg/plugin/gil-1.c @@ -13,7 +13,7 @@ void test_2 (PyObject *obj) { Py_BEGIN_ALLOW_THREADS /* { dg-message "releasing the GIL here" } */ - Py_INCREF (obj); /* { dg-warning "use of PyObject '\\*\\(obj\\)' without the GIL" } */ + Py_INCREF (obj); /* { dg-warning "use of PyObject '\\*obj' without the GIL" } */ Py_DECREF (obj); Py_END_ALLOW_THREADS @@ -60,7 +60,7 @@ void test_5 (PyObject *obj) static void __attribute__((noinline)) called_by_test_6 (PyObject *obj) { - Py_INCREF (obj); /* { dg-warning "use of PyObject '\\*\\(obj\\)' without the GIL" } */ + Py_INCREF (obj); /* { dg-warning "use of PyObject '\\*obj' without the GIL" } */ Py_DECREF (obj); } diff --git a/gcc/testsuite/gcc.dg/uninit-pr98578.c b/gcc/testsuite/gcc.dg/uninit-pr98578.c new file mode 100644 index 00000000000..98d611757ab --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr98578.c @@ -0,0 +1,110 @@ +/* PR middle-end/98578 - ICE warning on uninitialized VLA access + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +void* malloc (__SIZE_TYPE__); + +void T (int, ...); + +void vla_n (int n, int i) +{ + int a1[n]; + + /* a1[I] should be formatted as as a1[I] (or, for I == 0, perhaps + as *a1), but definitely not as *a1[I]. This is a bug in VLA + formatting. */ + T (a1[0]); // { dg-warning "'a1\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "'\\*a1\\\[0]' is used uninitialized" "spurious star" { target *-*-* } .-1 } + T (a1[1]); // { dg-warning "a1\\\[1]' is used uninitialized" } + T (a1[i]); // { dg-warning "a1\\\[i]' is used uninitialized" } +} + +void vla_n_2 (int n, int i) +{ + int a2[n][2]; + + T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" } + T (a2[2][1]); // { dg-warning "a2\\\[2]\\\[1]' is used uninitialized" } + T (a2[3][i]); // { dg-warning "a2\\\[3]\\\[i]' is used uninitialized" } + T (a2[i][0]); // { dg-warning "a2\\\[i]\\\[0]' is used uninitialized" } + T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" } +} + + +void vla_3_n (int n, int i) +{ + int a2[3][n]; + + T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" } + T (a2[1][2]); // { dg-warning "a2\\\[1]\\\[2]' is used uninitialized" } + T (a2[2][i]); // { dg-warning "a2\\\[2]\\\[i]' is used uninitialized" } + T (a2[i][3]); // { dg-warning "a2\\\[i]\\\[3]' is used uninitialized" } + T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" } +} + + +void vla_n_n (int n, int i) +{ + int a2[n][n]; + + T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" } + T (a2[4][5]); // { dg-warning "a2\\\[4]\\\[5]' is used uninitialized" } + T (a2[6][i]); // { dg-warning "a2\\\[6]\\\[i]' is used uninitialized" } + T (a2[i][7]); // { dg-warning "a2\\\[i]\\\[7]' is used uninitialized" } + T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" } +} + + +void char_ptr_n (int n, int i) +{ + char *p = malloc (n); + + T (p[0]); // { dg-warning "'\\\*p' is used uninitialized" } + T (p[1]); // { dg-warning "'p\\\[1]' is used uninitialized" } + T (p[i]); // { dg-warning "'p\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "is used uninitialized" "POINTER_PLUS_EXPR" { target *-*-* } .-1 } +} + + +void int_ptr_n (int n, int i) +{ + int *p = malloc (n); + + T (p[0]); // { dg-warning "'\\\*p' is used uninitialized" } + T (p[1]); // { dg-warning "'p\\\[1]' is used uninitialized" } + T (p[i]); // { dg-warning "'p\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "is used uninitialized" "POINTER_PLUS_EXPR" { target *-*-* } .-1 } +} + + +void int_arr_ptr_n (int n, int i) +{ + int (*p)[n] = malloc (n); + + T ((*p)[0]); // { dg-warning "\\(\\*p\\)\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "\\*p\\\[0]' is used uninitialized" "missing parens" { target *-*-* } .-1 } + T ((*p)[1]); // { dg-warning "\\(\\*p\\)\\\[1]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "\\*p\\\[1]' is used uninitialized" "missing parens" { target *-*-* } .-1 } + T ((*p)[i]); // { dg-warning "\\(\\*p\\)\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "\\*p\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 } +} + + +void int_arr_ptr_n_n (int n, int i) +{ + int (*p)[n][n] = malloc (n); + + T ((*p)[0][0]); // { dg-warning "\\(\\*p\\)\\\[0]\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "\\*p\\\[0]\\\[0]' is used uninitialized" "missing parens" { target *-*-* } .-1 } + T ((*p)[1][2]); // { dg-warning "\\(\\*p\\)\\\[1]\\\[2]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "\\*p\\\[1]\\\[2]' is used uninitialized" "missing parens" { target *-*-* } .-1 } + T ((*p)[0][i]); // { dg-warning "\\(\\*p\\)\\\[0]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "\\*p\\\[0]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 } + T ((*p)[3][i]); // { dg-warning "\\(\\*p\\)\\\[3]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "\\*p\\\[3]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 } + T ((*p)[i][i]); // { dg-warning "\\(\\*p\\)\\\[i]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } } + // { dg-warning "\\*p\\\[i]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 } + + T ((*p)[i][i + 1]); // { dg-warning "\\(\\*p\\)\\\[i]\\\[i \\+ 1]' is used uninitialized" "pr98588" { xfail *-*-* } } + // { dg-warning "\\*p\\\[i]\\\[]' is used uninitialized" "missing parens" { target *-*-* } .-1 } +}