Clang Project

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