From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42291 invoked by alias); 30 Jul 2018 20:16:39 -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 42270 invoked by uid 89); 30 Jul 2018 20:16:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=sk:COMPLE, sk:!comple, sk:!COMPLE, sk:comple X-HELO: mail-qk0-f172.google.com Received: from mail-qk0-f172.google.com (HELO mail-qk0-f172.google.com) (209.85.220.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Jul 2018 20:16:37 +0000 Received: by mail-qk0-f172.google.com with SMTP id 26-v6so8723080qks.9 for ; Mon, 30 Jul 2018 13:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version; bh=zWw7a/XU36ilsu+NgkZgyRJY/T/6IN/qk75syIyScmc=; b=XRxn/+9+LaUBQ5DPCW6KQlA4myQQOK15zXiyG8YL1ei61gZKK7JDCoQQQnRXCuDnwy c0q84BeX3VRaTCjk22mvO+YxBjrEYHJjguN8kJibR8pkgfRcZ7BOAP6UTR43C8yHXsJt HfQgAXwud/0imOcIDAbo/NhPNzYJxwwZ1jpoKorq+yBf22LakPiNW4TSmDzgUZf79Apj buv/vDxDLA556JbkkXdDoOo1xuw60l+hxdHghQUFRLnHEy1HGlS6B3HJ10v1Hbn1ImLF DfLdy0dxt62fPVQTCCl4/sCJrEYDkxK7THdFfu1cfTOkWbt3ItNvVmohgvo46l6/P/hv jNtQ== Return-Path: Received: from localhost.localdomain (97-118-124-30.hlrn.qwest.net. [97.118.124.30]) by smtp.gmail.com with ESMTPSA id d80-v6sm9798510qka.33.2018.07.30.13.16.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jul 2018 13:16:34 -0700 (PDT) From: Martin Sebor Subject: [PATCH] avoid incomplete types in -Warray-bounds (PR 86741) To: Gcc Patch List Message-ID: Date: Mon, 30 Jul 2018 20:16:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------31968DBAE267B72B90594F5C" X-IsSubscribed: yes X-SW-Source: 2018-07/txt/msg01876.txt.bz2 This is a multi-part message in MIME format. --------------31968DBAE267B72B90594F5C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 335 The enhanced handling of MEM_REFs in -Warray-bounds assumes the object from whose address an offset is being computed has a complete type. Since the size of such objects isn't known, whether the offset (or index) from its beginning is valid cannot be reliably determined. The attached patch avoids dealing with such objects. Martin --------------31968DBAE267B72B90594F5C Content-Type: text/x-patch; name="gcc-86741.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-86741.diff" Content-length: 1953 PR tree-optimization/86741 - ICE in -Warray-bounds indexing into an object of incomplete type gcc/ChangeLog: PR tree-optimization/86741 * tree-vrp.c (vrp_prop::check_mem_ref): Avoid incomplete types. gcc/testsuite/ChangeLog: PR tree-optimization/86741 * gcc.dg/Warray-bounds-33.c: New test. Index: gcc/testsuite/gcc.dg/Warray-bounds-33.c =================================================================== --- gcc/testsuite/gcc.dg/Warray-bounds-33.c (nonexistent) +++ gcc/testsuite/gcc.dg/Warray-bounds-33.c (working copy) @@ -0,0 +1,36 @@ +/* PR tree-optimization/86741 - ICE in -Warray-bounds indexing into + an object of incomplete type + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +struct S +{ + int s; +}; + +void f (void); + +void test_void (void) +{ + extern void v; + struct S *b = (struct S*)&v; + if (b->s) + f (); +} + +void test_incomplete_enum (void) +{ + extern enum E e; + struct S *b = (struct S*)&e; + if (b->s) + f (); +} + +void test_func (void) +{ + struct S *b = (struct S*)&f; + if (b->s) + f (); +} + +/* { dg-prune-output "taking address of expression of type .void." } */ Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 263072) +++ gcc/tree-vrp.c (working copy) @@ -5048,9 +5048,12 @@ vrp_prop::check_mem_ref (location_t location, tree a reference/subscript via a pointer to an object that is not an element of an array. References to members of structs and unions are excluded because MEM_REF doesn't make it possible - to identify the member where the reference originated. */ + to identify the member where the reference originated. + Incomplete types are excluded as well because their size is + not known. */ tree reftype = TREE_TYPE (arg); if (POINTER_TYPE_P (reftype) + || !COMPLETE_TYPE_P (reftype) || RECORD_OR_UNION_TYPE_P (reftype)) return; --------------31968DBAE267B72B90594F5C--