From patchwork Fri May 7 09:21:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1475414 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; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=VeFLVO2E; 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 4Fc4rn1SjGz9sj5 for ; Fri, 7 May 2021 19:28:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2009B3892440; Fri, 7 May 2021 09:28:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 576B53835815 for ; Fri, 7 May 2021 09:28:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 576B53835815 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wm1-x32f.google.com with SMTP id t11-20020a05600c198bb02901476e13296aso4500078wmq.0 for ; Fri, 07 May 2021 02:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rIBoAqeKIyca8uAAhCTp46NZ/zdS1loU6COa6P6kXgI=; b=VeFLVO2EWYkHZH1SAhtnlEJX0xwbKTPjsi3XnI+ooEiN8/tjIJK2005MRDFyePSLjt fJBypAWGs7Z2ff5wsPEAACVuGWGQ92MMIbFgewVyP/Q7KaAo62nJlVfCXK2ikDShJmYk of9/TBrGxQBoCh6bC+JDQk2qSoM7ZZR2IiKbPMCe8A4E3iExoWIwRUrSvfS/Kk3zvBxB S/LjQ0FntYpkeH6DVqENY8F1fIMEcOQM5TUrgkccT9u6B9mLds0S1Zn3u2f8J3FzDBWm AHY2QEOSby3CIacTmwcrGfLkn3WIOZ8lTK09QKJYn9fvXYu0zAO+fbgcwhMapqMwS3Et DVAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rIBoAqeKIyca8uAAhCTp46NZ/zdS1loU6COa6P6kXgI=; b=Ao++lWxrLNR9oidm+AGHSApIE8QBIneIQuERC1msvr9aZ3ikoMe4fLL5foxtm0xqr8 J4GTwFJ1+mh99pNqsaFVhbLJ6IWVLdv1yzGztIRj9hBXuQAZgiGapqtDGCBadtuPnC8a HYUxjsBSqyqlz+DScet+4N7FyhVhtrVrLAwWgIrTJeXZ2Es5WuOus/yCpI4HaaQNn1SA k9ARhsIXTJD8D6jMsTIvhgV6UtBXZWXCZDw/EaZvX4TVswVXhGhw4fhATTYMyQY1X453 fNyKj+lOhcxWuMiEtYAm9oa0skykopajRZiQGwsABLUrE2shMuuLl0Ib+Qw7q9U/3qAR gorg== X-Gm-Message-State: AOAM531ZvRj8mx3ePjtozxIu1Yo2LBBtM3bBI/raBPviHNgvIPnU5IP2 dwbkC//rgF9/PAWEQF8f+y1+702WLId6r7hn X-Google-Smtp-Source: ABdhPJwLtiDMMBJcoPtwkgu2BQ9SXjS1IgPrEXjmfe1YmpqlputdV/IQzGyKS6EQ3rru4EdZQFFiRw== X-Received: by 2002:a1c:7516:: with SMTP id o22mr19747066wmc.91.1620379730294; Fri, 07 May 2021 02:28:50 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id c8sm12655364wmr.48.2021.05.07.02.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 02:28:49 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Do not apply scalar storage order to pointer fields Date: Fri, 07 May 2021 11:21:25 +0200 Message-ID: <1757013.atdPhlSkOF@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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: , Cc: Ulrich Weigand Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, I didn't really think of pointer fields (nor of vector fields originally) when implementing the scalar_storage_order attribute, so they are swapped as well. As Ulrich pointed out, this is problematic to describe in DWARF and probably not very useful in any case, so the attached patch pulls them out. Tested on x86-64/Linux, OK for mainline? 2021-05-07 Eric Botcazou * doc/extend.texi (scalar_storage_order): Mention effect on pointer and vector fields. * tree.h (reverse_storage_order_for_component_p): Return false if the type is a pointer. c/ * c-typeck.c (build_unary_op) : Do not issue an error on the address of a pointer field in a record with reverse SSO. 2021-05-07 Eric Botcazou * gcc.dg/sso-12.c: New test. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index fdc7bb6125c..5bdc673d03a 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -4866,6 +4866,7 @@ build_unary_op (location_t location, enum tree_code code, tree xarg, if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0)))) { if (!AGGREGATE_TYPE_P (TREE_TYPE (arg)) + && !POINTER_TYPE_P (TREE_TYPE (arg)) && !VECTOR_TYPE_P (TREE_TYPE (arg))) { error_at (location, "cannot take address of scalar with " diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index c8caf36f293..fd9175d1b3b 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -8551,6 +8551,9 @@ or an array whose component is a @code{union} or a @code{struct}, and it is possible for these fields to have a different scalar storage order than the enclosing type. +Note that neither pointer nor vector fields are considered scalar fields in +this context, so the attribute has no effects on these fields. + This attribute is supported only for targets that use a uniform default scalar storage order (fortunately, most of them), i.e.@: targets that store the scalars either all in big-endian or all in little-endian. diff --git a/gcc/tree.h b/gcc/tree.h index 6d3cfc4c588..784452ca490 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4989,7 +4989,9 @@ static inline bool reverse_storage_order_for_component_p (tree t) { /* The storage order only applies to scalar components. */ - if (AGGREGATE_TYPE_P (TREE_TYPE (t)) || VECTOR_TYPE_P (TREE_TYPE (t))) + if (AGGREGATE_TYPE_P (TREE_TYPE (t)) + || POINTER_TYPE_P (TREE_TYPE (t)) + || VECTOR_TYPE_P (TREE_TYPE (t))) return false; if (TREE_CODE (t) == REALPART_EXPR || TREE_CODE (t) == IMAGPART_EXPR)