From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 43004 invoked by alias); 20 Mar 2017 23:04:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 42993 invoked by uid 89); 20 Mar 2017 23:04:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 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,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=approaches, Hx-languages-length:1969 X-HELO: mail-qt0-f174.google.com Received: from mail-qt0-f174.google.com (HELO mail-qt0-f174.google.com) (209.85.216.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Mar 2017 23:04:25 +0000 Received: by mail-qt0-f174.google.com with SMTP id i34so119488493qtc.0 for ; Mon, 20 Mar 2017 16:04:26 -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; bh=piZ+WCclojyG+xsmMlcOzNMbgFIc4RCnbcQRKoLBcHc=; b=omx6tLOysH16cMUFbtY7tz02JrHXTebtD7W7y6o+qKIsdxHnQqjKrAUAHqpw3/eh9w Sm+4auA8PWVq/Xv4u4JbgdoP9vi7nyumu5saSw64Fwn0bp3Ghyk9myQ86saNthQ1bqfa NlnN8/F9UXImO9q+gzxSFVuwoBQ7r2ghUTmyhhrpQ8+VdP8cohq8p3UgOTMUJc+KwGb0 qeTP3L4UyPelGwfW2MAvLdyzoCQDnse4VoKiQEcey5vKHHjguVVoLzBz+wcKOVD8Om5a x1afUGwrH9n8zi9HPfNK0khzbB5JLHs7pJBg/vQujDUJJxfcSFlV7Hh0sUjOpIjDiOmo EADw== X-Gm-Message-State: AFeK/H3BZmyo0zRJ/6UWdT2NB2Iuse/49oxlVzffAHAOjAqebmYxAcZHpyIAvQvko5ZkOA== X-Received: by 10.200.56.24 with SMTP id q24mr28421047qtb.234.1490051064589; Mon, 20 Mar 2017 16:04:24 -0700 (PDT) Received: from localhost.localdomain (97-118-178-40.hlrn.qwest.net. [97.118.178.40]) by smtp.gmail.com with ESMTPSA id z196sm13435552qkb.11.2017.03.20.16.04.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 16:04:23 -0700 (PDT) To: Gcc Patch List , Jason Merrill From: Martin Sebor Subject: [PATCH] have chkp skip flexible member arrays (PR #79986) Message-ID: <4c6d8cdd-46f8-216d-56cb-07a74284f69a@gmail.com> Date: Mon, 20 Mar 2017 23:04:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------29511FF47269C25644E95678" X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg01062.txt.bz2 This is a multi-part message in MIME format. --------------29511FF47269C25644E95678 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 715 Attached is a minimal patch to avoid an ICE in CHKP upon encountering one form of an initializer for a flexible array member, specifically the empty string: int f () { struct B { int n; char a[]; }; return ((struct B){ 1, "" }).a[0]; } Although GCC accepts (and doesn't ICE on) non-empty initializers for flexible array members, such as (struct B){ 1, "123" } it generates wrong code for them. This could either be fixed by emitting correct code, or it could be handled by rejecting all initializers for non-static objects with such members. Both approaches seem risky to me at this stage and so I think it's safest to hold off on implementing either until after the release. Martin --------------29511FF47269C25644E95678 Content-Type: text/x-patch; name="gcc-79986.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-79986.diff" Content-length: 1272 PR c++/79986 - [CHKP] ICE in fold_convert_loc with a flexible array gcc/ChangeLog: PR c++/79986 * tree-chkp.c (chkp_process_stmt): Avoid assuming size is non-null. gcc/testsuite/ChangeLog: PR c++/79986 * g++.dg/pr79986.C: New test. diff --git a/gcc/testsuite/g++.dg/pr79986.C b/gcc/testsuite/g++.dg/pr79986.C new file mode 100644 index 0000000..d179cf6 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr79986.C @@ -0,0 +1,10 @@ +/* PR c++/79986 - [CHKP] ICE in fold_convert_loc with a flexible array + { dg-do compile { target { { i?86-*-* x86_64-*-* } && { ! x32 } } } } + { dg-options "-fcheck-pointer-bounds -mmpx" } */ + +int f (int i) +{ + struct A { int n; char a[]; }; + + return ((struct A){ 1, "" }).a[i]; // { dg-error "invalid use of array" } +} diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index b1ff218..780d18f 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -4092,6 +4092,10 @@ chkp_process_stmt (gimple_stmt_iterator *iter, tree node, expression to compute it. */ if (!addr_last) { + /* C++ flexible array members have a null size. */ + if (!size) + return; + addr_last = fold_build_pointer_plus_loc (loc, addr_first, size); addr_last = fold_build_pointer_plus_hwi_loc (loc, addr_last, -1); } --------------29511FF47269C25644E95678--