]> granicus.if.org Git - clang/commitdiff
start converting over to attr(overloadable). Unfortunately, this
authorChris Lattner <sabre@nondot.org>
Tue, 17 Feb 2009 02:14:31 +0000 (02:14 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 17 Feb 2009 02:14:31 +0000 (02:14 +0000)
produces really horrible diagnostics when overload ambiguities
happen:

t.c:10:10: error: call to '__tg_acos' is ambiguous; candidates are:
  return acos(x);
         ^~~~
In file included from t.c:1:
/Users/sabre/llvm/Debug/Headers/tgmath-sofar.h:49:1: note: candidate function
__TG_RC_1(x, acos, cacos)
^
/Users/sabre/llvm/Debug/Headers/tgmath-sofar.h:49:1: note: candidate function
__TG_RC_1(x, acos, cacos)
^
/Users/sabre/llvm/Debug/Headers/tgmath-sofar.h:49:1: note: candidate function
__TG_RC_1(x, acos, cacos)
^
/Users/sabre/llvm/Debug/Headers/tgmath-sofar.h:49:1: note: candidate function
__TG_RC_1(x, acos, cacos)
^
/Users/sabre/llvm/Debug/Headers/tgmath-sofar.h:49:1: note: candidate function
__TG_RC_1(x, acos, cacos)
^
/Users/sabre/llvm/Debug/Headers/tgmath-sofar.h:49:1: note: candidate function
__TG_RC_1(x, acos, cacos)
^

A possible fix is to just not use macros for this, which I'll probably go for,
but it would be nice to emit the type at the call, so we know what we asked for!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64720 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Headers/tgmath-sofar.h

index 07cad5a188ec69adc9521fc66b8b4b9417ad0ea0..0377909c5647130c236866b80ff83519936a594e 100644 (file)
 #ifndef __cplusplus
 #include <complex.h>
 
+#define __TG_UNARY_OVERLOAD(TYPE, SRCFN, DSTFN) \
+  static TYPE __attribute__((overloadable, always_inline)) __tg_ ## SRCFN(TYPE x) { return DSTFN(x); }
+
+
+/* __TG_RC_1 - Unary functions defined on both real and complex values. */
+#define __TG_RC_1(op, REALFN, COMPLEXFN) \
+  __TG_UNARY_OVERLOAD(float, REALFN, REALFN ## f)                     \
+  __TG_UNARY_OVERLOAD(double, REALFN, REALFN)                         \
+  __TG_UNARY_OVERLOAD(long double, REALFN, REALFN ## l)               \
+  __TG_UNARY_OVERLOAD(_Complex float, REALFN, COMPLEXFN ## f)         \
+  __TG_UNARY_OVERLOAD(_Complex double, REALFN, COMPLEXFN)             \
+  __TG_UNARY_OVERLOAD(_Complex long double, REALFN, COMPLEXFN ## l)
+
 /* C99 7.22p4, functions in both math.h and complex.h. */
-#define acos(x) \
-  __builtin_overload(1, x, cacosl, cacos, cacosf, acosl, acos, acosf)
-#define asin(x) \
-  __builtin_overload(1, x, casinl, casin, casinf, asinl, asin, asinf)
+__TG_RC_1(x, acos, cacos)
+#define acos(x) __tg_acos(x)
+__TG_RC_1(x, asin, casin)
+#define asin(x) __tg_asin(x)
+
+
 #define atan(x) \
   __builtin_overload(1, x, catanl, catan, catanf, atanl, atan, atanf)
 #define acosh(x) \