brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · a763c24 Raw
122 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin9 -verify %s3// RUN: %clang_cc1 -DDYNAMIC -fsyntax-only -triple x86_64-apple-darwin9 -verify %s4 5// RUN: %clang_cc1 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter6// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin9 -verify %s -fexperimental-new-constant-interpreter7// RUN: %clang_cc1 -DDYNAMIC -fsyntax-only -triple x86_64-apple-darwin9 -verify %s -fexperimental-new-constant-interpreter8 9#ifndef DYNAMIC10#define OBJECT_SIZE_BUILTIN __builtin_object_size11#else12#define OBJECT_SIZE_BUILTIN __builtin_dynamic_object_size13#endif14 15int a[10];16 17int f0(void) {18  return OBJECT_SIZE_BUILTIN(&a); // expected-error {{too few arguments to function}}19}20int f1(void) {21  return (OBJECT_SIZE_BUILTIN(&a, 0) + 22          OBJECT_SIZE_BUILTIN(&a, 1) + 23          OBJECT_SIZE_BUILTIN(&a, 2) + 24          OBJECT_SIZE_BUILTIN(&a, 3));25}26int f2(void) {27  return OBJECT_SIZE_BUILTIN(&a, -1); // expected-error {{argument value -1 is outside the valid range [0, 3]}}28}29int f3(void) {30  return OBJECT_SIZE_BUILTIN(&a, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}}31}32 33 34// cannot call vsnprintf with va_list on x86_6435void f4(const char *fmt, ...) {36 __builtin_va_list args;37 __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}}38}39 40typedef __typeof__(sizeof(int)) size_t;41void * memcset(void *restrict dst, int src, size_t n);42void * memcpy(void *restrict dst, const void *restrict src, size_t n);43 44#define memset(dest, src, len) __builtin___memset_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 0))45#define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 0))46#define memcpy1(dest, src, len) __builtin___memcpy_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 4))47#define NULL ((void *)0)48 49void f5(void)50{51  char buf[10];52  memset((void *)0x100000000ULL, 0, 0x1000);53  memcpy((char *)NULL + 0x10000, buf, 0x10);54  memcpy1((char *)NULL + 0x10000, buf, 0x10); // expected-error {{argument value 4 is outside the valid range [0, 3]}}55}56 57void f6(void)58{59  char b[5];60  char buf[10];61  __builtin___memccpy_chk (buf, b, '\0', sizeof(b), OBJECT_SIZE_BUILTIN (buf, 0));62  __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}64 65int pr28314(void) {66  struct {67    struct InvalidField a; // expected-error{{has incomplete type}} expected-note 3{{forward declaration of 'struct InvalidField'}}68    char b[0];69  } *p;70 71  struct {72    struct InvalidField a; // expected-error{{has incomplete type}}73    char b[1];74  } *p2;75 76  struct {77    struct InvalidField a; // expected-error{{has incomplete type}}78    char b[2];79  } *p3;80 81  int a = 0;82  a += OBJECT_SIZE_BUILTIN(&p->a, 0);83  a += OBJECT_SIZE_BUILTIN(p->b, 0);84  a += OBJECT_SIZE_BUILTIN(p2->b, 0);85  a += OBJECT_SIZE_BUILTIN(p3->b, 0);86  return a;87}88 89int pr31843(void) {90  int n = 0;91 92  struct { int f; } a;93  int b;94  n += OBJECT_SIZE_BUILTIN(({&(b ? &a : &a)->f; pr31843;}), 0); // expected-warning{{expression result unused}}95 96  struct statfs { char f_mntonname[1024];};97  struct statfs *outStatFSBuf;98  n += OBJECT_SIZE_BUILTIN(outStatFSBuf->f_mntonname ? "" : "", 1); // expected-warning{{address of array}}99  n += OBJECT_SIZE_BUILTIN(outStatFSBuf->f_mntonname ?: "", 1);100 101  return n;102}103 104typedef struct {105  char string[512];106} NestedArrayStruct;107 108typedef struct {109  int x;110  NestedArrayStruct session[];111} IncompleteArrayStruct;112 113void rd36094951_IAS_builtin_object_size_assertion(IncompleteArrayStruct *p) {114#define rd36094951_CHECK(mode)                                                 \115  __builtin___strlcpy_chk(p->session[0].string, "ab", 2,                       \116                          OBJECT_SIZE_BUILTIN(p->session[0].string, mode))117  rd36094951_CHECK(0);118  rd36094951_CHECK(1);119  rd36094951_CHECK(2);120  rd36094951_CHECK(3);121}122