typedef unsigned long size_t;
struct Foo {
int t[10];
};
#define PS(N) __attribute__((pass_object_size(N)))
#define PDS(N) __attribute__((pass_dynamic_object_size(N)))
int gi = 0;
int ObjectSize0(void *const p PS(0)) {
return __builtin_object_size(p, 0);
}
int DynamicObjectSize0(void *const p PDS(0)) {
return __builtin_dynamic_object_size(p, 0);
}
int ObjectSize1(void *const p PS(1)) {
return __builtin_object_size(p, 1);
}
int DynamicObjectSize1(void *const p PDS(1)) {
return __builtin_dynamic_object_size(p, 1);
}
int ObjectSize2(void *const p PS(2)) {
return __builtin_object_size(p, 2);
}
int DynamicObjectSize2(void *const p PDS(2)) {
return __builtin_object_size(p, 2);
}
int ObjectSize3(void *const p PS(3)) {
return __builtin_object_size(p, 3);
}
int DynamicObjectSize3(void *const p PDS(3)) {
return __builtin_object_size(p, 3);
}
void *malloc(unsigned long) __attribute__((alloc_size(1)));
void test1(unsigned long sz) {
struct Foo t[10];
gi = ObjectSize0(&t[1]);
gi = ObjectSize1(&t[1]);
gi = ObjectSize2(&t[1]);
gi = ObjectSize3(&t[1]);
gi = ObjectSize0(&t[1].t[1]);
gi = ObjectSize1(&t[1].t[1]);
gi = ObjectSize2(&t[1].t[1]);
gi = ObjectSize3(&t[1].t[1]);
char *ptr = (char *)malloc(sz);
gi = DynamicObjectSize0(ptr);
gi = DynamicObjectSize0(ptr+10);
gi = DynamicObjectSize2(ptr);
}
void test2(struct Foo *t) {
gi = ObjectSize1(&t->t[1]);
gi = ObjectSize3(&t->t[1]);
}
int NoViableOverloadObjectSize0(void *const p) __attribute__((overloadable)) {
return __builtin_object_size(p, 0);
}
int NoViableOverloadDynamicObjectSize0(void *const p)
__attribute__((overloadable)) {
return __builtin_object_size(p, 0);
}
int NoViableOverloadObjectSize1(void *const p) __attribute__((overloadable)) {
return __builtin_object_size(p, 1);
}
int NoViableOverloadObjectSize2(void *const p) __attribute__((overloadable)) {
return __builtin_object_size(p, 2);
}
int NoViableOverloadObjectSize3(void *const p) __attribute__((overloadable)) {
return __builtin_object_size(p, 3);
}
int NoViableOverloadObjectSize0(void *const p PS(0))
__attribute__((overloadable)) {
return __builtin_object_size(p, 0);
}
int NoViableOverloadDynamicObjectSize0(void *const p PDS(0))
__attribute__((overloadable)) {
return __builtin_dynamic_object_size(p, 0);
}
int NoViableOverloadObjectSize1(void *const p PS(1))
__attribute__((overloadable)) {
return __builtin_object_size(p, 1);
}
int NoViableOverloadObjectSize2(void *const p PS(2))
__attribute__((overloadable)) {
return __builtin_object_size(p, 2);
}
int NoViableOverloadObjectSize3(void *const p PS(3))
__attribute__((overloadable)) {
return __builtin_object_size(p, 3);
}
const static int SHOULDNT_BE_CALLED = -100;
int NoViableOverloadObjectSize0(void *const p PS(0))
__attribute__((overloadable, enable_if(p == 0, "never selected"))) {
return SHOULDNT_BE_CALLED;
}
int NoViableOverloadObjectSize1(void *const p PS(1))
__attribute__((overloadable, enable_if(p == 0, "never selected"))) {
return SHOULDNT_BE_CALLED;
}
int NoViableOverloadObjectSize2(void *const p PS(2))
__attribute__((overloadable, enable_if(p == 0, "never selected"))) {
return SHOULDNT_BE_CALLED;
}
int NoViableOverloadObjectSize3(void *const p PS(3))
__attribute__((overloadable, enable_if(p == 0, "never selected"))) {
return SHOULDNT_BE_CALLED;
}
void test3(void) {
struct Foo t[10];
gi = NoViableOverloadObjectSize0(&t[1]);
gi = NoViableOverloadObjectSize1(&t[1]);
gi = NoViableOverloadObjectSize2(&t[1]);
gi = NoViableOverloadObjectSize3(&t[1]);
gi = NoViableOverloadObjectSize0(&t[1].t[1]);
gi = NoViableOverloadObjectSize1(&t[1].t[1]);
gi = NoViableOverloadObjectSize2(&t[1].t[1]);
gi = NoViableOverloadObjectSize3(&t[1].t[1]);
gi = NoViableOverloadDynamicObjectSize0(&t[1]);
}
void test4(struct Foo *t) {
gi = NoViableOverloadObjectSize0(&t[1]);
gi = NoViableOverloadObjectSize1(&t[1]);
gi = NoViableOverloadObjectSize2(&t[1]);
gi = NoViableOverloadObjectSize3(&t[1]);
gi = NoViableOverloadObjectSize0(&t[1].t[1]);
gi = NoViableOverloadObjectSize1(&t[1].t[1]);
gi = NoViableOverloadObjectSize2(&t[1].t[1]);
gi = NoViableOverloadObjectSize3(&t[1].t[1]);
}
void test5(void) {
struct Foo t[10];
int (*f)(void *) = &NoViableOverloadObjectSize0;
gi = f(&t[1]);
int (*g)(void *) = &NoViableOverloadDynamicObjectSize0;
gi = g(&t[1]);
}
int IndirectObjectSize0(void *const p PS(0)) {
return ObjectSize0(p);
}
int IndirectObjectSize1(void *const p PS(1)) {
return ObjectSize1(p);
}
int IndirectObjectSize2(void *const p PS(2)) {
return ObjectSize2(p);
}
int IndirectObjectSize3(void *const p PS(3)) {
return ObjectSize3(p);
}
int IndirectDynamicObjectSize0(void *const p PDS(0)) {
return ObjectSize0(p);
}
int Overload0(void *, size_t, void *, size_t);
int OverloadNoSize(void *, void *);
int OverloadedObjectSize(void *const p PS(0),
void *const c PS(0))
__attribute__((overloadable)) __asm__("Overload0");
int OverloadedObjectSize(void *const p, void *const c)
__attribute__((overloadable)) __asm__("OverloadNoSize");
void test6(void) {
int known[10], *opaque;
gi = OverloadedObjectSize(&known[0], &known[0]);
gi = OverloadedObjectSize(&known[0], opaque);
gi = OverloadedObjectSize(opaque, &known[0]);
gi = OverloadedObjectSize(opaque, opaque);
}
int Identity(void *p, size_t i) { return i; }
int AsmObjectSize0(void *const p PS(0)) __asm__("Identity");
int AsmObjectSize1(void *const p PS(1)) __asm__("Identity");
int AsmObjectSize2(void *const p PS(2)) __asm__("Identity");
int AsmObjectSize3(void *const p PS(3)) __asm__("Identity");
void test7(void) {
struct Foo t[10];
gi = AsmObjectSize0(&t[1]);
gi = AsmObjectSize1(&t[1]);
gi = AsmObjectSize2(&t[1]);
gi = AsmObjectSize3(&t[1]);
gi = AsmObjectSize0(&t[1].t[1]);
gi = AsmObjectSize1(&t[1].t[1]);
gi = AsmObjectSize2(&t[1].t[1]);
gi = AsmObjectSize3(&t[1].t[1]);
}
void test8(struct Foo *t) {
gi = AsmObjectSize1(&t[1].t[1]);
gi = AsmObjectSize3(&t[1].t[1]);
}
void DifferingObjectSize0(void *const p __attribute__((pass_object_size(0))));
void DifferingObjectSize1(void *const p __attribute__((pass_object_size(1))));
void DifferingObjectSize2(void *const p __attribute__((pass_object_size(2))));
void DifferingObjectSize3(void *const p __attribute__((pass_object_size(3))));
void test9(void *const p __attribute__((pass_object_size(0)))) {
DifferingObjectSize2(p);
DifferingObjectSize0(p);
DifferingObjectSize1(p);
DifferingObjectSize3(p);
}
void test10(void *const p __attribute__((pass_object_size(1)))) {
DifferingObjectSize2(p);
DifferingObjectSize0(p);
DifferingObjectSize1(p);
DifferingObjectSize3(p);
}
void test11(void *const p __attribute__((pass_object_size(2)))) {
DifferingObjectSize0(p);
DifferingObjectSize1(p);
DifferingObjectSize2(p);
DifferingObjectSize3(p);
}
void test12(void *const p __attribute__((pass_object_size(3)))) {
DifferingObjectSize0(p);
DifferingObjectSize1(p);
DifferingObjectSize2(p);
DifferingObjectSize3(p);
}
void test13(void) {
char c[10];
unsigned i = 0;
char *p = c;
ObjectSize0(p);
ObjectSize0(p + ++i);
ObjectSize0(p + i++);
}
void my_sprintf(char *const c __attribute__((pass_object_size(0))), ...) {}
void test14(char *c) {
my_sprintf(c);
my_sprintf(c, 1, 2, 3);
}
void pass_size_unsigned(unsigned *const PS(0));
void test15(unsigned *I) {
pass_size_unsigned(I);
}
void pass_size_as1(__attribute__((address_space(1))) void *const PS(0));
void pass_size_unsigned_as1(
__attribute__((address_space(1))) unsigned *const PS(0));
void test16(__attribute__((address_space(1))) unsigned *I) {
pass_size_as1(I);
pass_size_unsigned_as1(I);
}
void test17(char *C) {
ObjectSize0(C + ({ int a = 65535; a; }));
}
void test18(char *const p PDS(0)) {
gi = __builtin_dynamic_object_size(p, 0);
gi = __builtin_object_size(p, 0);
}