brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 9238b60 Raw
83 lines · c
1// RUN: %clang_cc1 -verify -fsyntax-only %s2 3typedef __SIZE_TYPE__ size_t;4 5typedef struct {6  void *ptr;7  size_t n;8} span;9span  returns_span  (void) __attribute((malloc_span)); // no-warning10 11typedef struct {12  size_t n;13  void *ptr;14} span2;15span2  returns_span2  (void) __attribute((malloc_span)); // no-warning16 17typedef struct {18  void *ptr;19  void *ptr2;20} span3;21span3  returns_span3  (void) __attribute((malloc_span)); // no-warning22 23typedef struct {24  void *ptr;25  int n;26} span4;27span4  returns_span4  (void) __attribute((malloc_span)); // no-warning28 29typedef struct incomplete_span incomplete_span;30// expected-warning@+2 {{attribute only applies to functions that return span-like structures}}31// expected-note@+1 {{returned type is incomplete}}32incomplete_span returns_incomplete_span (void) __attribute((malloc_span));33 34// expected-warning@+2 {{attribute only applies to functions that return span-like structures}}35// expected-note@+1 {{returned type is not a struct type}}36int *returns_int_ptr  (void) __attribute((malloc_span));37 38typedef struct {39  void *ptr;40  size_t n;41  size_t n2;42} too_long_span;43// expected-warning@+2 {{attribute only applies to functions that return span-like structures}}44// expected-note@+1 {{returned struct has 3 fields, expected 2}}45too_long_span  returns_too_long_span  (void) __attribute((malloc_span));46 47// Function pointers are not allowed.48typedef struct {49  int (*func_ptr)(void);50  size_t n;51} func_span;52// expected-warning@+2 {{attribute only applies to functions that return span-like structures}}53// expected-note@+1 {{returned struct fields are not a supported combination}}54func_span  returns_func_span  (void) __attribute((malloc_span));55 56// Integer should not be an enum.57enum some_enum { some_value, other_value };58typedef struct {59  void *ptr;60  enum some_enum field;61} enum_span;62// expected-warning@+2 {{attribute only applies to functions that return span-like structures}}63// expected-note@+1 {{2nd field is expected to be an integer}}64enum_span  returns_enum_span  (void) __attribute((malloc_span));65 66// Bit integers are also not supported.67typedef struct {68  void *ptr;69  _BitInt(16) n;70} bit_span;71// expected-warning@+2 {{attribute only applies to functions that return span-like structures}}72// expected-note@+1 {{2nd field is expected to be an integer}}73bit_span  returns_bit_span  (void) __attribute((malloc_span));74 75// Integer must be at least as big as int.76typedef struct {77  void *ptr;78  short n;79} short_span;80// expected-warning@+2 {{attribute only applies to functions that return span-like structures}}81// expected-note@+1 {{2nd field of span-like type is not a wide enough integer (minimum width: 32)}}82short_span  returns_short_span  (void) __attribute((malloc_span));83