From patchwork Tue Jan 16 23:12:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 861932 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-471438-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="l266OGKk"; 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 3zLmGC6cgXz9s7n for ; Wed, 17 Jan 2018 10:12:35 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=G5GekxPu20A+hmrw ew4jomJVC+jw6F/1tR1TAhs3ttgAoxS1zHA627q4/8aKu2FV5prCpO4a+a/REJ6e iLLQwVfwSuoJEuqOWxrLCmndctKauruXCrvB74xVgrDWLxaeQndCSt1wgppoZnvN q6CIMbkuxd76gQb9S0mHTMmbmck= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=s7JdlZaJD2qS6fRjUnsR2S Iu4XY=; b=l266OGKkamzCsUBQZCMBrkOTukqvlgIO0Ke6DasYN2lkqnEUR8haAK vD0uKWQbmFTwWWghdvUnavp/knniSZ5cgTjqqU6U6S2bSRMEttWl98E6MTL6k5Rx L5MdNMKwOuvrsAnMXiRmjxd0rtV8v220edL4cHUXHh0E1faD3jOr4= Received: (qmail 122593 invoked by alias); 16 Jan 2018 23:12:28 -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 122579 invoked by uid 89); 16 Jan 2018 23:12:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=1998 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Jan 2018 23:12:25 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 62CE481392 for ; Wed, 17 Jan 2018 00:12:23 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hTIEK3-74MR6 for ; Wed, 17 Jan 2018 00:12:23 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 38B368138F for ; Wed, 17 Jan 2018 00:12:23 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Fix Warray-bounds-3.c on Visium Date: Wed, 17 Jan 2018 00:12:22 +0100 Message-ID: <3394833.P0ZvxX0x16@polaris> MIME-Version: 1.0 This test fails on Visium because of 3 separate issues. The first one is benign, it's a warning about a pointer mismatch between int32_t* and int* (On most newlib targets, int32_t is long int instead of int) in the test. The other 2 are in the code itself (but cancel each other on most targets): builtin_memref::builtin_memref contains these lines: /* Determine the base object or pointer of the reference and its constant offset from the beginning of the base. */ base = get_addr_base_and_unit_offset (oper, &off); HOST_WIDE_INT const_off; if (base && off.is_constant (&const_off)) { offrange[0] += const_off; offrange[1] += const_off; /* Stash the reference for offset validation. */ ref = oper; /* Also stash the constant offset for offset validation. */ tree_code code = TREE_CODE (oper); if (code == COMPONENT_REF) { tree field = TREE_OPERAND (ref, 1); tree fldoff = DECL_FIELD_OFFSET (field); if (TREE_CODE (fldoff) == INTEGER_CST) refoff = const_off + wi::to_offset (fldoff); } } The first problem is that DECL_FIELD_OFFSET doesn't return the offset of a field, it's byte_position because DECL_FIELD_BIT_OFFSET needs to be taken into account: /* In a FIELD_DECL, this is the offset, in bits, of the first bit of the field from DECL_FIELD_OFFSET. This field may be nonzero even for fields that are not bit fields (since DECL_OFFSET_ALIGN may be larger than the natural alignment of the field's type). */ #define DECL_FIELD_BIT_OFFSET(NODE) \ (FIELD_DECL_CHECK (NODE)->field_decl.bit_offset) But replacing DECL_FIELD_OFFSET with byte_position is actually worse, because the offset of the field is then counted twice in refoff since it is already comprised in const_off. In the end, the correct thing to do is just to equate refoff and const_off. Tested on visium-elf & x86_64-suse-linux, applied on the mainline as obvious. 2018-01-16 Eric Botcazou * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): For an ADDR_EXPR, do not count the offset of a COMPONENT_REF twice. 2018-01-16 Eric Botcazou * c-c++-common/Warray-bounds-3.c (test_memmove_bounds): Fix mismatch. Index: gimple-ssa-warn-restrict.c =================================================================== --- gimple-ssa-warn-restrict.c (revision 256562) +++ gimple-ssa-warn-restrict.c (working copy) @@ -312,11 +312,11 @@ builtin_memref::builtin_memref (tree exp if (TREE_CODE (expr) == ADDR_EXPR) { poly_int64 off; - tree oper = TREE_OPERAND (expr, 0); + tree op = TREE_OPERAND (expr, 0); /* Determine the base object or pointer of the reference and its constant offset from the beginning of the base. */ - base = get_addr_base_and_unit_offset (oper, &off); + base = get_addr_base_and_unit_offset (op, &off); HOST_WIDE_INT const_off; if (base && off.is_constant (&const_off)) @@ -325,17 +325,11 @@ builtin_memref::builtin_memref (tree exp offrange[1] += const_off; /* Stash the reference for offset validation. */ - ref = oper; + ref = op; /* Also stash the constant offset for offset validation. */ - tree_code code = TREE_CODE (oper); - if (code == COMPONENT_REF) - { - tree field = TREE_OPERAND (ref, 1); - tree fldoff = DECL_FIELD_OFFSET (field); - if (TREE_CODE (fldoff) == INTEGER_CST) - refoff = const_off + wi::to_offset (fldoff); - } + if (TREE_CODE (op) == COMPONENT_REF) + refoff = const_off; } else { Index: testsuite/c-c++-common/Warray-bounds-3.c =================================================================== --- testsuite/c-c++-common/Warray-bounds-3.c (revision 256562) +++ testsuite/c-c++-common/Warray-bounds-3.c (working copy) @@ -199,7 +199,8 @@ void test_memmove_bounds (char *d, const T (int, 2, a + SR ( 1, 3), pi, n); T (int, 2, a + SR ( 2, 3), pi, n); - T (int32_t, 2, a + SR ( 3, 4), pi, n); /* { dg-warning "offset \\\[12, 16] is out of the bounds \\\[0, 8] of object .\[^\n\r]+. with type .int32_t ?\\\[2]." } */ + const int32_t *pi32 = (const int32_t*)s; + T (int32_t, 2, a + SR ( 3, 4), pi32, n); /* { dg-warning "offset \\\[12, 16] is out of the bounds \\\[0, 8] of object .\[^\n\r]+. with type .int32_t ?\\\[2]." } */ }