[cfe-commits] r64720 - /cfe/trunk/lib/Headers/tgmath-sofar.h

Chris Lattner sabre at nondot.org
Mon Feb 16 18:14:32 PST 2009


Author: lattner
Date: Mon Feb 16 20:14:31 2009
New Revision: 64720

URL: http://llvm.org/viewvc/llvm-project?rev=64720&view=rev
Log:
start converting over to attr(overloadable).  Unfortunately, this
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!


Modified:
    cfe/trunk/lib/Headers/tgmath-sofar.h

Modified: cfe/trunk/lib/Headers/tgmath-sofar.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/tgmath-sofar.h?rev=64720&r1=64719&r2=64720&view=diff

==============================================================================
--- cfe/trunk/lib/Headers/tgmath-sofar.h (original)
+++ cfe/trunk/lib/Headers/tgmath-sofar.h Mon Feb 16 20:14:31 2009
@@ -32,11 +32,26 @@
 #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) \





More information about the cfe-commits mailing list