xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Test compilation of tgmath macros. |
| 2 | Copyright (C) 2003-2016 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | Contributed by Andreas Jaeger <aj@suse.de>, 2003. |
| 5 | |
| 6 | The GNU C Library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | The GNU C Library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with the GNU C Library; if not, see |
| 18 | <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #include <math.h> |
| 21 | #include <complex.h> |
| 22 | #include <tgmath.h> |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | static float fx; |
| 26 | static double dx; |
| 27 | static long double lx; |
| 28 | static int errors = 0; |
| 29 | |
| 30 | static void |
| 31 | our_error (const char *c) |
| 32 | { |
| 33 | puts (c); |
| 34 | ++errors; |
| 35 | } |
| 36 | |
| 37 | /* First function where the return type is constant. */ |
| 38 | |
| 39 | #define CHECK_RET_CONST_TYPE(func, rettype, arg, name) \ |
| 40 | if (sizeof (func (arg)) != sizeof (rettype)) \ |
| 41 | our_error ("Return size of " #func " is wrong with " #name " argument"); |
| 42 | |
| 43 | #define CHECK_RET_CONST_FLOAT(func, rettype) \ |
| 44 | CHECK_RET_CONST_TYPE (func, rettype, fx, float) |
| 45 | #define CHECK_RET_CONST_DOUBLE(func, rettype) \ |
| 46 | CHECK_RET_CONST_TYPE (func, rettype, dx, double) |
| 47 | #ifdef NO_LONG_DOUBLE |
| 48 | # define CHECK_RET_CONST_LDOUBLE(func, rettype) |
| 49 | #else |
| 50 | # define CHECK_RET_CONST_LDOUBLE(func, rettype) \ |
| 51 | CHECK_RET_CONST_TYPE (func, rettype, lx, long double) |
| 52 | #endif |
| 53 | |
| 54 | #define CHECK_RET_CONST(func, rettype) \ |
| 55 | static void \ |
| 56 | check_return_ ##func (void) \ |
| 57 | { \ |
| 58 | CHECK_RET_CONST_FLOAT (func, rettype) \ |
| 59 | CHECK_RET_CONST_DOUBLE (func, rettype) \ |
| 60 | CHECK_RET_CONST_LDOUBLE (func, rettype) \ |
| 61 | } |
| 62 | |
| 63 | CHECK_RET_CONST(ilogb, int) |
| 64 | CHECK_RET_CONST(lrint, long) |
| 65 | CHECK_RET_CONST(lround, long) |
| 66 | CHECK_RET_CONST(llrint, long long) |
| 67 | CHECK_RET_CONST(llround, long long) |
| 68 | |
| 69 | static int |
| 70 | do_test (void) |
| 71 | { |
| 72 | check_return_ilogb (); |
| 73 | check_return_lrint (); |
| 74 | check_return_lround (); |
| 75 | check_return_llrint (); |
| 76 | check_return_llround (); |
| 77 | |
| 78 | printf ("%Zd\n", sizeof(carg (lx))); |
| 79 | |
| 80 | return errors != 0; |
| 81 | } |
| 82 | |
| 83 | #define TEST_FUNCTION do_test () |
| 84 | #include "../test-skeleton.c" |