510 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3// Math stuff4 5double g0 = __builtin_huge_val();6float g1 = __builtin_huge_valf();7long double g2 = __builtin_huge_vall();8#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)9__float128 g2_2 = __builtin_huge_valf128();10#endif11 12double g3 = __builtin_inf();13float g4 = __builtin_inff();14long double g5 = __builtin_infl();15#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)16__float128 g5_2 = __builtin_inff128();17#endif18 19double g6 = __builtin_nan("");20float g7 = __builtin_nanf("");21long double g8 = __builtin_nanl("");22#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)23__float128 g8_2 = __builtin_nanf128("");24#endif25 26// GCC constant folds these too (via native strtol):27//double g6_1 = __builtin_nan("1");28//float g7_1 = __builtin_nanf("1");29//long double g8_1 = __builtin_nanl("1");30 31double g9 = __builtin_nans("");32float g10 = __builtin_nansf("");33long double g11 = __builtin_nansl("");34#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)35__float128 g11_2 = __builtin_nansf128("");36#endif37 38int g12 = __builtin_abs(-12);39 40double g13 = __builtin_fabs(-12.);41double g13_0 = __builtin_fabs(-0.);42double g13_1 = __builtin_fabs(-__builtin_inf());43float g14 = __builtin_fabsf(-12.f);44// GCC doesn't eat this one.45//long double g15 = __builtin_fabsfl(-12.0L);46#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)47__float128 g15_2 = __builtin_fabsf128(-12.q);48#endif49 50float g16 = __builtin_copysign(1.0, -1.0);51double g17 = __builtin_copysignf(1.0f, -1.0f);52long double g18 = __builtin_copysignl(1.0L, -1.0L);53#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)54__float128 g18_2 = __builtin_copysignf128(1.0q, -1.0q);55#endif56 57char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nan(""))];58char classify_snan [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nans(""))];59char classify_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())];60char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())];61char classify_normal [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)];62char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)];63char classify_denorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)];64char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1, -1, -1e-308)];65char classify_zero [__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)];66char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)];67 68char isinf_sign_noninf1[__builtin_isinf_sign(-0.0) == 0 ? 1 : -1];69char isinf_sign_noninf2[__builtin_isinf_sign(1e307) == 0 ? 1 : -1];70char isinf_sign_noninf3[__builtin_isinf_sign(__builtin_nan("")) == 0 ? 1 : -1];71char isinf_sign_noninf4[__builtin_isinf_sign(-436.) == 0 ? 1 : -1];72char isinf_sign_inf [__builtin_isinf_sign(__builtin_inf()) == 1 ? 1 : -1];73char isinf_sign_neg_inf[__builtin_isinf_sign(-__builtin_inf()) == -1 ? 1 : -1];74 75char isinf_inf_pos[__builtin_isinf(__builtin_inf()) ? 1 : -1];76char isinf_pos [!__builtin_isinf(1.0) ? 1 : -1];77char isinf_normf [!__builtin_isinf(1e-37f) ? 1 : -1];78char isinf_denormf[!__builtin_isinf(1e-38f) ? 1 : -1];79char isinf_norm [!__builtin_isinf(1e-307) ? 1 : -1];80char isinf_denorm [!__builtin_isinf(1e-308) ? 1 : -1];81char isinf_zero [!__builtin_isinf(0.0) ? 1 : -1];82char isinf_negzero[!__builtin_isinf(-0.0) ? 1 : -1];83char isinf_neg [!__builtin_isinf(-1.0) ? 1 : -1];84char isinf_inf_neg[__builtin_isinf(-__builtin_inf()) ? 1 : -1];85char isinf_nan [!__builtin_isinf(__builtin_nan("")) ? 1 : -1];86char isinf_snan [!__builtin_isinf(__builtin_nans("")) ? 1 : -1];87 88char isfinite_inf_pos[!__builtin_isfinite(__builtin_inf()) ? 1 : -1];89char isfinite_pos [__builtin_isfinite(1.0) ? 1 : -1];90char isfinite_normf [__builtin_isfinite(1e-37f) ? 1 : -1];91char isfinite_denormf[__builtin_isfinite(1e-38f) ? 1 : -1];92char isfinite_norm [__builtin_isfinite(1e-307) ? 1 : -1];93char isfinite_denorm [__builtin_isfinite(1e-308) ? 1 : -1];94char isfinite_zero [__builtin_isfinite(0.0) ? 1 : -1];95char isfinite_negzero[__builtin_isfinite(-0.0) ? 1 : -1];96char isfinite_neg [__builtin_isfinite(-1.0) ? 1 : -1];97char isfinite_inf_neg[!__builtin_isfinite(-__builtin_inf()) ? 1 : -1];98char isfinite_nan [!__builtin_isfinite(__builtin_nan("")) ? 1 : -1];99char isfinite_snan [!__builtin_isfinite(__builtin_nans("")) ? 1 : -1];100 101char isnan_inf_pos[!__builtin_isnan(__builtin_inf()) ? 1 : -1];102char isnan_pos [!__builtin_isnan(1.0) ? 1 : -1];103char isnan_normf [!__builtin_isnan(1e-37f) ? 1 : -1];104char isnan_denormf[!__builtin_isnan(1e-38f) ? 1 : -1];105char isnan_norm [!__builtin_isnan(1e-307) ? 1 : -1];106char isnan_denorm [!__builtin_isnan(1e-308) ? 1 : -1];107char isnan_zero [!__builtin_isnan(0.0) ? 1 : -1];108char isnan_negzero[!__builtin_isnan(-0.0) ? 1 : -1];109char isnan_neg [!__builtin_isnan(-1.0) ? 1 : -1];110char isnan_inf_neg[!__builtin_isnan(-__builtin_inf()) ? 1 : -1];111char isnan_nan [__builtin_isnan(__builtin_nan("")) ? 1 : -1];112char isnan_snan [__builtin_isnan(__builtin_nans("")) ? 1 : -1];113 114char isnormal_inf_pos[!__builtin_isnormal(__builtin_inf()) ? 1 : -1];115char isnormal_pos [__builtin_isnormal(1.0) ? 1 : -1];116char isnormal_normf [__builtin_isnormal(1e-37f) ? 1 : -1];117char isnormal_denormf[!__builtin_isnormal(1e-38f) ? 1 : -1];118char isnormal_norm [__builtin_isnormal(1e-307) ? 1 : -1];119char isnormal_denorm [!__builtin_isnormal(1e-308) ? 1 : -1];120char isnormal_zero [!__builtin_isnormal(0.0) ? 1 : -1];121char isnormal_negzero[!__builtin_isnormal(-0.0) ? 1 : -1];122char isnormal_neg [__builtin_isnormal(-1.0) ? 1 : -1];123char isnormal_inf_neg[!__builtin_isnormal(-__builtin_inf()) ? 1 : -1];124char isnormal_nan [!__builtin_isnormal(__builtin_nan("")) ? 1 : -1];125char isnormal_snan [!__builtin_isnormal(__builtin_nans("")) ? 1 : -1];126 127char iszero_inf_pos[!__builtin_iszero(__builtin_inf()) ? 1 : -1];128char iszero_pos [!__builtin_iszero(1.0) ? 1 : -1];129char iszero_normf [!__builtin_iszero(1e-37f) ? 1 : -1];130char iszero_denormf[!__builtin_iszero(1e-38f) ? 1 : -1];131char iszero_norm [!__builtin_iszero(1e-307) ? 1 : -1];132char iszero_denorm [!__builtin_iszero(1e-308) ? 1 : -1];133char iszero_zero [__builtin_iszero(0.0) ? 1 : -1];134char iszero_negzero[__builtin_iszero(-0.0) ? 1 : -1];135char iszero_neg [!__builtin_iszero(-1.0) ? 1 : -1];136char iszero_inf_neg[!__builtin_iszero(-__builtin_inf()) ? 1 : -1];137char iszero_nan [!__builtin_iszero(__builtin_nan("")) ? 1 : -1];138char iszero_snan [!__builtin_iszero(__builtin_nans("")) ? 1 : -1];139 140char issubnormal_inf_pos[!__builtin_issubnormal(__builtin_inf()) ? 1 : -1];141char issubnormal_pos [!__builtin_issubnormal(1.0) ? 1 : -1];142char issubnormal_normf [!__builtin_issubnormal(1e-37f) ? 1 : -1];143char issubnormal_denormf[__builtin_issubnormal(1e-38f) ? 1 : -1];144char issubnormal_norm [!__builtin_issubnormal(1e-307) ? 1 : -1];145char issubnormal_denorm [__builtin_issubnormal(1e-308) ? 1 : -1];146char issubnormal_zero [!__builtin_issubnormal(0.0) ? 1 : -1];147char issubnormal_negzero[!__builtin_issubnormal(-0.0) ? 1 : -1];148char issubnormal_neg [!__builtin_issubnormal(-1.0) ? 1 : -1];149char issubnormal_inf_neg[!__builtin_issubnormal(-__builtin_inf()) ? 1 : -1];150char issubnormal_nan [!__builtin_issubnormal(__builtin_nan("")) ? 1 : -1];151char issubnormal_snan [!__builtin_issubnormal(__builtin_nans("")) ? 1 : -1];152 153char issignaling_inf_pos[!__builtin_issignaling(__builtin_inf()) ? 1 : -1];154char issignaling_pos [!__builtin_issignaling(1.0) ? 1 : -1];155char issignaling_normf [!__builtin_issignaling(1e-37f) ? 1 : -1];156char issignaling_denormf[!__builtin_issignaling(1e-38f) ? 1 : -1];157char issignaling_norm [!__builtin_issignaling(1e-307) ? 1 : -1];158char issignaling_denorm [!__builtin_issignaling(1e-308) ? 1 : -1];159char issignaling_zero [!__builtin_issignaling(0.0) ? 1 : -1];160char issignaling_negzero[!__builtin_issignaling(-0.0) ? 1 : -1];161char issignaling_neg [!__builtin_issignaling(-1.0) ? 1 : -1];162char issignaling_inf_neg[!__builtin_issignaling(-__builtin_inf()) ? 1 : -1];163char issignaling_nan [!__builtin_issignaling(__builtin_nan("")) ? 1 : -1];164char issignaling_snan [__builtin_issignaling(__builtin_nans("")) ? 1 : -1];165 166char isfpclass_inf_pos_0[__builtin_isfpclass(__builtin_inf(), 0x0200) ? 1 : -1]; // fcPosInf167char isfpclass_inf_pos_1[!__builtin_isfpclass(__builtin_inff(), 0x0004) ? 1 : -1]; // fcNegInf168char isfpclass_inf_pos_2[__builtin_isfpclass(__builtin_infl(), 0x0207) ? 1 : -1]; // fcSNan|fcQNan|fcNegInf|fcPosInf169char isfpclass_inf_pos_3[!__builtin_isfpclass(__builtin_inf(), 0x01F8) ? 1 : -1]; // fcFinite170char isfpclass_pos_0 [__builtin_isfpclass(1.0, 0x0100) ? 1 : -1]; // fcPosNormal171char isfpclass_pos_1 [!__builtin_isfpclass(1.0f, 0x0008) ? 1 : -1]; // fcNegNormal172char isfpclass_pos_2 [__builtin_isfpclass(1.0L, 0x01F8) ? 1 : -1]; // fcFinite173char isfpclass_pos_3 [!__builtin_isfpclass(1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan174char isfpclass_pdenorm_0[__builtin_isfpclass(1.0e-40f, 0x0080) ? 1 : -1]; // fcPosSubnormal175char isfpclass_pdenorm_1[__builtin_isfpclass(1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite176char isfpclass_pdenorm_2[!__builtin_isfpclass(1.0e-40f, 0x003C) ? 1 : -1]; // fcNegative177char isfpclass_pdenorm_3[!__builtin_isfpclass(1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite178char isfpclass_pzero_0 [__builtin_isfpclass(0.0f, 0x0060) ? 1 : -1]; // fcZero179char isfpclass_pzero_1 [__builtin_isfpclass(0.0, 0x01F8) ? 1 : -1]; // fcFinite180char isfpclass_pzero_2 [!__builtin_isfpclass(0.0L, 0x0020) ? 1 : -1]; // fcNegZero181char isfpclass_pzero_3 [!__builtin_isfpclass(0.0, 0x0003) ? 1 : -1]; // fcNan182char isfpclass_nzero_0 [__builtin_isfpclass(-0.0f, 0x0060) ? 1 : -1]; // fcZero183char isfpclass_nzero_1 [__builtin_isfpclass(-0.0, 0x01F8) ? 1 : -1]; // fcFinite184char isfpclass_nzero_2 [!__builtin_isfpclass(-0.0L, 0x0040) ? 1 : -1]; // fcPosZero185char isfpclass_nzero_3 [!__builtin_isfpclass(-0.0, 0x0003) ? 1 : -1]; // fcNan186char isfpclass_ndenorm_0[__builtin_isfpclass(-1.0e-40f, 0x0010) ? 1 : -1]; // fcNegSubnormal187char isfpclass_ndenorm_1[__builtin_isfpclass(-1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite188char isfpclass_ndenorm_2[!__builtin_isfpclass(-1.0e-40f, 0x03C0) ? 1 : -1]; // fcPositive189char isfpclass_ndenorm_3[!__builtin_isfpclass(-1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite190char isfpclass_neg_0 [__builtin_isfpclass(-1.0, 0x0008) ? 1 : -1]; // fcNegNormal191char isfpclass_neg_1 [!__builtin_isfpclass(-1.0f, 0x00100) ? 1 : -1]; // fcPosNormal192char isfpclass_neg_2 [__builtin_isfpclass(-1.0L, 0x01F8) ? 1 : -1]; // fcFinite193char isfpclass_neg_3 [!__builtin_isfpclass(-1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan194char isfpclass_inf_neg_0[__builtin_isfpclass(-__builtin_inf(), 0x0004) ? 1 : -1]; // fcNegInf195char isfpclass_inf_neg_1[!__builtin_isfpclass(-__builtin_inff(), 0x0200) ? 1 : -1]; // fcPosInf196char isfpclass_inf_neg_2[__builtin_isfpclass(-__builtin_infl(), 0x0207) ? 1 : -1]; // ~fcFinite197char isfpclass_inf_neg_3[!__builtin_isfpclass(-__builtin_inf(), 0x03C0) ? 1 : -1]; // fcPositive198char isfpclass_qnan_0 [__builtin_isfpclass(__builtin_nan(""), 0x0002) ? 1 : -1]; // fcQNan199char isfpclass_qnan_1 [!__builtin_isfpclass(__builtin_nanf(""), 0x0001) ? 1 : -1]; // fcSNan200char isfpclass_qnan_2 [__builtin_isfpclass(__builtin_nanl(""), 0x0207) ? 1 : -1]; // ~fcFinite201char isfpclass_qnan_3 [!__builtin_isfpclass(__builtin_nan(""), 0x01F8) ? 1 : -1]; // fcFinite202char isfpclass_snan_0 [__builtin_isfpclass(__builtin_nansf(""), 0x0001) ? 1 : -1]; // fcSNan203char isfpclass_snan_1 [!__builtin_isfpclass(__builtin_nans(""), 0x0002) ? 1 : -1]; // fcQNan204char isfpclass_snan_2 [__builtin_isfpclass(__builtin_nansl(""), 0x0207) ? 1 : -1]; // ~fcFinite205char isfpclass_snan_3 [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 1 : -1]; // fcFinite206 207__extension__ _Static_assert(208 !__builtin_signbit(1.0) && __builtin_signbit(-1.0) && !__builtin_signbit(0.0) && __builtin_signbit(-0.0) &&209 !__builtin_signbitf(1.0f) && __builtin_signbitf(-1.0f) && !__builtin_signbitf(0.0f) && __builtin_signbitf(-0.0f) &&210 !__builtin_signbitl(1.0L) && __builtin_signbitf(-1.0L) && !__builtin_signbitf(0.0L) && __builtin_signbitf(-0.0L) &&211 !__builtin_signbit(1.0f) && __builtin_signbit(-1.0f) && !__builtin_signbit(0.0f) && __builtin_signbit(-0.0f) &&212 !__builtin_signbit(1.0L) && __builtin_signbit(-1.0L) && !__builtin_signbit(0.0L) && __builtin_signbit(-0.0L) &&213#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)214 !__builtin_signbit(1.0q) && __builtin_signbit(-1.0q) && !__builtin_signbit(0.0q) && __builtin_signbit(-0.0q) &&215#endif216 1, ""217);218 219#define LESS(X, Y) \220 !__builtin_isgreater(X, Y) && __builtin_isgreater(Y, X) && \221 !__builtin_isgreaterequal(X, Y) && __builtin_isgreaterequal(Y, X) && \222 __builtin_isless(X, Y) && !__builtin_isless(Y, X) && \223 __builtin_islessequal(X, Y) && !__builtin_islessequal(Y, X) && \224 __builtin_islessgreater(X, Y) && __builtin_islessgreater(Y, X) && \225 !__builtin_isunordered(X, Y) && !__builtin_isunordered(Y, X)226#define EQUAL(X, Y) \227 !__builtin_isgreater(X, Y) && !__builtin_isgreater(Y, X) && \228 __builtin_isgreaterequal(X, Y) && __builtin_isgreaterequal(Y, X) && \229 !__builtin_isless(X, Y) && !__builtin_isless(Y, X) && \230 __builtin_islessequal(X, Y) && __builtin_islessequal(Y, X) && \231 !__builtin_islessgreater(X, Y) && !__builtin_islessgreater(Y, X) && \232 !__builtin_isunordered(X, Y) && !__builtin_isunordered(Y, X)233#define UNORDERED(X, Y) \234 !__builtin_isgreater(X, Y) && !__builtin_isgreater(Y, X) && \235 !__builtin_isgreaterequal(X, Y) && !__builtin_isgreaterequal(Y, X) && \236 !__builtin_isless(X, Y) && !__builtin_isless(Y, X) && \237 !__builtin_islessequal(X, Y) && !__builtin_islessequal(Y, X) && \238 !__builtin_islessgreater(X, Y) && !__builtin_islessgreater(Y, X) && \239 __builtin_isunordered(X, Y) && __builtin_isunordered(Y, X)240 241__extension__ _Static_assert(242 LESS(0.0, 1.0) && EQUAL(1.0, 1.0) && EQUAL(0.0, -0.0) &&243 UNORDERED(__builtin_nan(""), 1.0) && UNORDERED(__builtin_nan(""), __builtin_inf()) && LESS(0.0, __builtin_inf()) &&244 LESS(0.0f, 1.0f) && EQUAL(1.0f, 1.0f) && EQUAL(0.0f, -0.0f) &&245 UNORDERED(__builtin_nanf(""), 1.0f) && UNORDERED(__builtin_nanf(""), __builtin_inff()) && LESS(0.0f, __builtin_inff()) &&246 LESS(0.0L, 1.0L) && EQUAL(1.0L, 1.0L) && EQUAL(0.0L, -0.0L) &&247 UNORDERED(__builtin_nanl(""), 1.0L) && UNORDERED(__builtin_nanl(""), __builtin_infl()) && LESS(0.0L, __builtin_infl()) &&248#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)249 LESS(0.0q, 1.0q) && EQUAL(1.0q, 1.0q) && EQUAL(0.0q, -0.0q) &&250#endif251 1, ""252);253 254//double g19 = __builtin_powi(2.0, 4);255//float g20 = __builtin_powif(2.0f, 4);256//long double g21 = __builtin_powil(2.0L, 4);257 258#define BITSIZE(x) (sizeof(x) * 8)259char clz1[__builtin_clz(1) == BITSIZE(int) - 1 ? 1 : -1];260char clz2[__builtin_clz(7) == BITSIZE(int) - 3 ? 1 : -1];261char clz3[__builtin_clz(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];262int clz4 = __builtin_clz(0); // expected-error {{not a compile-time constant}}263char clz5[__builtin_clzl(0xFL) == BITSIZE(long) - 4 ? 1 : -1];264char clz6[__builtin_clzll(0xFFLL) == BITSIZE(long long) - 8 ? 1 : -1];265char clz7[__builtin_clzs(0x1) == BITSIZE(short) - 1 ? 1 : -1];266char clz8[__builtin_clzs(0xf) == BITSIZE(short) - 4 ? 1 : -1];267char clz9[__builtin_clzs(0xfff) == BITSIZE(short) - 12 ? 1 : -1];268int clz10 = __builtin_clzg((unsigned char)0); // expected-error {{not a compile-time constant}}269char clz11[__builtin_clzg((unsigned char)0, 42) == 42 ? 1 : -1];270char clz12[__builtin_clzg((unsigned char)0x1) == BITSIZE(char) - 1 ? 1 : -1];271char clz13[__builtin_clzg((unsigned char)0x1, 42) == BITSIZE(char) - 1 ? 1 : -1];272char clz14[__builtin_clzg((unsigned char)0xf) == BITSIZE(char) - 4 ? 1 : -1];273char clz15[__builtin_clzg((unsigned char)0xf, 42) == BITSIZE(char) - 4 ? 1 : -1];274char clz16[__builtin_clzg((unsigned char)(1 << (BITSIZE(char) - 1))) == 0 ? 1 : -1];275char clz17[__builtin_clzg((unsigned char)(1 << (BITSIZE(char) - 1)), 42) == 0 ? 1 : -1];276int clz18 = __builtin_clzg((unsigned short)0); // expected-error {{not a compile-time constant}}277char clz19[__builtin_clzg((unsigned short)0, 42) == 42 ? 1 : -1];278char clz20[__builtin_clzg((unsigned short)0x1) == BITSIZE(short) - 1 ? 1 : -1];279char clz21[__builtin_clzg((unsigned short)0x1, 42) == BITSIZE(short) - 1 ? 1 : -1];280char clz22[__builtin_clzg((unsigned short)0xf) == BITSIZE(short) - 4 ? 1 : -1];281char clz23[__builtin_clzg((unsigned short)0xf, 42) == BITSIZE(short) - 4 ? 1 : -1];282char clz24[__builtin_clzg((unsigned short)(1 << (BITSIZE(short) - 1))) == 0 ? 1 : -1];283char clz25[__builtin_clzg((unsigned short)(1 << (BITSIZE(short) - 1)), 42) == 0 ? 1 : -1];284int clz26 = __builtin_clzg(0U); // expected-error {{not a compile-time constant}}285char clz27[__builtin_clzg(0U, 42) == 42 ? 1 : -1];286char clz28[__builtin_clzg(0x1U) == BITSIZE(int) - 1 ? 1 : -1];287char clz29[__builtin_clzg(0x1U, 42) == BITSIZE(int) - 1 ? 1 : -1];288char clz30[__builtin_clzg(0xfU) == BITSIZE(int) - 4 ? 1 : -1];289char clz31[__builtin_clzg(0xfU, 42) == BITSIZE(int) - 4 ? 1 : -1];290char clz32[__builtin_clzg(1U << (BITSIZE(int) - 1)) == 0 ? 1 : -1];291char clz33[__builtin_clzg(1U << (BITSIZE(int) - 1), 42) == 0 ? 1 : -1];292int clz34 = __builtin_clzg(0UL); // expected-error {{not a compile-time constant}}293char clz35[__builtin_clzg(0UL, 42) == 42 ? 1 : -1];294char clz36[__builtin_clzg(0x1UL) == BITSIZE(long) - 1 ? 1 : -1];295char clz37[__builtin_clzg(0x1UL, 42) == BITSIZE(long) - 1 ? 1 : -1];296char clz38[__builtin_clzg(0xfUL) == BITSIZE(long) - 4 ? 1 : -1];297char clz39[__builtin_clzg(0xfUL, 42) == BITSIZE(long) - 4 ? 1 : -1];298char clz40[__builtin_clzg(1UL << (BITSIZE(long) - 1)) == 0 ? 1 : -1];299char clz41[__builtin_clzg(1UL << (BITSIZE(long) - 1), 42) == 0 ? 1 : -1];300int clz42 = __builtin_clzg(0ULL); // expected-error {{not a compile-time constant}}301char clz43[__builtin_clzg(0ULL, 42) == 42 ? 1 : -1];302char clz44[__builtin_clzg(0x1ULL) == BITSIZE(long long) - 1 ? 1 : -1];303char clz45[__builtin_clzg(0x1ULL, 42) == BITSIZE(long long) - 1 ? 1 : -1];304char clz46[__builtin_clzg(0xfULL) == BITSIZE(long long) - 4 ? 1 : -1];305char clz47[__builtin_clzg(0xfULL, 42) == BITSIZE(long long) - 4 ? 1 : -1];306char clz48[__builtin_clzg(1ULL << (BITSIZE(long long) - 1)) == 0 ? 1 : -1];307char clz49[__builtin_clzg(1ULL << (BITSIZE(long long) - 1), 42) == 0 ? 1 : -1];308#ifdef __SIZEOF_INT128__309int clz50 = __builtin_clzg((unsigned __int128)0); // expected-error {{not a compile-time constant}}310char clz51[__builtin_clzg((unsigned __int128)0, 42) == 42 ? 1 : -1];311char clz52[__builtin_clzg((unsigned __int128)0x1) == BITSIZE(__int128) - 1 ? 1 : -1];312char clz53[__builtin_clzg((unsigned __int128)0x1, 42) == BITSIZE(__int128) - 1 ? 1 : -1];313char clz54[__builtin_clzg((unsigned __int128)0xf) == BITSIZE(__int128) - 4 ? 1 : -1];314char clz55[__builtin_clzg((unsigned __int128)0xf, 42) == BITSIZE(__int128) - 4 ? 1 : -1];315char clz56[__builtin_clzg((unsigned __int128)(1 << (BITSIZE(__int128) - 1))) == 0 ? 1 : -1]; // expected-error {{variable length array declaration not allowed at file scope}}316char clz57[__builtin_clzg((unsigned __int128)(1 << (BITSIZE(__int128) - 1)), 42) == 0 ? 1 : -1]; // expected-error {{variable length array declaration not allowed at file scope}}317#endif318int clz58 = __builtin_clzg((unsigned _BitInt(128))0); // expected-error {{not a compile-time constant}}319char clz59[__builtin_clzg((unsigned _BitInt(128))0, 42) == 42 ? 1 : -1];320char clz60[__builtin_clzg((unsigned _BitInt(128))0x1) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1];321char clz61[__builtin_clzg((unsigned _BitInt(128))0x1, 42) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1];322char clz62[__builtin_clzg((unsigned _BitInt(128))0xf) == BITSIZE(_BitInt(128)) - 4 ? 1 : -1];323char clz63[__builtin_clzg((unsigned _BitInt(128))0xf, 42) == BITSIZE(_BitInt(128)) - 4 ? 1 : -1];324char clz64[__builtin_clzg((unsigned _BitInt(128))(1 << (BITSIZE(_BitInt(128)) - 1))) == 0 ? 1 : -1]; // expected-error {{variable length array declaration not allowed at file scope}}325char clz65[__builtin_clzg((unsigned _BitInt(128))(1 << (BITSIZE(_BitInt(128)) - 1)), 42) == 0 ? 1 : -1]; // expected-error {{variable length array declaration not allowed at file scope}}326 327char ctz1[__builtin_ctz(1) == 0 ? 1 : -1];328char ctz2[__builtin_ctz(8) == 3 ? 1 : -1];329char ctz3[__builtin_ctz(1 << (BITSIZE(int) - 1)) == BITSIZE(int) - 1 ? 1 : -1];330int ctz4 = __builtin_ctz(0); // expected-error {{not a compile-time constant}}331char ctz5[__builtin_ctzl(0x10L) == 4 ? 1 : -1];332char ctz6[__builtin_ctzll(0x100LL) == 8 ? 1 : -1];333char ctz7[__builtin_ctzs(1 << (BITSIZE(short) - 1)) == BITSIZE(short) - 1 ? 1 : -1];334int ctz8 = __builtin_ctzg((unsigned char)0); // expected-error {{not a compile-time constant}}335char ctz9[__builtin_ctzg((unsigned char)0, 42) == 42 ? 1 : -1];336char ctz10[__builtin_ctzg((unsigned char)0x1) == 0 ? 1 : -1];337char ctz11[__builtin_ctzg((unsigned char)0x1, 42) == 0 ? 1 : -1];338char ctz12[__builtin_ctzg((unsigned char)0x10) == 4 ? 1 : -1];339char ctz13[__builtin_ctzg((unsigned char)0x10, 42) == 4 ? 1 : -1];340char ctz14[__builtin_ctzg((unsigned char)(1 << (BITSIZE(char) - 1))) == BITSIZE(char) - 1 ? 1 : -1];341char ctz15[__builtin_ctzg((unsigned char)(1 << (BITSIZE(char) - 1)), 42) == BITSIZE(char) - 1 ? 1 : -1];342int ctz16 = __builtin_ctzg((unsigned short)0); // expected-error {{not a compile-time constant}}343char ctz17[__builtin_ctzg((unsigned short)0, 42) == 42 ? 1 : -1];344char ctz18[__builtin_ctzg((unsigned short)0x1) == 0 ? 1 : -1];345char ctz19[__builtin_ctzg((unsigned short)0x1, 42) == 0 ? 1 : -1];346char ctz20[__builtin_ctzg((unsigned short)0x10) == 4 ? 1 : -1];347char ctz21[__builtin_ctzg((unsigned short)0x10, 42) == 4 ? 1 : -1];348char ctz22[__builtin_ctzg((unsigned short)(1 << (BITSIZE(short) - 1))) == BITSIZE(short) - 1 ? 1 : -1];349char ctz23[__builtin_ctzg((unsigned short)(1 << (BITSIZE(short) - 1)), 42) == BITSIZE(short) - 1 ? 1 : -1];350int ctz24 = __builtin_ctzg(0U); // expected-error {{not a compile-time constant}}351char ctz25[__builtin_ctzg(0U, 42) == 42 ? 1 : -1];352char ctz26[__builtin_ctzg(0x1U) == 0 ? 1 : -1];353char ctz27[__builtin_ctzg(0x1U, 42) == 0 ? 1 : -1];354char ctz28[__builtin_ctzg(0x10U) == 4 ? 1 : -1];355char ctz29[__builtin_ctzg(0x10U, 42) == 4 ? 1 : -1];356char ctz30[__builtin_ctzg(1U << (BITSIZE(int) - 1)) == BITSIZE(int) - 1 ? 1 : -1];357char ctz31[__builtin_ctzg(1U << (BITSIZE(int) - 1), 42) == BITSIZE(int) - 1 ? 1 : -1];358int ctz32 = __builtin_ctzg(0UL); // expected-error {{not a compile-time constant}}359char ctz33[__builtin_ctzg(0UL, 42) == 42 ? 1 : -1];360char ctz34[__builtin_ctzg(0x1UL) == 0 ? 1 : -1];361char ctz35[__builtin_ctzg(0x1UL, 42) == 0 ? 1 : -1];362char ctz36[__builtin_ctzg(0x10UL) == 4 ? 1 : -1];363char ctz37[__builtin_ctzg(0x10UL, 42) == 4 ? 1 : -1];364char ctz38[__builtin_ctzg(1UL << (BITSIZE(long) - 1)) == BITSIZE(long) - 1 ? 1 : -1];365char ctz39[__builtin_ctzg(1UL << (BITSIZE(long) - 1), 42) == BITSIZE(long) - 1 ? 1 : -1];366int ctz40 = __builtin_ctzg(0ULL); // expected-error {{not a compile-time constant}}367char ctz41[__builtin_ctzg(0ULL, 42) == 42 ? 1 : -1];368char ctz42[__builtin_ctzg(0x1ULL) == 0 ? 1 : -1];369char ctz43[__builtin_ctzg(0x1ULL, 42) == 0 ? 1 : -1];370char ctz44[__builtin_ctzg(0x10ULL) == 4 ? 1 : -1];371char ctz45[__builtin_ctzg(0x10ULL, 42) == 4 ? 1 : -1];372char ctz46[__builtin_ctzg(1ULL << (BITSIZE(long long) - 1)) == BITSIZE(long long) - 1 ? 1 : -1];373char ctz47[__builtin_ctzg(1ULL << (BITSIZE(long long) - 1), 42) == BITSIZE(long long) - 1 ? 1 : -1];374#ifdef __SIZEOF_INT128__375int ctz48 = __builtin_ctzg((unsigned __int128)0); // expected-error {{not a compile-time constant}}376char ctz49[__builtin_ctzg((unsigned __int128)0, 42) == 42 ? 1 : -1];377char ctz50[__builtin_ctzg((unsigned __int128)0x1) == 0 ? 1 : -1];378char ctz51[__builtin_ctzg((unsigned __int128)0x1, 42) == 0 ? 1 : -1];379char ctz52[__builtin_ctzg((unsigned __int128)0x10) == 4 ? 1 : -1];380char ctz53[__builtin_ctzg((unsigned __int128)0x10, 42) == 4 ? 1 : -1];381char ctz54[__builtin_ctzg((unsigned __int128)1 << (BITSIZE(__int128) - 1)) == BITSIZE(__int128) - 1 ? 1 : -1];382char ctz55[__builtin_ctzg((unsigned __int128)1 << (BITSIZE(__int128) - 1), 42) == BITSIZE(__int128) - 1 ? 1 : -1];383#endif384int ctz56 = __builtin_ctzg((unsigned _BitInt(128))0); // expected-error {{not a compile-time constant}}385char ctz57[__builtin_ctzg((unsigned _BitInt(128))0, 42) == 42 ? 1 : -1];386char ctz58[__builtin_ctzg((unsigned _BitInt(128))0x1) == 0 ? 1 : -1];387char ctz59[__builtin_ctzg((unsigned _BitInt(128))0x1, 42) == 0 ? 1 : -1];388char ctz60[__builtin_ctzg((unsigned _BitInt(128))0x10) == 4 ? 1 : -1];389char ctz61[__builtin_ctzg((unsigned _BitInt(128))0x10, 42) == 4 ? 1 : -1];390char ctz62[__builtin_ctzg((unsigned _BitInt(128))1 << (BITSIZE(_BitInt(128)) - 1)) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1];391char ctz63[__builtin_ctzg((unsigned _BitInt(128))1 << (BITSIZE(_BitInt(128)) - 1), 42) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1];392 393char popcount1[__builtin_popcount(0) == 0 ? 1 : -1];394char popcount2[__builtin_popcount(0xF0F0) == 8 ? 1 : -1];395char popcount3[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1];396char popcount4[__builtin_popcount(~0L) == BITSIZE(int) ? 1 : -1];397char popcount5[__builtin_popcountl(0L) == 0 ? 1 : -1];398char popcount6[__builtin_popcountl(0xF0F0L) == 8 ? 1 : -1];399char popcount7[__builtin_popcountl(~0L) == BITSIZE(long) ? 1 : -1];400char popcount8[__builtin_popcountll(0LL) == 0 ? 1 : -1];401char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];402char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];403char popcount11[__builtin_popcountg(0U) == 0 ? 1 : -1];404char popcount12[__builtin_popcountg(0xF0F0U) == 8 ? 1 : -1];405char popcount13[__builtin_popcountg(~0U) == BITSIZE(int) ? 1 : -1];406char popcount14[__builtin_popcountg(~0UL) == BITSIZE(long) ? 1 : -1];407char popcount15[__builtin_popcountg(~0ULL) == BITSIZE(long long) ? 1 : -1];408#ifdef __SIZEOF_INT128__409char popcount16[__builtin_popcountg(~(unsigned __int128)0) == BITSIZE(__int128) ? 1 : -1];410#endif411char popcount17[__builtin_popcountg(~(unsigned _BitInt(128))0) == BITSIZE(_BitInt(128)) ? 1 : -1];412 413char parity1[__builtin_parity(0) == 0 ? 1 : -1];414char parity2[__builtin_parity(0xb821) == 0 ? 1 : -1];415char parity3[__builtin_parity(0xb822) == 0 ? 1 : -1];416char parity4[__builtin_parity(0xb823) == 1 ? 1 : -1];417char parity5[__builtin_parity(0xb824) == 0 ? 1 : -1];418char parity6[__builtin_parity(0xb825) == 1 ? 1 : -1];419char parity7[__builtin_parity(0xb826) == 1 ? 1 : -1];420char parity8[__builtin_parity(~0) == 0 ? 1 : -1];421char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];422char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : -1];423 424char bitreverse1[__builtin_bitreverse8(0x01) == 0x80 ? 1 : -1];425char bitreverse2[__builtin_bitreverse16(0x3C48) == 0x123C ? 1 : -1];426char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1];427char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 0xF7B3D591E6A2C480 ? 1 : -1];428 429char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];430char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];431char rotateleft3[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : -1];432char rotateleft4[__builtin_rotateleft64(0xFEDCBA9876543210ULL, 55) == 0x87F6E5D4C3B2A19ULL ? 1 : -1];433 434char rotateright1[__builtin_rotateright8(0x01, 5) == 0x08 ? 1 : -1];435char rotateright2[__builtin_rotateright16(0x3210, 11) == 0x4206 ? 1 : -1];436char rotateright3[__builtin_rotateright32(0x76543210, 22) == 0x50C841D9 ? 1 : -1];437char rotateright4[__builtin_rotateright64(0xFEDCBA9876543210ULL, 55) == 0xB97530ECA86421FDULL ? 1 : -1];438 439char ffs1[__builtin_ffs(0) == 0 ? 1 : -1];440char ffs2[__builtin_ffs(1) == 1 ? 1 : -1];441char ffs3[__builtin_ffs(0xfbe71) == 1 ? 1 : -1];442char ffs4[__builtin_ffs(0xfbe70) == 5 ? 1 : -1];443char ffs5[__builtin_ffs(1U << (BITSIZE(int) - 1)) == BITSIZE(int) ? 1 : -1];444char ffs6[__builtin_ffsl(0x10L) == 5 ? 1 : -1];445char ffs7[__builtin_ffsll(0x100LL) == 9 ? 1 : -1];446 447char clrsb1[__builtin_clrsb(0) == BITSIZE(int) - 1 ? 1 : -1];448char clrsb2[__builtin_clrsbl(0L) == BITSIZE(long) - 1 ? 1 : -1];449char clrsb3[__builtin_clrsbll(0LL) == BITSIZE(long long) - 1 ? 1 : -1];450char clrsb4[__builtin_clrsb(~0) == BITSIZE(int) - 1 ? 1 : -1];451char clrsb5[__builtin_clrsbl(~0L) == BITSIZE(long) - 1 ? 1 : -1];452char clrsb6[__builtin_clrsbll(~0LL) == BITSIZE(long long) - 1 ? 1 : -1];453char clrsb7[__builtin_clrsb(1) == BITSIZE(int) - 2 ? 1 : -1];454char clrsb8[__builtin_clrsb(~1) == BITSIZE(int) - 2 ? 1 : -1];455char clrsb9[__builtin_clrsb(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];456char clrsb10[__builtin_clrsb(~(1 << (BITSIZE(int) - 1))) == 0 ? 1 : -1];457char clrsb11[__builtin_clrsb(0xf) == BITSIZE(int) - 5 ? 1 : -1];458char clrsb12[__builtin_clrsb(~0x1f) == BITSIZE(int) - 6 ? 1 : -1];459 460char abs1[__builtin_abs(-12)];461char abs2[__builtin_labs(-12L)];462char abs3[__builtin_llabs(-12LL)];463int abs4 = __builtin_abs(1 << (BITSIZE(int) - 1)); // expected-error {{not a compile-time constant}}464char abs5[__builtin_abs((1 << (BITSIZE(int) - 1)) + 1)];465long abs6 = __builtin_labs(1L << (BITSIZE(long) - 1)); // expected-error {{not a compile-time constant}}466long abs7 = __builtin_labs((1L << (BITSIZE(long) - 1)) + 1);467long long abs8 = __builtin_llabs(1LL << (BITSIZE(long long) - 1)); // expected-error {{not a compile-time constant}}468long long abs9 = __builtin_llabs((1LL << (BITSIZE(long long) - 1)) + 1);469 470#undef BITSIZE471 472// GCC misc stuff473 474extern int f(void);475 476int h0 = __builtin_types_compatible_p(int, float);477//int h1 = __builtin_choose_expr(1, 10, f());478//int h2 = __builtin_expect(0, 0);479int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();480int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();481int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();482int h6 = __builtin_bswapg((char)(0x12)) == (char)(0x12) ? 1 : f();483int h7 = __builtin_bswapg((short)(0x1234)) == (short)(0x3412) ? 1 : f();484int h8 = __builtin_bswapg(0x00001234) == 0x34120000 ? 1 : f();485int h9 = __builtin_bswapg(0x0000000000001234ULL) == 0x3412000000000000 ? 1 : f();486float h10 = __builtin_bswapg(1.0f); // expected-error {{1st argument must be a scalar integer type (was 'float')}}487double h12 = __builtin_bswapg(1.0L); // expected-error {{1st argument must be a scalar integer type (was 'long double')}}488char *h13 = __builtin_bswapg("hello"); // expected-error {{1st argument must be a scalar integer type (was 'char[6]')}}489int h14 = __builtin_bswapg(1, 2); // expected-error {{too many arguments to function call, expected 1, have 2}}490int *h15 = __builtin_bswapg(&h9); // expected-error {{1st argument must be a scalar integer type (was 'int *')}}491int arr[4] = {0x12, 0x34, 0x56, 0x78};492int h16 = __builtin_bswapg(arr); // expected-error {{1st argument must be a scalar integer type (was 'int[4]')}}493enum BasicEnum {494 ENUM_VALUE1 = 0x1234,495};496int h17 = __builtin_bswapg(ENUM_VALUE1) == 0x34120000 ? 1 : f();497int h18 = __builtin_bswapg((_BitInt(8))0x12) == (_BitInt(8))0x12 ? 1 : f();498int h19 = __builtin_bswapg((_BitInt(16))0x1234) == (_BitInt(16))0x3412 ? 1 : f();499int h20 = __builtin_bswapg((_BitInt(32))0x00001234) == (_BitInt(32))0x34120000 ? 1 : f();500int h21 = __builtin_bswapg((_BitInt(64))0x0000000000001234) == (_BitInt(64))0x3412000000000000 ? 1 : f();501int h22 = __builtin_bswapg(~(_BitInt(128))0) == (~(_BitInt(128))0) ? 1 : f();502int h23 = __builtin_bswapg((_BitInt(24))0x1234) == (_BitInt(24))0x3412 ? 1 : f();503// expected-error@-1 {{_BitInt type '_BitInt(24)' (24 bits) must be a multiple of 16 bits for byte swapping}}504extern long int bi0;505extern __typeof__(__builtin_expect(0, 0)) bi0;506 507// Strings508int array1[__builtin_strlen("ab\0cd")];509int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];510