[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / builtins-overflow.c
blob302489c19e37964df8fd566980a0f92ca3860de5
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 #if __has_feature(__builtin_add_overflow)
4 #warning defined as expected
5 // expected-warning@-1 {{defined as expected}}
6 #endif
8 void test(void) {
9 unsigned r;
10 const char * c;
11 float f;
12 const unsigned q;
14 __builtin_add_overflow(); // expected-error {{too few arguments to function call, expected 3, have 0}}
15 __builtin_add_overflow(1, 1, 1, 1); // expected-error {{too many arguments to function call, expected 3, have 4}}
17 __builtin_add_overflow(c, 1, &r); // expected-error {{operand argument to overflow builtin must be an integer type ('const char *' invalid)}}
18 __builtin_add_overflow(1, c, &r); // expected-error {{operand argument to overflow builtin must be an integer type ('const char *' invalid)}}
19 __builtin_add_overflow(1, 1, 3); // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('int' invalid)}}
20 __builtin_add_overflow(1, 1, &f); // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('float *' invalid)}}
21 __builtin_add_overflow(1, 1, &q); // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('const unsigned int *' invalid)}}
24 _BitInt(128) x = 1;
25 _BitInt(128) y = 1;
26 _BitInt(128) result;
27 _Bool status = __builtin_mul_overflow(x, y, &result); // expect ok
29 #if __BITINT_MAXWIDTH__ > 128
31 unsigned _BitInt(129) x = 1;
32 unsigned _BitInt(129) y = 1;
33 unsigned _BitInt(129) result;
34 _Bool status = __builtin_mul_overflow(x, y, &result); // expect ok
37 _BitInt(129) x = 1;
38 _BitInt(129) y = 1;
39 _BitInt(129) result;
40 _Bool status = __builtin_mul_overflow(x, y, &result); // expected-error {{__builtin_mul_overflow does not support 'signed _BitInt' operands of more than 128 bits}}
42 #endif