From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0laqDOXxp2CVAwAAWB0awg (envelope-from ) for ; Fri, 21 May 2021 13:46:13 -0400 Received: by simark.ca (Postfix, from userid 112) id 24B371F11C; Fri, 21 May 2021 13:46:13 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 simark.ca (Postfix) with ESMTPS id 74E3F1E813 for ; Fri, 21 May 2021 13:46:12 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB3BE39960E6; Fri, 21 May 2021 17:46:11 +0000 (GMT) Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id A12353847832 for ; Fri, 21 May 2021 17:46:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A12353847832 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jhb@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 6C51BA70E8; Fri, 21 May 2021 17:46:09 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FmvD12NDQz4pMR; Fri, 21 May 2021 17:46:09 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro.local (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id CF8996FC4; Fri, 21 May 2021 17:46:08 +0000 (UTC) (envelope-from jhb@FreeBSD.org) To: gdb-patches@sourceware.org, luis.machado@linaro.org References: <20210519174537.17278-1-jhb@FreeBSD.org> From: John Baldwin Subject: Re: [PATCH] sim/d10v: Use offsetof in a static assertion about structure layout. Message-ID: <5d80d289-9a53-ef2e-c40a-f9766eef5dc0@FreeBSD.org> Date: Fri, 21 May 2021 10:46:04 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 5/19/21 4:35 PM, Mike Frysinger wrote: > On 19 May 2021 10:45, John Baldwin wrote: >> clang 11 fails to compile the static assertion as it cannot compute >> the pointer value at a compile time: >> >> gdb/sim/d10v/interp.c:1149:37: error: static_assert expression is not an integral constant expression >> static_assert ((uintptr_t) &State == (uintptr_t) &State.regs, >> ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ >> 1 error generated. >> >> Instead, assert that the offset of State.regs is 0. > > idea is good ... > >> --- a/sim/d10v/interp.c >> +++ b/sim/d10v/interp.c >> >> - static_assert ((uintptr_t) &State == (uintptr_t) &State.regs, >> - "&State != &State.regs"); >> + static_assert (offsetof(typeof(State), regs) == 0, > > stylewise: > * need space before the ( > * i think we want __typeof since it's not in C11 afaik Oh, yes. I had forgotten that it typeof() is an extension. It might be simpler to just use the type directly: diff --git a/sim/d10v/interp.c b/sim/d10v/interp.c index b56b204c72d..b587cc18654 100644 --- a/sim/d10v/interp.c +++ b/sim/d10v/interp.c @@ -1146,8 +1146,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, bfd_vma start_address; /* Make sure we have the right structure for the following memset. */ - static_assert ((uintptr_t) &State == (uintptr_t) &State.regs, - "&State != &State.regs"); + static_assert (offsetof (struct _state, regs) == 0, + "State.regs is not at offset 0"); /* Reset state from the regs field until the mem field. */ memset (&State, 0, (uintptr_t) &State.mem - (uintptr_t) &State.regs); -- John Baldwin