public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Joseph Myers <joseph@codesourcery.com>,
	Marek Polacek <polacek@redhat.com>,
	gcc-patches@gcc.gnu.org, libc-alpha@sourceware.org
Subject: Re: [RFC] Add stdckdint.h header for C23
Date: Wed, 14 Jun 2023 08:49:30 +0200	[thread overview]
Message-ID: <ZIli+miHB7qbe9e7@tucnak> (raw)
In-Reply-To: <f3f9fd1e-5b77-8c32-fe12-d0adec4d4cce@cs.ucla.edu>

On Tue, Jun 13, 2023 at 07:54:25PM -0700, Paul Eggert wrote:
> I don't see how you could implement __has_include_next(<stdckdint.h>) for
> arbitrary non-GCC compilers, which is what we'd need for glibc users. For
> glibc internals we can use "#include_next" more readily, since we assume a
> new-enough GCC. I.e. we could do something like this:

Indeed, limits.h uses
#if defined __GNUC__ && !defined _GCC_LIMITS_H_
/* `_GCC_LIMITS_H_' is what GCC's file defines.  */
# include_next <limits.h>
#endif

I'd just do:
#if defined (__has_include_next) && !defined (ckd_add)
# if __has_include_next (<stdckdint.h>)
#  include_next <stdckdint.h>
# endif
#endif

and then deal with the fallback (if the C library really needs one,
does it need to support a C23 feature in arbitrary compiler which
doesn't support C23?).
A fallback should start with using __builtin_{add,sub,mul}_overflow
without extra checking if compiler supports it, with or without
use of __has_builtin.  GCC 6 and later has __builtin_{add,sub,mul}_overflow,
only GCC 10 has __has_builtin, I think clang has added those shortly
after they were added in GCC 6 (though, __builtin_{add,sub,mul}_overflow_p
which has been added in GCC 7 wasn't added to clang).

	Jakub


  reply	other threads:[~2023-06-14  6:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-10 10:37 Jakub Jelinek
2023-06-10 11:37 ` Jakub Jelinek
2023-06-11 14:05   ` Martin Uecker
2023-06-12 10:35 ` Eric Gallager
2023-06-12 21:51 ` Joseph Myers
2023-06-13  6:28   ` Jakub Jelinek
2023-06-13 15:10     ` Joseph Myers
2023-06-13 15:20       ` Jakub Jelinek
2023-06-13 15:45         ` Joseph Myers
2023-06-14  2:54     ` Paul Eggert
2023-06-14  6:49       ` Jakub Jelinek [this message]
2023-06-14 11:46       ` Florian Weimer
2023-06-14 14:52       ` Joseph Myers
2023-06-14 15:50         ` Zack Weinberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZIli+miHB7qbe9e7@tucnak \
    --to=jakub@redhat.com \
    --cc=eggert@cs.ucla.edu \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).