xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/callingconv.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -triple i386-unknown-unknown -verify
2f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -triple i386-unknown-unknown -fms-compatibility -DWIN -verify
3f4a2713aSLionel Sambuc 
foo(float * a)4f4a2713aSLionel Sambuc void __attribute__((fastcall)) foo(float *a) {
5f4a2713aSLionel Sambuc }
6f4a2713aSLionel Sambuc 
bar(float * a)7f4a2713aSLionel Sambuc void __attribute__((stdcall)) bar(float *a) {
8f4a2713aSLionel Sambuc }
9f4a2713aSLionel Sambuc 
baz(float * a)10f4a2713aSLionel Sambuc void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{'fastcall' attribute takes no arguments}}
11f4a2713aSLionel Sambuc }
12f4a2713aSLionel Sambuc 
test0()13*0a6a1f1dSLionel Sambuc void __attribute__((fastcall)) test0() {
14f4a2713aSLionel Sambuc }
15f4a2713aSLionel Sambuc 
test1(void)16f4a2713aSLionel Sambuc void __attribute__((fastcall)) test1(void) {
17f4a2713aSLionel Sambuc }
18f4a2713aSLionel Sambuc 
test2(int a,...)19f4a2713aSLionel Sambuc void __attribute__((fastcall)) test2(int a, ...) { // expected-warning {{fastcall calling convention ignored on variadic function}}
20f4a2713aSLionel Sambuc }
test3(int a,...)21f4a2713aSLionel Sambuc void __attribute__((stdcall)) test3(int a, ...) { // expected-warning {{stdcall calling convention ignored on variadic function}}
22f4a2713aSLionel Sambuc }
test4(int a,...)23f4a2713aSLionel Sambuc void __attribute__((thiscall)) test4(int a, ...) { // expected-error {{variadic function cannot use thiscall calling convention}}
24f4a2713aSLionel Sambuc }
25f4a2713aSLionel Sambuc 
ctest0()26f4a2713aSLionel Sambuc void __attribute__((cdecl)) ctest0() {}
27f4a2713aSLionel Sambuc 
ctest1(float x)28f4a2713aSLionel Sambuc void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{'cdecl' attribute takes no arguments}}
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc void (__attribute__((fastcall)) *pfoo)(float*) = foo;
31f4a2713aSLionel Sambuc 
32f4a2713aSLionel Sambuc void (__attribute__((stdcall)) *pbar)(float*) = bar;
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc void (__attribute__((cdecl)) *ptest1)(void) = test1; // expected-warning {{incompatible pointer types}}
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc void (*pctest0)() = ctest0;
37f4a2713aSLionel Sambuc 
ctest2()38f4a2713aSLionel Sambuc void ctest2() {}
39f4a2713aSLionel Sambuc void (__attribute__((cdecl)) *pctest2)() = ctest2;
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc typedef void (__attribute__((fastcall)) *Handler) (float *);
42f4a2713aSLionel Sambuc Handler H = foo;
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc int __attribute__((pcs("aapcs", "aapcs"))) pcs1(void); // expected-error {{'pcs' attribute takes one argument}}
45f4a2713aSLionel Sambuc int __attribute__((pcs())) pcs2(void); // expected-error {{'pcs' attribute takes one argument}}
46f4a2713aSLionel Sambuc int __attribute__((pcs(pcs1))) pcs3(void); // expected-error {{'pcs' attribute requires a string}} \
47f4a2713aSLionel Sambuc                                            // expected-error {{invalid PCS type}}
48f4a2713aSLionel Sambuc int __attribute__((pcs(0))) pcs4(void); // expected-error {{'pcs' attribute requires a string}}
49f4a2713aSLionel Sambuc /* These are ignored because the target is i386 and not ARM */
50f4a2713aSLionel Sambuc int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{calling convention 'pcs' ignored for this target}}
51f4a2713aSLionel Sambuc int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{calling convention 'pcs' ignored for this target}}
52f4a2713aSLionel Sambuc int __attribute__((pcs("foo"))) pcs7(void); // expected-error {{invalid PCS type}}
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc // PR6361
55f4a2713aSLionel Sambuc void ctest3();
ctest3()56f4a2713aSLionel Sambuc void __attribute__((cdecl)) ctest3() {}
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc // PR6408
59f4a2713aSLionel Sambuc typedef __attribute__((stdcall)) void (*PROC)();
ctest4(const char * x)60f4a2713aSLionel Sambuc PROC __attribute__((cdecl)) ctest4(const char *x) {}
61f4a2713aSLionel Sambuc 
pnaclfunc(float * a)62f4a2713aSLionel Sambuc void __attribute__((pnaclcall)) pnaclfunc(float *a) {} // expected-warning {{calling convention 'pnaclcall' ignored for this target}}
63f4a2713aSLionel Sambuc 
inteloclbifunc(float * a)64f4a2713aSLionel Sambuc void __attribute__((intel_ocl_bicc)) inteloclbifunc(float *a) {}
65f4a2713aSLionel Sambuc 
66f4a2713aSLionel Sambuc typedef void typedef_fun_t(int);
67f4a2713aSLionel Sambuc typedef_fun_t typedef_fun; // expected-note {{previous declaration is here}}
typedef_fun(int x)68f4a2713aSLionel Sambuc void __attribute__((stdcall)) typedef_fun(int x) { } // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
69*0a6a1f1dSLionel Sambuc 
70*0a6a1f1dSLionel Sambuc struct type_test {} __attribute__((stdcall));  // expected-warning {{'stdcall' attribute only applies to functions and methods}}
71