void fn0 (int n) { p = __builtin_alloca_with_align (n, 6); /* { dg-error "39:must be a constant integer" } */ r += __builtin_isfinite (0); /* { dg-error "28:non-floating-point argument in call" } */ r += __builtin_isinf (0); /* { dg-error "25:non-floating-point argument in call" } */ r += __builtin_isinf_sign (0); /* { dg-error "30:non-floating-point argument in call" } */ r += __builtin_isnan (0); /* { dg-error "25:non-floating-point argument in call" } */ r += __builtin_isnormal (0); /* { dg-error "28:non-floating-point argument in call" } */ r += __builtin_signbit (0); /* { dg-error "27:non-floating-point argument in call" } */ r += __builtin_isgreater (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */ r += __builtin_isgreaterequal (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */ r += __builtin_isless (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */ r += __builtin_islessequal (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */ r += __builtin_islessgreater (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */ r += __builtin_isunordered (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */ r += __builtin_fpclassify (1, 2, n, 4, 5, n); /* { dg-error "36:non-const integer argument 3 in call" } */ r += __builtin_fpclassify (1, 2, 3, 4, 5, 6); /* { dg-error "45:non-floating-point argument in call" } */ d = __builtin_assume_aligned (p, n, p); /* { dg-error "39:non-integer argument 3 in call" } */ b = __builtin_add_overflow (n, *d, &r); /* { dg-error "34:argument 2 in call to function" } */ b = __builtin_add_overflow (n, 5, d); /* { dg-error "37:argument 3 in call" } */ b = __builtin_sub_overflow (n, *d, &r); /* { dg-error "34:argument 2 in call to function" } */ b = __builtin_sub_overflow (n, 5, d); /* { dg-error "37:argument 3 in call" } */ b = __builtin_mul_overflow (n, *d, &r); /* { dg-error "34:argument 2 in call to function" } */ b = __builtin_mul_overflow (n, 5, d); /* { dg-error "37:argument 3 in call" } */ }
int f3 (float fa, int a, _Complex long int ca, double fb, void *pb, int b, enum E eb, bool bb, int *c) { int x = __builtin_add_overflow (fa, b, c); /* { dg-error "argument 1 in call to function\[^\n\r]*does not have integral type" } */ x += __builtin_sub_overflow (ca, b, c); /* { dg-error "argument 1 in call to function\[^\n\r]*does not have integral type" } */ x += __builtin_mul_overflow (a, fb, c); /* { dg-error "argument 2 in call to function\[^\n\r]*does not have integral type" } */ x += __builtin_add_overflow (a, pb, c); /* { dg-error "argument 2 in call to function\[^\n\r]*does not have integral type" } */ x += __builtin_sub_overflow (a, eb, c); x += __builtin_mul_overflow (a, bb, c); return x; }
int f4 (float *fp, double *dp, _Complex int *cp, enum E *ep, bool *bp, long long int *llp) { int x = __builtin_add_overflow (1, 2, fp); /* { dg-error "argument 3 in call to function\[^\n\r]*does not have pointer to integer type" } */ x += __builtin_sub_overflow (1, 2, dp); /* { dg-error "argument 3 in call to function\[^\n\r]*does not have pointer to integer type" } */ x += __builtin_mul_overflow (1, 2, cp); /* { dg-error "argument 3 in call to function\[^\n\r]*does not have pointer to integer type" } */ x += __builtin_add_overflow (1, 2, ep); /* { dg-error "argument 3 in call to function\[^\n\r]*does not have pointer to integer type" } */ x += __builtin_sub_overflow (1, 2, bp); /* { dg-error "argument 3 in call to function\[^\n\r]*does not have pointer to integer type" } */ x += __builtin_mul_overflow (1, 2, llp); return x; }
U usseu (U x, S y, int *ovf) { U res; *ovf = __builtin_sub_overflow (x, y, &res); return res; }
int f2 (int a, int b, int *c, int d) { int x = __builtin_add_overflow (a, b, c, d); /* { dg-error "too many arguments to function" } */ x += __builtin_sub_overflow (a, b, c, d, d, d); /* { dg-error "too many arguments to function" } */ x += __builtin_mul_overflow (a, b, c, d); /* { dg-error "too many arguments to function" } */ return x; }
int f1 (void) { int x = __builtin_add_overflow (); /* { dg-error "not enough arguments to function" } */ x += __builtin_sub_overflow (); /* { dg-error "not enough arguments to function" } */ x += __builtin_mul_overflow (); /* { dg-error "not enough arguments to function" } */ return x; }
bool Overflow<Unsigned>::operator-=(Unsigned other) { #ifdef __GNUC__ return __builtin_sub_overflow(_value, other, &_value); #else bool overflow = _value < other; _value -= other; return overflow; #endif }
/* SUB_OVERFLOW should be folded into unsigned subtraction, because ovf is never used. */ __attribute__((noinline, noclone)) int fn1 (int x, unsigned int y) { int res; int ovf = __builtin_sub_overflow (x, y, &res); int res2 = res; int res3 = res2 - 2; (void) ovf; return res; }
Fraction Fraction::operator -= (const Fraction& rhs) { const int lcm = LCM(DenominatorAsInt(), rhs.DenominatorAsInt()); int A = 0, B = 0; if (__builtin_mul_overflow(numerator / DenominatorAsInt(), lcm, &A)) goto err; if (__builtin_mul_overflow(rhs.numerator / rhs.DenominatorAsInt(), lcm, &B)) goto err; if (__builtin_sub_overflow(A, B, &numerator)) goto err; denominator = lcm; Reduce(); // std::cout << "result: " << *this << std::endl; return *this; err: valid = false; return *this; }
int a() { const int x = 3; static int z; constexpr int *y = &z; return []() { return __builtin_sub_overflow((int)x, (int)x, (int *)y); }(); }
constexpr Result<RET> sub(LHS &&lhs, RHS &&rhs) { RET sum{}; return {__builtin_sub_overflow(lhs, rhs, &sum), sum}; }
int a2() { const int x = 3; static int z; constexpr int *y = &z; return []() { return __builtin_sub_overflow(x, x, y); }(); }
bool my_neg_overflow (int a, int *res) { return __builtin_sub_overflow (0, a, res); }
bool my_sub_overflow (int a, int b, int *res) { return __builtin_sub_overflow (a, b, res); }
bool my_uneg_overflow (unsigned int a, unsigned int *res) { return __builtin_sub_overflow (0, a, res); }
bool my_usub_overflow (unsigned int a, unsigned int b, unsigned int *res) { return __builtin_sub_overflow (a, b, res); }
// Determine video dimensions from the sequence parameterset. void FindAVCDimensions( const sp<ABuffer> &seqParamSet, int32_t *width, int32_t *height, int32_t *sarWidth, int32_t *sarHeight) { ABitReader br(seqParamSet->data() + 1, seqParamSet->size() - 1); unsigned profile_idc = br.getBits(8); br.skipBits(16); parseUE(&br); // seq_parameter_set_id unsigned chroma_format_idc = 1; // 4:2:0 chroma format if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244 || profile_idc == 44 || profile_idc == 83 || profile_idc == 86) { chroma_format_idc = parseUE(&br); if (chroma_format_idc == 3) { br.skipBits(1); // residual_colour_transform_flag } parseUE(&br); // bit_depth_luma_minus8 parseUE(&br); // bit_depth_chroma_minus8 br.skipBits(1); // qpprime_y_zero_transform_bypass_flag if (br.getBits(1)) { // seq_scaling_matrix_present_flag for (size_t i = 0; i < 8; ++i) { if (br.getBits(1)) { // seq_scaling_list_present_flag[i] // WARNING: the code below has not ever been exercised... // need a real-world example. if (i < 6) { // ScalingList4x4[i],16,... skipScalingList(&br, 16); } else { // ScalingList8x8[i-6],64,... skipScalingList(&br, 64); } } } } } parseUE(&br); // log2_max_frame_num_minus4 unsigned pic_order_cnt_type = parseUE(&br); if (pic_order_cnt_type == 0) { parseUE(&br); // log2_max_pic_order_cnt_lsb_minus4 } else if (pic_order_cnt_type == 1) { // offset_for_non_ref_pic, offset_for_top_to_bottom_field and // offset_for_ref_frame are technically se(v), but since we are // just skipping over them the midpoint does not matter. br.getBits(1); // delta_pic_order_always_zero_flag parseUE(&br); // offset_for_non_ref_pic parseUE(&br); // offset_for_top_to_bottom_field unsigned num_ref_frames_in_pic_order_cnt_cycle = parseUE(&br); for (unsigned i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) { parseUE(&br); // offset_for_ref_frame } } parseUE(&br); // num_ref_frames br.getBits(1); // gaps_in_frame_num_value_allowed_flag unsigned pic_width_in_mbs_minus1 = parseUE(&br); unsigned pic_height_in_map_units_minus1 = parseUE(&br); unsigned frame_mbs_only_flag = br.getBits(1); *width = pic_width_in_mbs_minus1 * 16 + 16; *height = (2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 * 16 + 16); if (!frame_mbs_only_flag) { br.getBits(1); // mb_adaptive_frame_field_flag } br.getBits(1); // direct_8x8_inference_flag if (br.getBits(1)) { // frame_cropping_flag unsigned frame_crop_left_offset = parseUE(&br); unsigned frame_crop_right_offset = parseUE(&br); unsigned frame_crop_top_offset = parseUE(&br); unsigned frame_crop_bottom_offset = parseUE(&br); unsigned cropUnitX, cropUnitY; if (chroma_format_idc == 0 /* monochrome */) { cropUnitX = 1; cropUnitY = 2 - frame_mbs_only_flag; } else { unsigned subWidthC = (chroma_format_idc == 3) ? 1 : 2; unsigned subHeightC = (chroma_format_idc == 1) ? 2 : 1; cropUnitX = subWidthC; cropUnitY = subHeightC * (2 - frame_mbs_only_flag); } ALOGV("frame_crop = (%u, %u, %u, %u), cropUnitX = %u, cropUnitY = %u", frame_crop_left_offset, frame_crop_right_offset, frame_crop_top_offset, frame_crop_bottom_offset, cropUnitX, cropUnitY); // *width -= (frame_crop_left_offset + frame_crop_right_offset) * cropUnitX; if(__builtin_add_overflow(frame_crop_left_offset, frame_crop_right_offset, &frame_crop_left_offset) || __builtin_mul_overflow(frame_crop_left_offset, cropUnitX, &frame_crop_left_offset) || __builtin_sub_overflow(*width, frame_crop_left_offset, width) || *width < 0) { *width = 0; } //*height -= (frame_crop_top_offset + frame_crop_bottom_offset) * cropUnitY; if(__builtin_add_overflow(frame_crop_top_offset, frame_crop_bottom_offset, &frame_crop_top_offset) || __builtin_mul_overflow(frame_crop_top_offset, cropUnitY, &frame_crop_top_offset) || __builtin_sub_overflow(*height, frame_crop_top_offset, height) || *height < 0) { *height = 0; } } if (sarWidth != NULL) { *sarWidth = 0; } if (sarHeight != NULL) { *sarHeight = 0; } if (br.getBits(1)) { // vui_parameters_present_flag unsigned sar_width = 0, sar_height = 0; if (br.getBits(1)) { // aspect_ratio_info_present_flag unsigned aspect_ratio_idc = br.getBits(8); if (aspect_ratio_idc == 255 /* extendedSAR */) { sar_width = br.getBits(16); sar_height = br.getBits(16); } else { static const struct { unsigned width, height; } kFixedSARs[] = { { 0, 0 }, // Invalid { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 }, { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 }, { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 }, { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 }, }; if (aspect_ratio_idc > 0 && aspect_ratio_idc < NELEM(kFixedSARs)) { sar_width = kFixedSARs[aspect_ratio_idc].width; sar_height = kFixedSARs[aspect_ratio_idc].height; } } } ALOGV("sample aspect ratio = %u : %u", sar_width, sar_height); if (sarWidth != NULL) { *sarWidth = sar_width; } if (sarHeight != NULL) { *sarHeight = sar_height; } } }
int main(int argc, const char **argv) { signed char res; if (__builtin_sub_overflow((signed char)0x0, (signed char)0x0, &res)) { return -1; } if (__builtin_sub_overflow((signed char)0x0, (signed char)0x7F, &res)) { return -1; } if (!__builtin_sub_overflow((signed char)0x0, (signed char)0x80, &res)) { return -1; } if (__builtin_sub_overflow((signed char)0x0, (signed char)0x81, &res)) { return -1; } if (__builtin_sub_overflow((signed char)0x1, (signed char)0x7F, &res)) { return -1; } if (__builtin_sub_overflow((signed char)0x7F, (signed char)0x0, &res)) { return -1; } if (__builtin_sub_overflow((signed char)0x7F, (signed char)0x1, &res)) { return -1; } if (__builtin_sub_overflow((signed char)0x7F, (signed char)0x7F, &res)) { return -1; } if (!__builtin_sub_overflow((signed char)0x7F, (signed char)0x80, &res)) { return -1; } if (!__builtin_sub_overflow((signed char)0x7F, (signed char)0xFF, &res)) { return -1; } if (!__builtin_sub_overflow((signed char)0x80, (signed char)0x7F, &res)) { return -1; } if (__builtin_sub_overflow((signed char)0x80, (signed char)0x80, &res)) { return -1; } if (__builtin_sub_overflow((signed char)0x81, (signed char)0x1, &res)) { return -1; } if (!__builtin_sub_overflow((signed char)0x81, (signed char)0x2, &res)) { return -1; } return 0; }