1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin9 -verify %s
3 // RUN: %clang_cc1 -DDYNAMIC -fsyntax-only -triple x86_64-apple-darwin9 -verify %s
6 #define OBJECT_SIZE_BUILTIN __builtin_object_size
8 #define OBJECT_SIZE_BUILTIN __builtin_dynamic_object_size
14 return OBJECT_SIZE_BUILTIN(&a
); // expected-error {{too few arguments to function}}
17 return (OBJECT_SIZE_BUILTIN(&a
, 0) +
18 OBJECT_SIZE_BUILTIN(&a
, 1) +
19 OBJECT_SIZE_BUILTIN(&a
, 2) +
20 OBJECT_SIZE_BUILTIN(&a
, 3));
23 return OBJECT_SIZE_BUILTIN(&a
, -1); // expected-error {{argument value -1 is outside the valid range [0, 3]}}
26 return OBJECT_SIZE_BUILTIN(&a
, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
30 // cannot call vsnprintf with va_list on x86_64
31 void f4(const char *fmt
, ...) {
32 __builtin_va_list args
;
33 __builtin___vsnprintf_chk (0, 42, 0, 11, fmt
, args
); // expected-warning {{'vsnprintf' will always overflow; destination buffer has size 11, but size argument is 42}}
36 typedef __typeof__(sizeof(int)) size_t;
37 void * memcset(void *restrict dst
, int src
, size_t n
);
38 void * memcpy(void *restrict dst
, const void *restrict src
, size_t n
);
40 #define memset(dest, src, len) __builtin___memset_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 0))
41 #define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 0))
42 #define memcpy1(dest, src, len) __builtin___memcpy_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 4))
43 #define NULL ((void *)0)
48 memset((void *)0x100000000ULL
, 0, 0x1000);
49 memcpy((char *)NULL
+ 0x10000, buf
, 0x10);
50 memcpy1((char *)NULL
+ 0x10000, buf
, 0x10); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
57 __builtin___memccpy_chk (buf
, b
, '\0', sizeof(b
), OBJECT_SIZE_BUILTIN (buf
, 0));
58 __builtin___memccpy_chk (b
, buf
, '\0', sizeof(buf
), OBJECT_SIZE_BUILTIN (b
, 0)); // expected-warning {{'memccpy' will always overflow; destination buffer has size 5, but size argument is 10}}
63 struct InvalidField a
; // expected-error{{has incomplete type}} expected-note 3{{forward declaration of 'struct InvalidField'}}
68 struct InvalidField a
; // expected-error{{has incomplete type}}
73 struct InvalidField a
; // expected-error{{has incomplete type}}
78 a
+= OBJECT_SIZE_BUILTIN(&p
->a
, 0);
79 a
+= OBJECT_SIZE_BUILTIN(p
->b
, 0);
80 a
+= OBJECT_SIZE_BUILTIN(p2
->b
, 0);
81 a
+= OBJECT_SIZE_BUILTIN(p3
->b
, 0);
90 n
+= OBJECT_SIZE_BUILTIN(({&(b
? &a
: &a
)->f
; pr31843
;}), 0); // expected-warning{{expression result unused}}
92 struct statfs
{ char f_mntonname
[1024];};
93 struct statfs
*outStatFSBuf
;
94 n
+= OBJECT_SIZE_BUILTIN(outStatFSBuf
->f_mntonname
? "" : "", 1); // expected-warning{{address of array}}
95 n
+= OBJECT_SIZE_BUILTIN(outStatFSBuf
->f_mntonname
?: "", 1);
106 NestedArrayStruct session
[];
107 } IncompleteArrayStruct
;
109 void rd36094951_IAS_builtin_object_size_assertion(IncompleteArrayStruct
*p
) {
110 #define rd36094951_CHECK(mode) \
111 __builtin___strlcpy_chk(p->session[0].string, "ab", 2, \
112 OBJECT_SIZE_BUILTIN(p->session[0].string, mode))