[PATCH] D157331: [clang] Implement C23 <stdckdint.h>

Dávid Bolvanský via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 7 16:42:22 PDT 2023


xbolva00 added inline comments.


================
Comment at: clang/lib/Headers/stdckdint.h:13
+
+#if defined(__GNUC__)
+#define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
----------------
enh wrote:
> enh wrote:
> > enh wrote:
> > > ZijunZhao wrote:
> > > > enh wrote:
> > > > > is this ever _not_ set for clang?
> > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/stdbool.h#L23
> > > > I think it is set?
> > > i get an error from
> > > ```
> > > /tmp$ cat x.c
> > > #if defined(__GNUC__)
> > > #error foo
> > > #endif
> > > ```
> > > regardless of whether i compile with -std=c11 or -std=gnu11.
> > > neither -ansi nor -pedantic seem to stop it either.
> > it does look like it _should_ be possible to not have it set though? llvm/llvm-project/clang/lib/Frontend/InitPreprocessor.cpp has:
> > ```
> >   if (LangOpts.GNUCVersion != 0) {
> >     // Major, minor, patch, are given two decimal places each, so 4.2.1 becomes
> >     // 40201.
> >     unsigned GNUCMajor = LangOpts.GNUCVersion / 100 / 100;
> >     unsigned GNUCMinor = LangOpts.GNUCVersion / 100 % 100;
> >     unsigned GNUCPatch = LangOpts.GNUCVersion % 100;
> >     Builder.defineMacro("__GNUC__", Twine(GNUCMajor));
> >     Builder.defineMacro("__GNUC_MINOR__", Twine(GNUCMinor));
> >     Builder.defineMacro("__GNUC_PATCHLEVEL__", Twine(GNUCPatch));
> >     Builder.defineMacro("__GXX_ABI_VERSION", "1002");
> > 
> >     if (LangOpts.CPlusPlus) {
> >       Builder.defineMacro("__GNUG__", Twine(GNUCMajor));
> >       Builder.defineMacro("__GXX_WEAK__");
> >     }
> >   }
> > ```
> /me wonders whether the right test here is actually `#if __has_feature(__builtin_add_overflow)` (etc)...
> 
> but at this point, you definitely need an llvm person :-)
#ifndef __has_builtin         // Optional of course.
  #define __has_builtin(x) 0  // Compatibility with non-clang compilers.
#endif

...
#if __has_builtin(__builtin_trap)
  __builtin_trap();
#else
  abort();
#endif


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157331/new/

https://reviews.llvm.org/D157331



More information about the cfe-commits mailing list