callingconv.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. void __attribute__((fastcall)) foo(float *a) {
  4. }
  5. void __attribute__((stdcall)) bar(float *a) {
  6. }
  7. void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{'fastcall' attribute takes no arguments}}
  8. }
  9. void __attribute__((fastcall)) test0() {
  10. }
  11. void __attribute__((fastcall)) test1(void) {
  12. }
  13. void __attribute__((fastcall)) test2(int a, ...) { // expected-warning {{fastcall calling convention ignored on variadic function}}
  14. }
  15. void __attribute__((stdcall)) test3(int a, ...) { // expected-warning {{stdcall calling convention ignored on variadic function}}
  16. }
  17. void __attribute__((thiscall)) test4(int a, ...) { // expected-error {{variadic function cannot use thiscall calling convention}}
  18. }
  19. void __attribute__((cdecl)) ctest0() {}
  20. void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{'cdecl' attribute takes no arguments}}
  21. void (__attribute__((fastcall)) *pfoo)(float*) = foo;
  22. void (__attribute__((stdcall)) *pbar)(float*) = bar;
  23. void (__attribute__((cdecl)) *ptest1)(void) = test1; // expected-warning {{incompatible pointer types}}
  24. void (*pctest0)() = ctest0;
  25. void ctest2() {}
  26. void (__attribute__((cdecl)) *pctest2)() = ctest2;
  27. typedef void (__attribute__((fastcall)) *Handler) (float *);
  28. Handler H = foo;
  29. int __attribute__((pcs("aapcs", "aapcs"))) pcs1(void); // expected-error {{'pcs' attribute takes one argument}}
  30. int __attribute__((pcs())) pcs2(void); // expected-error {{'pcs' attribute takes one argument}}
  31. int __attribute__((pcs(pcs1))) pcs3(void); // expected-error {{'pcs' attribute requires a string}} \
  32. // expected-error {{invalid PCS type}}
  33. int __attribute__((pcs(0))) pcs4(void); // expected-error {{'pcs' attribute requires a string}}
  34. /* These are ignored because the target is i386 and not ARM */
  35. int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{calling convention 'pcs' ignored for this target}}
  36. int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{calling convention 'pcs' ignored for this target}}
  37. int __attribute__((pcs("foo"))) pcs7(void); // expected-error {{invalid PCS type}}
  38. // PR6361
  39. void ctest3();
  40. void __attribute__((cdecl)) ctest3() {}
  41. // PR6408
  42. typedef __attribute__((stdcall)) void (*PROC)();
  43. PROC __attribute__((cdecl)) ctest4(const char *x) {}
  44. void __attribute__((intel_ocl_bicc)) inteloclbifunc(float *a) {}
  45. typedef void typedef_fun_t(int);
  46. typedef_fun_t typedef_fun; // expected-note {{previous declaration is here}}
  47. void __attribute__((stdcall)) typedef_fun(int x) { } // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
  48. struct type_test {} __attribute__((stdcall)); // expected-warning {{'stdcall' attribute only applies to functions and methods}}