From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id dkVNH9dOpWCyQAAAWB0awg (envelope-from ) for ; Wed, 19 May 2021 13:45:59 -0400 Received: by simark.ca (Postfix, from userid 112) id 71E321F11C; Wed, 19 May 2021 13:45:59 -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 B714F1E54D for ; Wed, 19 May 2021 13:45:58 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 326853947414; Wed, 19 May 2021 17:45:58 +0000 (GMT) Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 9FBDF3898537 for ; Wed, 19 May 2021 17:45:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9FBDF3898537 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=jhb@FreeBSD.org Received: from ralph.baldwin.cx (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 472EF1A84C54; Wed, 19 May 2021 13:45:52 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH] sim/d10v: Use offsetof in a static assertion about structure layout. Date: Wed, 19 May 2021 10:45:37 -0700 Message-Id: <20210519174537.17278-1-jhb@FreeBSD.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Wed, 19 May 2021 13:45:52 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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. sim/d10v/ChangeLog: * interp.c (sim_create_inferior): Use offsetof in static assertion. --- sim/d10v/ChangeLog | 5 +++++ sim/d10v/interp.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sim/d10v/ChangeLog b/sim/d10v/ChangeLog index e45bd3833b0..d799d238db9 100644 --- a/sim/d10v/ChangeLog +++ b/sim/d10v/ChangeLog @@ -1,3 +1,8 @@ +2021-05-19 John Baldwin + + * interp.c (sim_create_inferior): Use offsetof in static + assertion. + 2021-05-17 Mike Frysinger * sim-main.h (SIM_HAVE_COMMON_SIM_STATE): Delete. diff --git a/sim/d10v/interp.c b/sim/d10v/interp.c index b56b204c72d..ee242f766f6 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(typeof(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); -- 2.31.1