From patchwork Fri May 3 09:22:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1930979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AMv2G9Uo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VW53l1bNPz20fb for ; Fri, 3 May 2024 19:24:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B6F6384641A for ; Fri, 3 May 2024 09:24:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 7C0003858C66 for ; Fri, 3 May 2024 09:24:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C0003858C66 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7C0003858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714728252; cv=none; b=My/RlQKYBRFFFg09/AmMkX9NUV51zY5gwAVa38ZS+QwNaBoue6EtPXPpmYfKUnYueY8TdMSGO438forYWPU64IKLzZzxbGg1kNr2Q6+YY/2zd6d7e8e7e4gHsIz6SNZT11BCve77aBlpu94ylAqwyXxFyPG3+JcCN5gmCbsaufM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714728252; c=relaxed/simple; bh=UWwLedKtGcaNgdc958xwFOtrgGTlV1ifIKXl8yDU+IY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MicKhrJ4ueB7XCIyrjj9nONc4kj714+K6ragM88JtZQc5av8gOrJsoN5/YZ4rEYMtzXwNaBvzBWGEjecvIRzvbHPvNoxJyhH/f1H8jEigRgb5EOebZxp3hP3Edk4K6k2Bx9mYGhPzh78UxQGSUpG7rdbWCtAEstrUaaxcOY0xdU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714728249; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mEuLPENoLzbwy2Imr52z7SFn840B359XW0VaItaxUvg=; b=AMv2G9Uo8wsJ5ac8MOXvI3KfsxlbM5znZ0ojbJEn5kd4frMkwGPshccCEQI7+yGMjtQalL sweBtoXttAK2upKbRSmi6QywR8Z573nGY9nkTqhG73X/D8IkM3mClQyvd7EPhlsrr8yKaF fnLTRgGz3p53jPcd7NoKZD9qzrCyxyY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-fz7IhIfQOC-IJ1KrvJS9vw-1; Fri, 03 May 2024 05:24:06 -0400 X-MC-Unique: fz7IhIfQOC-IJ1KrvJS9vw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DA720800CA2; Fri, 3 May 2024 09:24:05 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.97]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EFE3203397D; Fri, 3 May 2024 09:24:05 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.2/8.17.1) with ESMTPS id 4439O3lx474159 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 3 May 2024 11:24:03 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.2/8.17.2/Submit) id 4439O3WV474158; Fri, 3 May 2024 11:24:03 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Andrew Pinski , Aldy Hernandez Subject: [PATCH] [ranger] Force buffer alignment in Value_Range [PR114912] Date: Fri, 3 May 2024 11:22:50 +0200 Message-ID: <20240503092307.474116-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sparc requires strict alignment and is choking on the byte vector in Value_Range. Is this the right approach, or is there a more canonical way of forcing alignment? If this is correct, OK for trunk? gcc/ChangeLog: * value-range.h (class Value_Range): Use a union. --- gcc/value-range.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/gcc/value-range.h b/gcc/value-range.h index 934eec9e386..31af7888018 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -740,9 +740,14 @@ private: void init (const vrange &); vrange *m_vrange; - // The buffer must be at least the size of the largest range. - static_assert (sizeof (int_range_max) > sizeof (frange), ""); - char m_buffer[sizeof (int_range_max)]; + union { + // The buffer must be at least the size of the largest range, and + // be aligned on a word boundary for strict alignment targets + // such as sparc. + static_assert (sizeof (int_range_max) > sizeof (frange), ""); + char m_buffer[sizeof (int_range_max)]; + void *align; + } u; }; // The default constructor is uninitialized and must be initialized @@ -816,11 +821,11 @@ Value_Range::init (tree type) gcc_checking_assert (TYPE_P (type)); if (irange::supports_p (type)) - m_vrange = new (&m_buffer) int_range_max (); + m_vrange = new (&u.m_buffer) int_range_max (); else if (frange::supports_p (type)) - m_vrange = new (&m_buffer) frange (); + m_vrange = new (&u.m_buffer) frange (); else - m_vrange = new (&m_buffer) unsupported_range (); + m_vrange = new (&u.m_buffer) unsupported_range (); } // Initialize object with a copy of R. @@ -829,11 +834,12 @@ inline void Value_Range::init (const vrange &r) { if (is_a (r)) - m_vrange = new (&m_buffer) int_range_max (as_a (r)); + m_vrange = new (&u.m_buffer) int_range_max (as_a (r)); else if (is_a (r)) - m_vrange = new (&m_buffer) frange (as_a (r)); + m_vrange = new (&u.m_buffer) frange (as_a (r)); else - m_vrange = new (&m_buffer) unsupported_range (as_a (r)); + m_vrange + = new (&u.m_buffer) unsupported_range (as_a (r)); } // Assignment operator. Copying incompatible types is allowed. That