blob: 14674c66f3a66ed2519722dbd3dab1067c3e6bf5 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin9 -verify %s
Daniel Dunbar20e5db72008-09-03 21:17:21 +00003
4int a[10];
5
6int f0() {
7 return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
8}
9int f1() {
10 return (__builtin_object_size(&a, 0) +
11 __builtin_object_size(&a, 1) +
12 __builtin_object_size(&a, 2) +
13 __builtin_object_size(&a, 3));
14}
15int f2() {
16 return __builtin_object_size(&a, -1); // expected-error {{argument should be a value from 0 to 3}}
17}
18int f3() {
19 return __builtin_object_size(&a, 4); // expected-error {{argument should be a value from 0 to 3}}
20}
Chris Lattner037379d2008-09-28 06:05:35 +000021
22
23// rdar://6252231 - cannot call vsnprintf with va_list on x86_64
24void f4(const char *fmt, ...) {
25 __builtin_va_list args;
Fariborz Jahanian3e6a0be2014-09-18 17:58:27 +000026 __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'__builtin___vsnprintf_chk' will always overflow destination buffer}}
Chris Lattner037379d2008-09-28 06:05:35 +000027}
28
Fariborz Jahaniana3d88792014-09-22 17:11:59 +000029// rdar://18334276
Hans Wennborg38277f72014-09-23 00:02:36 +000030typedef __typeof__(sizeof(int)) size_t;
Fariborz Jahaniana3d88792014-09-22 17:11:59 +000031void * memcset(void *restrict dst, int src, size_t n);
32void * memcpy(void *restrict dst, const void *restrict src, size_t n);
33
34#define memset(dest, src, len) __builtin___memset_chk(dest, src, len, __builtin_object_size(dest, 0))
35#define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, __builtin_object_size(dest, 0))
36#define memcpy1(dest, src, len) __builtin___memcpy_chk(dest, src, len, __builtin_object_size(dest, 4))
37#define NULL ((void *)0)
38
39void f5(void)
40{
41 char buf[10];
42 memset((void *)0x100000000ULL, 0, 0x1000);
43 memcpy((char *)NULL + 0x10000, buf, 0x10);
44 memcpy1((char *)NULL + 0x10000, buf, 0x10); // expected-error {{argument should be a value from 0 to 3}}
45}
Steven Wu566c14e2014-09-24 04:37:33 +000046
47// rdar://18431336
48void f6(void)
49{
50 char b[5];
51 char buf[10];
52 __builtin___memccpy_chk (buf, b, '\0', sizeof(b), __builtin_object_size (buf, 0));
53 __builtin___memccpy_chk (b, buf, '\0', sizeof(buf), __builtin_object_size (b, 0)); // expected-warning {{'__builtin___memccpy_chk' will always overflow destination buffer}}
54}
George Burgess IV4168d752016-06-27 19:40:41 +000055
56int pr28314(void) {
57 struct {
58 struct InvalidField a; // expected-error{{has incomplete type}} expected-note 3{{forward declaration of 'struct InvalidField'}}
59 char b[0];
60 } *p;
61
62 struct {
63 struct InvalidField a; // expected-error{{has incomplete type}}
64 char b[1];
65 } *p2;
66
67 struct {
68 struct InvalidField a; // expected-error{{has incomplete type}}
69 char b[2];
70 } *p3;
71
72 int a = 0;
73 a += __builtin_object_size(&p->a, 0);
74 a += __builtin_object_size(p->b, 0);
75 a += __builtin_object_size(p2->b, 0);
76 a += __builtin_object_size(p3->b, 0);
77 return a;
78}