1 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu -Wincompatible-pointer-types
3 // Tests for the pass_object_size attribute
4 // Non-failure cases are covered in test/CodeGen/pass-object-size.c
6 void a(void *p
__attribute__((pass_object_size
))); //expected-error{{'pass_object_size' attribute takes one argument}}
7 void b(void *p
__attribute__((pass_object_size(1.0)))); //expected-error{{'pass_object_size' attribute requires parameter 1 to be an integer constant}}
9 void c(void *p
__attribute__((pass_object_size(4)))); //expected-error{{'pass_object_size' attribute requires integer constant between 0 and 3 inclusive}}
10 void d(void *p
__attribute__((pass_object_size(-1)))); //expected-error{{'pass_object_size' attribute requires integer constant between 0 and 3 inclusive}}
12 void e(void *p
__attribute__((pass_object_size(1ULL<<32)))); //expected-error{{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}}
14 void f(char p
__attribute__((pass_object_size(0)))); //expected-error{{'pass_object_size' attribute only applies to constant pointer arguments}}
15 void g(const char p
__attribute__((pass_object_size(0)))); //expected-error{{'pass_object_size' attribute only applies to constant pointer arguments}}
16 void h(char *p
__attribute__((pass_object_size(0)))) {} //expected-error{{pass_object_size attribute only applies to constant pointer arguments}}
17 void i(char *p
__attribute__((pass_object_size(0)))); // OK -- const is only necessary on definitions, not decls.
18 void j(char *p
__attribute__((pass_object_size(0), pass_object_size(1)))); //expected-error{{'pass_object_size' attribute can only be applied once per parameter}}
20 void k(char *p
__attribute__((pass_dynamic_object_size
))); // expected-error {{'pass_dynamic_object_size' attribute takes one argument}}
21 void l(int p
__attribute__((pass_dynamic_object_size(0)))); // expected-error {{'pass_dynamic_object_size' attribute only applies to constant pointer arguments}}
23 #define PS(N) __attribute__((pass_object_size(N)))
24 #define overloaded __attribute__((overloadable))
25 void Overloaded(void *p
PS(0)) overloaded
; //expected-note{{previous declaration is here}}
26 void Overloaded(void *p
PS(1)) overloaded
; //expected-error{{conflicting pass_object_size attributes on parameters}}
27 void Overloaded2(void *p
PS(1), void *p2
PS(0)) overloaded
; //expected-note{{previous declaration is here}}
28 void Overloaded2(void *p
PS(0), void *p2
PS(1)) overloaded
; //expected-error{{conflicting pass_object_size attributes on parameters}}
30 void Overloaded3(void *p
PS(0), void *p2
) overloaded
; //expected-note{{previous declaration is here}}
31 void Overloaded3(void *p
, void *p2
PS(0)) overloaded
; //expected-error{{conflicting pass_object_size attributes on parameters}}
33 void TakeFn(void (*)(void *));
34 void TakeFnOvl(void (*)(void *)) overloaded
;
35 void TakeFnOvl(void (*)(int *)) overloaded
;
37 void NotOverloaded(void *p
PS(0));
38 void IsOverloaded(void *p
PS(0)) overloaded
; // expected-note 2 {{candidate address cannot be taken because parameter 1 has pass_object_size attribute}}
40 // char* inestead of void* is intentional
41 void IsOverloaded(char *p
) overloaded
; // expected-note{{passing argument to parameter 'p' here}} expected-note 2 {{type mismatch}}
43 void FunctionPtrs(void) {
44 void (*p
)(void *) = NotOverloaded
; //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
45 void (*p2
)(void *) = &NotOverloaded
; //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
47 void (*p3
)(void *) = IsOverloaded
; //expected-error{{incompatible function pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}}
48 void (*p4
)(void *) = &IsOverloaded
; //expected-error{{incompatible function pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}}
50 void (*p5
)(char *) = IsOverloaded
;
51 void (*p6
)(char *) = &IsOverloaded
;
53 TakeFn(NotOverloaded
); //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
54 TakeFn(&NotOverloaded
); //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
56 TakeFnOvl(NotOverloaded
); //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
57 TakeFnOvl(&NotOverloaded
); //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
60 (&NotOverloaded
)(&P
); //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
61 (&IsOverloaded
)(&P
); //expected-warning{{incompatible pointer types passing 'int *' to parameter of type 'char *'}}
64 void mismatch(void *p
__attribute__((pass_object_size(0)))); // expected-note {{previous declaration is here}}
65 void mismatch(void *p
__attribute__((pass_dynamic_object_size(0)))); // expected-error {{conflicting pass_object_size attributes on parameters}}
67 void mismatch2(void *p
__attribute__((pass_dynamic_object_size(0)))); // expected-note {{previous declaration is here}}
68 void mismatch2(void *p
__attribute__((pass_dynamic_object_size(1)))); // expected-error {{conflicting pass_object_size attributes on parameters}}