From patchwork Fri Dec 6 09:11:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 297644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DE5112C00A8 for ; Fri, 6 Dec 2013 20:12:17 +1100 (EST) 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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=H6MVYpAsdRRhMsMjMmUn98oRy5sDLCTByEJzWS+nvYu+K5oecbUYU l2x7aFeQGSjm98SGxE6pjJIncD54NifrjIWKWQjf2WKAn4lR60gTR4fFrNJzkdTE CcZbEIh4kfDIJt75WsqmsL0lCZzcosqrPTJl4K+QlN0r23tO0wWUIc= 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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=4EEgnSqnJvKLKuTkiMFBXa92PHM=; b=u/OzdChHipQKjOVi+L4um4Tl/6ou 9Yt3/nquCpdzdiIeiILvUrFd6tXp8vJ7G2JboB/fsTReYcyHb8yNeKRFK5AmEjPp zIHL3+vyNcaNovXvqMoh0sk5rR5EdhEL8ybqOY9AIKt1Dq/CaMYmm8sjLdbzqEIb 3u7afgsR00BskL0= Received: (qmail 26241 invoked by alias); 6 Dec 2013 09:12:11 -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 26229 invoked by uid 89); 6 Dec 2013 09:12:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from Unknown (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 06 Dec 2013 09:12:11 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 3D85A26C04E3; Fri, 6 Dec 2013 10:12:02 +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 fzuQhTTy_MhH; Fri, 6 Dec 2013 10:12:02 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 19B3426C005D; Fri, 6 Dec 2013 10:12:02 +0100 (CET) From: Eric Botcazou To: Bernd Edlinger Cc: gcc-patches@gcc.gnu.org, Jeff Law , Richard Biener , Jakub Jelinek Subject: Re: [REPOST] Invalid Code when reading from unaligned zero-sized array Date: Fri, 06 Dec 2013 10:11:38 +0100 Message-ID: <55501474.8ce4n3Il8S@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.29-desktop; KDE/4.7.2; x86_64; ; ) In-Reply-To: <2249139.y74dSSf1GI@polaris> References: <2249139.y74dSSf1GI@polaris> MIME-Version: 1.0 > Here's the Correct Fix(tm). We may or may not decide to go for it because > of concerns about ABI changes; in the latter case, any kludge that we'll > put in place instead must be restricted to the cases caught by this patch. > > > * stor-layout.c (compute_record_mode): Return BLKmode for a trailing > array with size 0 or 1. Revised version without the one-by-one error... Index: stor-layout.c =================================================================== --- stor-layout.c (revision 205727) +++ stor-layout.c (working copy) @@ -1605,6 +1605,17 @@ compute_record_mode (tree type) || ! tree_fits_uhwi_p (DECL_SIZE (field))) return; + /* As a GNU extension, we support out-of-bounds accesses for a trailing + array with size 0 or 1. In this case, the record type effectively + has variable size so it needs to have BLKmode. */ + if (!DECL_CHAIN (field) && TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE) + { + tree domain_type = TYPE_DOMAIN (TREE_TYPE (field)); + if (!TYPE_MAX_VALUE (domain_type) + || integer_zerop (TYPE_MAX_VALUE (domain_type))) + return; + } + /* If this field is the whole struct, remember its mode so that, say, we can put a double in a class into a DF register instead of forcing it to live in the stack. */