[PATCH] D29736: [WebAssembly] Add target specific overrides for lgamma family functions

Jacob Gravelle via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 8 16:01:51 PST 2017


jgravelle-google created this revision.
Herald added a subscriber: jfb.

Current WebAssembly implementations use musl libc, which writes to
signgam in its lgamma functions. We want the rest of the builtins to be
const under -fno-math-errno, so overwrite lgamma's builtin definitions
to be never-const.


https://reviews.llvm.org/D29736

Files:
  include/clang/Basic/BuiltinsWebAssembly.def


Index: include/clang/Basic/BuiltinsWebAssembly.def
===================================================================
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -16,9 +16,21 @@
 
 // The format of this database matches clang/Basic/Builtins.def.
 
+#if defined(BUILTIN) && !defined(LIBBUILTIN)
+#  define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) BUILTIN(ID, TYPE, ATTRS)
+#endif
+
 // Note that current_memory is not "c" (readnone) because it must be sequenced
 // with respect to grow_memory calls.
 BUILTIN(__builtin_wasm_current_memory, "z", "n")
 BUILTIN(__builtin_wasm_grow_memory, "zz", "n")
 
+// Redeclaring lgamma from Builtins.def as non-const to allow for POSIX
+// compatibility. Specifically lgamma writes to a user-visible global, signgam,
+// that is available in POSIX-compliant libcs.
+LIBBUILTIN(lgamma, "dd", "fn", "math.h")
+LIBBUILTIN(lgammaf, "ff", "fn", "math.h")
+LIBBUILTIN(lgammal, "LdLd", "fn", "math.h")
+
 #undef BUILTIN
+#undef LIBBUILTIN


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29736.87726.patch
Type: text/x-patch
Size: 1020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170209/a23467d4/attachment.bin>


More information about the cfe-commits mailing list