From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id UnoSFiz0F2egKxcAWB0awg (envelope-from ) for ; Tue, 22 Oct 2024 14:51:24 -0400 Received: by simark.ca (Postfix, from userid 112) id 3FCDE1E0BB; Tue, 22 Oct 2024 14:51:24 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.7 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 200391E05C for ; Tue, 22 Oct 2024 14:51:23 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7BC43858D39 for ; Tue, 22 Oct 2024 18:51:22 +0000 (GMT) Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by sourceware.org (Postfix) with ESMTPS id 0D4B53858D21 for ; Tue, 22 Oct 2024 18:51:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D4B53858D21 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=andrewoates.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0D4B53858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729623063; cv=none; b=mqmcCIeJgtqqcOzesSifb06xw4r3RAHoYJIJoFF1qdXEby56Gn5g/R75RQAvi14ZKlwqFESqeiHV0u44qduznxwxT6hjDQDOP2BJRbnYBX0fyK4SUHWGYLe6zpvPrvVrP1JJadDApw0DHpsbKmqFYzlqvgWXXUZ0LpFdjK+Fby0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729623063; c=relaxed/simple; bh=u3o8sOn4MMjtRbiAsnyBSrhppBcyG5ZuAgNylRWvX20=; h=MIME-Version:From:Date:Message-ID:Subject:To; b=G1/Y6D1Wohll0NrFOqC6JJKvRIYcG9xcfHISpc77HbnNpOieoAfOrsFj36gfWUtdXfCtocCnr8plGabbYeXY7lZyD6OA2ZYzJzIsnQQJJZbFMSo8tBBldWkmeTKvAnv9ut1eSNOu/gAnG83vQz2vaI+WE+vXBhuDBlMO1iBm1pI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3e60e57a322so1742731b6e.3 for ; Tue, 22 Oct 2024 11:51:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729623060; x=1730227860; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O0DguNLXWS1V/IWJZEGsnqeAMN9drA4M9qJnXAf7IOA=; b=GaYrXW/S2b74bmhbJ7qvV2GePgIy3RfOgYqvLRJ7A5fAOlNuq3LGD2ew7XoQ4qprcw 5dtG8OOas0fgaMUol1uTZFwf70LzAb+0746ZH+H4/Me9gSS1jlQHDnTHrZPgMizmbnY0 Fzjr/ho8Bq6DK49tsTOBXVmUdKaxjAjVa89zeWNMBylpUS3t6oGndE0Uvc9ERH7j+epE GDmcmoqUOjiUrBkzKwTG2WuJV8ShT9KlyYs9eJ+667mbb8nL2glnWH9KZ9qs/W6c954b tPQaNtsLYB4i8DH7YOI7rf+PF56JfcTT/EkxJJFeD8MzRZRwN5UX+Hn7MSwH/+g/Uouh mT7Q== X-Gm-Message-State: AOJu0YwO5tiq3rMQU9FDjrXy/5pmhLu8MtAM1N2RhkACPUESuzmsmQTA bG8jZ3xJLrMuNm6/LiEnsyYMdaa+R3Flz5jcOlMo3aHcHo9kocXcKtkqrWzUKJZaQniemNoW8rX lfiI+iL4W+cTm2D70jD/9ipw2qa9QOwRo X-Google-Smtp-Source: AGHT+IGVUIYyY5ypDqGWRj1mQF4gUqKTRaO32Vu9UHeV6OAo3OjJiEkjbfS588U3suSqoI5/MRonroOiiyS5oZkNTmk= X-Received: by 2002:a05:6808:2e49:b0:3e5:fd66:c16b with SMTP id 5614622812f47-3e6245aea68mr104938b6e.33.1729623060236; Tue, 22 Oct 2024 11:51:00 -0700 (PDT) MIME-Version: 1.0 References: <20241020180001.67425-1-andrew@andrewoates.com> In-Reply-To: From: Andrew Oates Date: Tue, 22 Oct 2024 14:50:49 -0400 Message-ID: Subject: Re: [PATCH] Fix compile error due to [[noreturn]] with clang To: Guinevere Larsen Cc: gdb-patches@sourceware.org Content-Type: multipart/alternative; boundary="00000000000019d3860625154086" X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org --00000000000019d3860625154086 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Oct 22, 2024 at 2:29=E2=80=AFPM Guinevere Larsen wrote: > On 10/20/24 3:00 PM, andrew@andrewoates.com wrote: > > From: Andrew Oates > > > > Since commit d9deb60b2e9e94b532f43a7d3ddddf5ddf6dbdd3, I get the > > following compiler error when building binutils (cross-compiling) on > > macos: > > > > CXX remote-sim.o > > ../../gdb/remote-sim.c:334:28: error: assigning to 'void > (*)(host_callback *, const char *, ...) __attribute__((noreturn))' (aka > 'void (*)(host_callback_struct *, const char *, ...) > __attribute__((noreturn))') from incompatible type 'void (host_callback > > *, const char *, ...)' (aka 'void (host_callback_struct *, const char *= , > ...)') > > gdb_callback.error =3D gdb_os_error; > > ^~~~~~~~~~~~ > > 1 error generated. > > > > This appears to be due to the mismatch between ATTRIBUTE_NORETURN and > > [[noreturn]] on gdb_os_error. Removing ATTTRIBUTE_NORETURN on the > > declaration of host_callback::error resolves the issue. > > Have you tried using ATTRIBUTE_NORETURN for gdb_os_error instead? If the > problem is the mismatch, I would prefer that we made them match over > removing information for the compiler. > gdb_os_error used to have ATTRIBUTE_NORETURN on it, but that was removed in favor of [[noreturn]] in commit d9deb60b2e9e94b532f43a7d3ddddf5ddf6dbdd3 (which seems to have done ATTRIBUTE_NORETURN -> [[noreturn]] through most of the codebase). I'm definitely not an expert here, but I agree that if there's a way to annotate the function pointer instead so it can be assigned to a [[noreturn]] function, that would be better. I tried doing that but couldn't make it work. > > Also, from my little knowledge in this area, this sounds like a clang > bug. I encourage you to report it to upstream clang, or I can do it > myself if you'd prefer. > Ah...maybe. That didn't occur to me, but you could be right, if clang should be recognizing __attribute__((noreturn)) as equivalent to [[noreturn]]. > > -- > Cheers, > Guinevere Larsen > She/Her/Hers > > > > > Tested by compiling on macos both with the system clang, as well as wit= h > > GCC 14. With clang, remote-sim.c does not compile (per above) without > > this patch. With GCC, it compiles with and without the patch (it > > doesn't link, but AFAICT that is unrelated). > > --- > > include/sim/callback.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/include/sim/callback.h b/include/sim/callback.h > > index f69f783abac..045ac3411af 100644 > > --- a/include/sim/callback.h > > +++ b/include/sim/callback.h > > @@ -129,7 +129,7 @@ struct host_callback_struct > > In the case of gdb "exiting" means doing a longjmp back to the > main > > command loop. */ > > void (*error) (host_callback *, const char *, ...) > > - ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_2; > > + ATTRIBUTE_PRINTF_2; > > > > int last_errno; /* host format */ > > > > --00000000000019d3860625154086 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Oct 22, 2024 at 2:29=E2=80=AF= PM Guinevere Larsen <guinevere@r= edhat.com> wrote:
On 10/20/24 3:00 PM, andrew@andrewoates.com wrote:
> From: Andrew Oates <andrew@andrewoates.com>
>
> Since commit d9deb60b2e9e94b532f43a7d3ddddf5ddf6dbdd3, I get the
> following compiler error when building binutils (cross-compiling) on > macos:
>
>=C2=A0 =C2=A0CXX=C2=A0 =C2=A0 remote-sim.o
> ../../gdb/remote-sim.c:334:28: error: assigning to 'void (*)(host_= callback *, const char *, ...) __attribute__((noreturn))' (aka 'voi= d (*)(host_callback_struct *, const char *, ...) __attribute__((noreturn))&= #39;) from incompatible type 'void (host_callback
> *, const char *, ...)' (aka 'void (host_callback_struct *, con= st char *, ...)')
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 gdb_callback.error =3D gdb_os_error;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^~~~~~~~~~~~
> 1 error generated.
>
> This appears to be due to the mismatch between ATTRIBUTE_NORETURN and<= br> > [[noreturn]] on gdb_os_error.=C2=A0 Removing ATTTRIBUTE_NORETURN on th= e
> declaration of host_callback::error resolves the issue.

Have you tried using ATTRIBUTE_NORETURN for gdb_os_error instead? If the problem is the mismatch, I would prefer that we made them match over
removing information for the compiler.

= gdb_os_error used to have ATTRIBUTE_NORETURN on it, but that was removed in= favor of [[noreturn]] in commit=C2=A0d9deb60b2e9e94b532f43a7d3ddddf5ddf6db= dd3 (which seems to have done ATTRIBUTE_NORETURN -> [[noreturn]] through= most of the codebase).

I'm definitely not an = expert here, but I agree that if there's a way to annotate the function= pointer instead so it can be assigned to a [[noreturn]] function, that wou= ld be better.=C2=A0 I tried doing that but couldn't make it work.
=
=C2=A0

Also, from my little knowledge in this area, this sounds like a clang
bug. I encourage you to report it to upstream clang, or I can do it
myself if you'd prefer.

Ah...maybe.= =C2=A0 That didn't occur to me, but you could be right, if clang should= be recognizing __attribute__((noreturn)) as equivalent to [[noreturn]].
=C2=A0

--
Cheers,
Guinevere Larsen
She/Her/Hers

>
> Tested by compiling on macos both with the system clang, as well as wi= th
> GCC 14.=C2=A0 With clang, remote-sim.c does not compile (per above) wi= thout
> this patch.=C2=A0 With GCC, it compiles with and without the patch (it=
> doesn't link, but AFAICT that is unrelated).
> ---
>=C2=A0 =C2=A0include/sim/callback.h | 2 +-
>=C2=A0 =C2=A01 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/sim/callback.h b/include/sim/callback.h
> index f69f783abac..045ac3411af 100644
> --- a/include/sim/callback.h
> +++ b/include/sim/callback.h
> @@ -129,7 +129,7 @@ struct host_callback_struct
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 In the case of gdb "exiting" mean= s doing a longjmp back to the main
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 command loop.=C2=A0 */
>=C2=A0 =C2=A0 =C2=A0void (*error) (host_callback *, const char *, ...)<= br> > -=C2=A0 =C2=A0 ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_2;
> +=C2=A0 =C2=A0 ATTRIBUTE_PRINTF_2;
>=C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0int last_errno;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0/* host format */
>=C2=A0 =C2=A0

--00000000000019d3860625154086--