[PATCH] Small fix for tgmath.h

Richard Smith richard at metafoo.co.uk
Fri Mar 29 16:31:57 PDT 2013


On Fri, Mar 29, 2013 at 4:25 PM, YunZhong Gao <gaoyunzhong at gmail.com> wrote:

> gaoyunzhong added you to the CC list for the revision "Small fix for
> tgmath.h".
>
> Hi,
>
> 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.
>
> 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.
>
> ``` /* test.c */
> #include <stdio.h>
> #include <tgmath.h>
>
> float f;
>
> int main() {
>   printf("%lu\n", sizeof(creal(f)));
>   return 0;
> }
> /* end of file */```
>
> Could someone review and commit the patch for me?
>
> Thanks, Gao.
>
> http://llvm-reviews.chandlerc.com/D595
>
> Files:
>   lib/Headers/tgmath.h
>   test/Headers/tgmath.c
>
> Index: lib/Headers/tgmath.h
> ===================================================================
> --- lib/Headers/tgmath.h
> +++ lib/Headers/tgmath.h
> @@ -1340,15 +1340,15 @@
>
>  // creal
>
> -static float _Complex
> +static float
>      _TG_ATTRS
>      __tg_creal(float __x) {return __x;}
>
> -static double _Complex
> +static double
>      _TG_ATTRS
>      __tg_creal(double __x) {return __x;}
>
> -static long double _Complex
> +static long double
>      _TG_ATTRS
>      __tg_creal(long double __x) {return __x;}
>
> Index: test/Headers/tgmath.c
> ===================================================================
> --- test/Headers/tgmath.c
> +++ test/Headers/tgmath.c
> @@ -0,0 +1,67 @@
> +// RUN: %clang -S -emit-llvm -o - %s | FileCheck %s
>

We prefer for tests to go through as few stages of the compiler as
possible. Please reformulate this as a -fsyntax-only test:


> +
> +#include <tgmath.h>
> +
> +// CHECK: define i32 @check_float_creal
> +// CHECK: ret i32 1
> +int check_float_creal(float f)
> +{
> +  return sizeof(creal(f)) == sizeof(float);
>

_Static_assert(sizeof(creal(f)) == sizeof(float), "");

... or ...

int check[sizeof(creal(f)) == sizeof(float) ? 1 : -1];


> +}
> +
> +// CHECK: define i32 @check_double_creal
> +// CHECK: ret i32 1
> +int check_double_creal(double d)
> +{
> +  return sizeof(creal(d)) == sizeof(double);
> +}
> +
> +// CHECK: define i32 @check_ldouble_creal
> +// CHECK: ret i32 1
> +int check_ldouble_creal(long double l)
> +{
> +  return sizeof(creal(l)) == sizeof(long double);
> +}
> +
> +// CHECK: define i32 @check_float_fabs
> +// CHECK: ret i32 1
> +int check_float_fabs(float complex f)
> +{
> +  return sizeof(fabs(f)) == sizeof(float);
> +}
> +
> +// CHECK: define i32 @check_double_fabs
> +// CHECK: ret i32 1
> +int check_double_fabs(double complex d)
> +{
> +  return sizeof(fabs(d)) == sizeof(double);
> +}
> +
> +// CHECK: define i32 @check_ldouble_fabs
> +// CHECK: ret i32 1
> +int check_ldouble_fabs(long double complex l)
> +{
> +  return sizeof(fabs(l)) == sizeof(long double);
> +}
> +
> +// CHECK: define i32 @check_float_logb
> +// CHECK: ret i32 1
> +int check_float_logb(float f)
> +{
> +  return sizeof(logb(f)) == sizeof(float);
> +}
> +
> +// CHECK: define i32 @check_double_logb
> +// CHECK: ret i32 1
> +int check_double_logb(double d)
> +{
> +  return sizeof(logb(d)) == sizeof(double);
> +}
> +
> +// CHECK: define i32 @check_ldouble_logb
> +// CHECK: ret i32 1
> +int check_ldouble_logb(long double l)
> +{
> +  return sizeof(logb(l)) == sizeof(long double);
> +}
> +
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130329/04467585/attachment.html>


More information about the cfe-commits mailing list