On Fri, Mar 29, 2013 at 4:25 PM, YunZhong Gao <span dir="ltr"><<a href="mailto:gaoyunzhong@gmail.com" target="_blank">gaoyunzhong@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">gaoyunzhong added you to the CC list for the revision "Small fix for tgmath.h".<br>
<br>
Hi,<br>
<br>
This patch attempts to fix the return types of the complex creal functions. They should return non-complex types according to C99 section 7.22c6 and 7.3.9.5. The fix is to remove the extra _Complex keywords from the prototypes of the creal functions in a similar manner as Kristof Beyls did to fabs a few weeks ago.<br>
<br>
</div>I am not sure where I can add a regression test for a header change like this. With the small test case below, GCC 4.4.3 returns 4 at run-time while Clang trunk r176911 returns 8.<br>
<div class="im"><br>
``` /* test.c */<br>
#include <stdio.h><br>
#include <tgmath.h><br>
<br>
float f;<br>
<br>
int main() {<br>
printf("%lu\n", sizeof(creal(f)));<br>
return 0;<br>
}<br>
/* end of file */```<br>
<br>
Could someone review and commit the patch for me?<br>
<br>
Thanks, Gao.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D595" target="_blank">http://llvm-reviews.chandlerc.com/D595</a><br>
<br>
Files:<br>
lib/Headers/tgmath.h<br>
</div> test/Headers/tgmath.c<br>
<div class="im"><br>
Index: lib/Headers/tgmath.h<br>
===================================================================<br>
--- lib/Headers/tgmath.h<br>
+++ lib/Headers/tgmath.h<br>
@@ -1340,15 +1340,15 @@<br>
<br>
// creal<br>
<br>
-static float _Complex<br>
+static float<br>
_TG_ATTRS<br>
__tg_creal(float __x) {return __x;}<br>
<br>
-static double _Complex<br>
+static double<br>
_TG_ATTRS<br>
__tg_creal(double __x) {return __x;}<br>
<br>
-static long double _Complex<br>
+static long double<br>
_TG_ATTRS<br>
__tg_creal(long double __x) {return __x;}<br>
<br>
</div>Index: test/Headers/tgmath.c<br>
===================================================================<br>
--- test/Headers/tgmath.c<br>
+++ test/Headers/tgmath.c<br>
@@ -0,0 +1,67 @@<br>
+// RUN: %clang -S -emit-llvm -o - %s | FileCheck %s<br></blockquote><div><br></div><div>We prefer for tests to go through as few stages of the compiler as possible. Please reformulate this as a -fsyntax-only test:</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+#include <tgmath.h><br>
+<br>
+// CHECK: define i32 @check_float_creal<br>
+// CHECK: ret i32 1<br>
+int check_float_creal(float f)<br>
+{<br>
+ return sizeof(creal(f)) == sizeof(float);<br></blockquote><div><br></div><div>_Static_assert(sizeof(creal(f)) == sizeof(float), "");</div><div><br></div><div>... or ...</div><div><br></div><div>int check[sizeof(creal(f)) == sizeof(float) ? 1 : -1];</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
+// CHECK: define i32 @check_double_creal<br>
+// CHECK: ret i32 1<br>
+int check_double_creal(double d)<br>
+{<br>
+ return sizeof(creal(d)) == sizeof(double);<br>
+}<br>
+<br>
+// CHECK: define i32 @check_ldouble_creal<br>
+// CHECK: ret i32 1<br>
+int check_ldouble_creal(long double l)<br>
+{<br>
+ return sizeof(creal(l)) == sizeof(long double);<br>
+}<br>
+<br>
+// CHECK: define i32 @check_float_fabs<br>
+// CHECK: ret i32 1<br>
+int check_float_fabs(float complex f)<br>
+{<br>
+ return sizeof(fabs(f)) == sizeof(float);<br>
+}<br>
+<br>
+// CHECK: define i32 @check_double_fabs<br>
+// CHECK: ret i32 1<br>
+int check_double_fabs(double complex d)<br>
+{<br>
+ return sizeof(fabs(d)) == sizeof(double);<br>
+}<br>
+<br>
+// CHECK: define i32 @check_ldouble_fabs<br>
+// CHECK: ret i32 1<br>
+int check_ldouble_fabs(long double complex l)<br>
+{<br>
+ return sizeof(fabs(l)) == sizeof(long double);<br>
+}<br>
+<br>
+// CHECK: define i32 @check_float_logb<br>
+// CHECK: ret i32 1<br>
+int check_float_logb(float f)<br>
+{<br>
+ return sizeof(logb(f)) == sizeof(float);<br>
+}<br>
+<br>
+// CHECK: define i32 @check_double_logb<br>
+// CHECK: ret i32 1<br>
+int check_double_logb(double d)<br>
+{<br>
+ return sizeof(logb(d)) == sizeof(double);<br>
+}<br>
+<br>
+// CHECK: define i32 @check_ldouble_logb<br>
+// CHECK: ret i32 1<br>
+int check_ldouble_logb(long double l)<br>
+{<br>
+ return sizeof(logb(l)) == sizeof(long double);<br>
+}<br>
+<br>
</blockquote></div><br>