[PATCH] D86508: [clang] implement+test remaining C90 __builtin_ functions
Nick Desaulniers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 2 14:42:58 PDT 2020
nickdesaulniers marked 2 inline comments as done.
nickdesaulniers added inline comments.
================
Comment at: clang/include/clang/Basic/Builtins.def:513
BUILTIN(__builtin_printf, "icC*.", "Fp:0:")
+BUILTIN(__builtin_putchar, "ii", "F")
+BUILTIN(__builtin_puts, "icC*", "nF")
----------------
nickdesaulniers wrote:
> nickdesaulniers wrote:
> > nickdesaulniers wrote:
> > > nickdesaulniers wrote:
> > > > rsmith wrote:
> > > > > aaron.ballman wrote:
> > > > > > Should we also add a builtin for `putc()` (I know that's often a macro, so I'm not certain if it applies)?
> > > > > Yes, GCC has a `__builtin_putc`, so it'd make sense for us to support that too.
> > > > Curious, `putc` isn't documented at https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html, which is what I was using. It looks like `putc` was a part of ANSI C, so I'm not sure what else might be missing from my implementation. Let me see if I can find a more complete list of C90 functions to verify.
> > > (retrieves copy of `The Standard C Library` from P. J. Plauger)
> > Looks like I'm missing:
> >
> > From stdlib.h:
> > * `div`
> > * `ldiv`
> > * `bsearch`
> > * `qsort`
> > * `rand`
> > * `srand`
> > * `atof`
> > * `atoi`
> > * `atol`
> > * `mblen`
> > * `mbstowcs`
> > * `mbtowc`
> > * `wcstombs`
> > * `wctomb`
> > * `abort`
> > * `atexit`
> > * `getenv`
> > * `system`
> >
> > From string.h:
> > * `strcoll`
> >
> > From stdio.h:
> > * `remove`
> > * `rename`
> > * `tmpfile`
> > * `fclose`
> > * `fflush`
> > * `freopen`
> > * `setvbuf`
> > * `scanfwrite`
> > * `fgetc`
> > * `fgets`
> > * `fputc`
> > * `getc`
> > * `getchar`
> > * `gets`
> > * `putc`
> > * `ungetc`
> > * `fgetpos`
> > * `fseek`
> > * `fsetpos`
> > * `ftell`
> > * `rewind`
> > * `clearerr`
> > * `feof`
> > * `ferror`
> > * `perror`
> >
> > We look good on ctype.h and stdard.h. Shall I very those against GCC and implement what's missing here?
> (`abort` should not have been in the above list; it's in GCC's docs and we implement the builtin for it)
>
> From the above list, GCC has builtins for:
> * fputc
> * putc
>
> We already support `abort. Let me:
> 1. file a docs bug against GCC for those 2 undocumented builtins.
> 2. add implementations of them to this change.
> 3. add a test case for pr/47387 just to be safe.
1. Filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96907.
2. done
3. as long as clang adds the no-builtin-puts attribute, then pr/47387 is fixed. It may not be interesting to add a test for properly emitting the builtin, since clang/test/CodeGen/libcalls-fno-builtin.c already covers that.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86508/new/
https://reviews.llvm.org/D86508
More information about the cfe-commits
mailing list