(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
cpp/
has-builtin-2.c
       1  /* PR c/66970 - Add __has_builtin() macro
       2     Verify __has_builtin evaluation for common built-ins and other identifiers.
       3     { dg-do compile } */
       4  
       5  // Verify a few library built-ins.
       6  #if !__has_builtin (__builtin_abs)
       7  #  error "__has_builtin (__builtin_abs) failed"
       8  #endif
       9  
      10  #if !__has_builtin (abs)
      11     // abs is also a built-in unless disabled by -fno-builtin.
      12  #  error "__has_builtin (abs) failed"
      13  #endif
      14  
      15  #if __cplusplus
      16  // Declare an overload and verify that __has_builtin (isalpha) still
      17  // evaluates to true.
      18  int isalpha (const char*);
      19  #endif
      20  
      21  #if !__has_builtin (__builtin_isalpha)
      22  #  error "__has_builtin (__builtin_isalpha) failed"
      23  #endif
      24  
      25  #if !__has_builtin (isalpha)
      26     // isalpha is still a built-in despite the overload above.
      27  #  error "__has_builtin (isalpha) failed"
      28  #endif
      29  
      30  
      31  #if !__has_builtin (__builtin__Exit)
      32  #  error "__has_builtin (__builtin__Exit) failed"
      33  #endif
      34  
      35  
      36  #if !__has_builtin (__builtin_alloca)
      37  #  error "__has_builtin (__builtin_alloca) failed"
      38  #endif
      39  
      40  #if !__has_builtin (__builtin_is_constant_evaluated)
      41     // __builtin_is_constant_evaluated is a C++-only built.
      42  #  ifdef __cplusplus
      43  #    error "__has_builtin (__builtin_is_constant_evaluated) failed"
      44  #  endif
      45  #else
      46  #  ifndef __cplusplus
      47  #    error "__has_builtin (__builtin_is_constant_evaluated) failed"
      48  #  endif
      49  #endif
      50  
      51  #if !__has_builtin (__builtin_expect)
      52  #  error "__has_builtin (__builtin_expect) failed"
      53  #endif
      54  
      55  #if !__has_builtin (__builtin_trap)
      56  #  error "__has_builtin (__builtin_trap) failed"
      57  #endif
      58  
      59  #if !__has_builtin (__builtin_unreachable)
      60  #  error "__has_builtin (__builtin_unreachable) failed"
      61  #endif
      62  
      63  #if !__has_builtin (__builtin_LINE)
      64  #  error "__has_builtin (__builtin_LINE) failed"
      65  #endif
      66  
      67  #if !__has_builtin (__builtin_object_size)
      68  #  error "__has_builtin (__builtin_object_size) failed"
      69  #endif
      70  
      71  #if !__has_builtin (__builtin_inf)
      72  #  error "__has_builtin (__builtin_inf) failed"
      73  #endif
      74  
      75  #if !__has_builtin (__builtin_nan)
      76  #  error "__has_builtin (__builtin_nan) failed"
      77  #endif
      78  
      79  #if !__has_builtin (__builtin_bswap16)
      80  #  error "__has_builtin (__builtin_bswap16) failed"
      81  #endif
      82  
      83  #if !__has_builtin (__builtin_bswap32)
      84  #  error "__has_builtin (__builtin_bswap32) failed"
      85  #endif
      86  
      87  
      88  // Verify a few integer overflow built-ins.
      89  #if !__has_builtin (__builtin_add_overflow)
      90  #  error "__has_builtin (__builtin_add_overflow) failed"
      91  #endif
      92  
      93  #if !__has_builtin (__builtin_sadd_overflow)
      94  #  error "__has_builtin (__builtin_sadd_overflow) failed"
      95  #endif
      96  
      97  #if !__has_builtin (__builtin_add_overflow_p)
      98  #  error "__has_builtin (__builtin_add_overflow_p) failed"
      99  #endif
     100  
     101  
     102  // Verify a few atomic built-ins.
     103  #if !__has_builtin (__atomic_load)
     104  #  error "__has_builtin (__atomic_load) failed"
     105  #endif
     106  
     107  #if !__has_builtin (__atomic_load_n)
     108  #  error "__has_builtin (__atomic_load_n) failed"
     109  #endif
     110  
     111  #if !__has_builtin (__atomic_store)
     112  #  error "__has_builtin (__atomic_store) failed"
     113  #endif
     114  
     115  #if !__has_builtin (__atomic_store_n)
     116  #  error "__has_builtin (__atomic_store_n) failed"
     117  #endif
     118  
     119  #if !__has_builtin (__atomic_exchange)
     120  #  error "__has_builtin (__atomic_echange) failed"
     121  #endif
     122  
     123  #if !__has_builtin (__atomic_exchange_n)
     124  #  error "__has_builtin (__atomic_exchange_n) failed"
     125  #endif
     126  
     127  
     128  // Verify a few sync built-ins.
     129  #if !__has_builtin (__sync_fetch_and_add)
     130  #  error "__has_builtin (__sync_fetch_and_add) failed"
     131  #endif
     132  
     133  #if !__has_builtin (__sync_add_and_fetch)
     134  #  error "__has_builtin (__sync_add_and_fetch) failed"
     135  #endif
     136  
     137  #if !__has_builtin (__sync_bool_compare_and_swap)
     138  #  error "__has_builtin (__sync_bool_compare_and_swap) failed"
     139  #endif
     140  
     141  #if !__has_builtin (__sync_val_compare_and_swap)
     142  #  error "__has_builtin (__sync_val_compare_and_swap) failed"
     143  #endif
     144  
     145  #if !__has_builtin (__sync_synchronize)
     146  #  error "__has_builtin (__sync_synchronize) failed"
     147  #endif
     148  
     149  // Verify nonlocal goto builtins.
     150  #if !__has_builtin (__builtin_setjmp)
     151  #  error "__has_builtin (__builtin_setjmp) failed"
     152  #endif
     153  
     154  #if !__has_builtin (__builtin_longjmp)
     155  #  error "__has_builtin (__builtin_longjmp) failed"
     156  #endif
     157  
     158  
     159  // Verify a few built-ins for constructing function calls.
     160  
     161  #if !__has_builtin (__builtin_apply)
     162  #  error "__has_builtin (__builtin_apply) failed"
     163  #endif
     164  
     165  #if !__has_builtin (__builtin_return)
     166  #  error "__has_builtin (__builtin_return) failed"
     167  #endif
     168  
     169  // Verify built-ins for function return address.
     170  #if !__has_builtin (__builtin_return_address)
     171  #  error "__has_builtin (__builtin_return_address) failed"
     172  #endif
     173  
     174  #if !__has_builtin (__builtin_extract_return_addr)
     175  #  error "__has_builtin (__builtin_extract_return_addr) failed"
     176  #endif
     177  
     178  #if !__has_builtin (__builtin_frob_return_addr)
     179  #  error "__has_builtin (__builtin_frob_return_addr) failed"
     180  #endif
     181  
     182  #if !__has_builtin (__builtin_frame_address)
     183  #  error "__has_builtin (__builtin_frame_address) failed"
     184  #endif
     185  
     186  // Verify keywords that aren't declared built-in functions.
     187  
     188  #if !__has_builtin (__builtin_has_attribute)
     189  #  error "__has_builtin (__builtin_has_attribute) failed"
     190  #endif
     191  
     192  #if !__has_builtin (__builtin_offsetof)
     193  #  error "__has_builtin (__builtin_offsetof) failed"
     194  #endif
     195  
     196  // Verify some C-only built-ins.
     197  
     198  #if !__has_builtin (__builtin_types_compatible_p)
     199  #  if !__cplusplus
     200  #    error "__has_builtin (__builtin_types_compatible_p) failed"
     201  #  endif
     202  #else
     203  #  if __cplusplus
     204  #    error "__has_builtin (__builtin_types_compatible_p) failed"
     205  #  endif
     206  #endif
     207  
     208  // Verify a few C++ traits built-ins.
     209  
     210  #if !__has_builtin (__builtin_addressof)
     211  #  if __cplusplus
     212  #    error "__has_builtin (__builtin_addressof) failed"
     213  #  endif
     214  #else
     215  #  if !__cplusplus
     216  #    error "__has_builtin (__builtin_addressof) failed"
     217  #  endif
     218  #endif
     219  
     220  #if !__has_builtin (__builtin_launder)
     221  #  if __cplusplus
     222  #    error "__has_builtin (__builtin_launder) failed"
     223  #  endif
     224  #else
     225  #  if !__cplusplus
     226  #    error "__has_builtin (__builtin_launder) failed"
     227  #  endif
     228  #endif
     229  
     230  #if !__has_builtin (__has_nothrow_assign)
     231  #  if __cplusplus
     232  #    error "__has_builtin (__has_nothrow_assign) failed"
     233  #  endif
     234  #else
     235  #  if !__cplusplus
     236  #    error "__has_builtin (__has_nothrow_assign) failed"
     237  #  endif
     238  #endif
     239  
     240  #if !__has_builtin (__has_trivial_assign)
     241  #  if __cplusplus
     242  #    error "__has_builtin (__has_trivial_assign) failed"
     243  #  endif
     244  #else
     245  #  if !__cplusplus
     246  #    error "__has_builtin (__has_trivial_assign) failed"
     247  #  endif
     248  #endif
     249  
     250  #if !__has_builtin (__has_virtual_destructor)
     251  #  if __cplusplus
     252  #    error "__has_builtin (__has_virtual_destructor) failed"
     253  #  endif
     254  #else
     255  #  if !__cplusplus
     256  #    error "__has_builtin (__has_virtual_destructor) failed"
     257  #  endif
     258  #endif
     259  
     260  
     261  // Verify an Intel built-in that's not implemented by any other target.
     262  #if !__has_builtin (__builtin_ia32_pause)
     263  #  if defined (__i386__) || defined (__x86_64__)
     264  #    error "__has_builtin (__builtin_ia32_pause) failed"
     265  #  endif
     266  #else
     267  #  if !defined (__i386__) && !defined (__x86_64__)
     268  #    error "__has_builtin (__builtin_ia32_pause) failed"
     269  #  endif
     270  #endif
     271  
     272  
     273  // Verify non-functions.
     274  
     275  #if __has_builtin (__alignof__)
     276  #  error "__has_builtin (__alignof__) failed"
     277  #endif
     278  
     279  #if __has_builtin (asm)
     280  #  error "__has_builtin (asm) failed"
     281  #endif
     282  
     283  #if __has_builtin (__asm__)
     284  #  error "__has_builtin (__asm__) failed"
     285  #endif
     286  
     287  #if __has_builtin (__attribute__)
     288  #  error "__has_builtin (__attribute__) failed"
     289  #endif
     290  
     291  #if __has_builtin (__inline__)
     292  #  error "__has_builtin (__inline__) failed"
     293  #endif
     294  
     295  #if __has_builtin (__typeof__)
     296  #  error "__has_builtin (__typeof__) failed"
     297  #endif