1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin9 -verify %s
3 
4 int a[10];
5 
f0()6 int f0() {
7   return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
8 }
f1()9 int 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 }
f2()15 int f2() {
16   return __builtin_object_size(&a, -1); // expected-error {{argument should be a value from 0 to 3}}
17 }
f3()18 int f3() {
19   return __builtin_object_size(&a, 4); // expected-error {{argument should be a value from 0 to 3}}
20 }
21 
22 
23 // rdar://6252231 - cannot call vsnprintf with va_list on x86_64
f4(const char * fmt,...)24 void f4(const char *fmt, ...) {
25  __builtin_va_list args;
26  __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'__builtin___vsnprintf_chk' will always overflow destination buffer}}
27 }
28 
29 // rdar://18334276
30 typedef __typeof__(sizeof(int)) size_t;
31 void * memcset(void *restrict dst, int src, size_t n);
32 void * 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 
f5(void)39 void 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 }
46 
47 // rdar://18431336
f6(void)48 void 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 }
55