Skip to content

Commit b01cdde

Browse files
[Clang][Cygwin] Cygwin x86_64 should accept __stdcall (#158385)
Cygwin should support calling convention attributes `__cdecl`, `__stdcall`, `__thiscall`, and `__fastcall`, even though they have no effect in x86_64, as done in MinGW. Originally reported in https://cygwin.com/pipermail/cygwin/2025-September/258782.html --------- Co-authored-by: Jeremy Drake <[email protected]>
1 parent d7bf2bf commit b01cdde

File tree

8 files changed

+41
-39
lines changed

8 files changed

+41
-39
lines changed

clang/lib/Basic/Targets/X86.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,29 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
999999
Builder.defineMacro("_GNU_SOURCE");
10001000
}
10011001

1002+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
1003+
switch (CC) {
1004+
case CC_X86StdCall:
1005+
case CC_X86ThisCall:
1006+
case CC_X86FastCall:
1007+
return CCCR_Ignore;
1008+
case CC_C:
1009+
case CC_X86VectorCall:
1010+
case CC_IntelOclBicc:
1011+
case CC_PreserveMost:
1012+
case CC_PreserveAll:
1013+
case CC_PreserveNone:
1014+
case CC_X86_64SysV:
1015+
case CC_Swift:
1016+
case CC_SwiftAsync:
1017+
case CC_X86RegCall:
1018+
case CC_DeviceKernel:
1019+
return CCCR_OK;
1020+
default:
1021+
return CCCR_Warning;
1022+
}
1023+
}
1024+
10021025
BuiltinVaListKind getBuiltinVaListKind() const override {
10031026
return TargetInfo::CharPtrBuiltinVaList;
10041027
}

clang/test/CodeGen/X86/cygwin-varargs.c

Lines changed: 0 additions & 35 deletions
This file was deleted.

clang/test/CodeGen/calling-conv-ignored.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -o - %s | FileCheck %s --check-prefix=X86
22
// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -o - %s | FileCheck %s --check-prefix=X64
3+
// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=X64
4+
// RUN: %clang_cc1 -triple x86_64-cygwin -emit-llvm -o - %s | FileCheck %s --check-prefix=X64
35
// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -o - %s -fdefault-calling-conv=vectorcall | FileCheck %s --check-prefix=X86-VEC
46
// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -o - %s -fdefault-calling-conv=vectorcall | FileCheck %s --check-prefix=X64-VEC
57

clang/test/CodeGen/ms_abi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-freebsd10.0 -emit-llvm < %s | FileCheck -check-prefix=FREEBSD %s
22
// RUN: %clang_cc1 -triple x86_64-pc-win32 -emit-llvm < %s | FileCheck -check-prefix=WIN64 %s
3+
// RUN: %clang_cc1 -triple x86_64-mingw -emit-llvm < %s | FileCheck -check-prefix=WIN64 %s
4+
// RUN: %clang_cc1 -triple x86_64-cygwin -emit-llvm < %s | FileCheck -check-prefix=WIN64 %s
35
// RUN: %clang_cc1 -triple x86_64-uefi -emit-llvm < %s | FileCheck -check-prefix=WIN64 %s
46

57
struct foo {

clang/test/CodeGen/sysv_abi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// RUN: %clang_cc1 -triple x86_64-pc-win32 -emit-llvm -target-cpu skylake-avx512 < %s | FileCheck %s --check-prefixes=CHECK,AVX
2+
// RUN: %clang_cc1 -triple x86_64-mingw -emit-llvm -target-cpu skylake-avx512 < %s | FileCheck %s --check-prefixes=CHECK,AVX
3+
// RUN: %clang_cc1 -triple x86_64-cygwin -emit-llvm -target-cpu skylake-avx512 < %s | FileCheck %s --check-prefixes=CHECK,AVX
24
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -target-cpu skylake-avx512 < %s | FileCheck %s --check-prefixes=CHECK,AVX
35
// RUN: %clang_cc1 -triple x86_64-uefi -emit-llvm -target-cpu skylake-avx512 < %s | FileCheck %s --check-prefixes=CHECK,AVX
46
// RUN: %clang_cc1 -triple x86_64-pc-win32 -emit-llvm < %s | FileCheck %s --check-prefixes=CHECK,NOAVX
7+
// RUN: %clang_cc1 -triple x86_64-mingw -emit-llvm < %s | FileCheck %s --check-prefixes=CHECK,NOAVX
8+
// RUN: %clang_cc1 -triple x86_64-cygwin -emit-llvm < %s | FileCheck %s --check-prefixes=CHECK,NOAVX
59
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm < %s | FileCheck %s --check-prefixes=CHECK,NOAVX
610
// RUN: %clang_cc1 -triple x86_64-uefi -emit-llvm < %s | FileCheck %s --check-prefixes=CHECK,NOAVX
711

clang/test/DebugInfo/Generic/cc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -o - -emit-llvm -debug-info-kind=limited %s | FileCheck %s --check-prefix=LINUX
2-
// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -o - -emit-llvm -debug-info-kind=limited %s | FileCheck %s --check-prefix=WINDOWS
2+
// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -o - -emit-llvm -debug-info-kind=limited %s | FileCheck %s --check-prefix=WINDOWS
3+
// RUN: %clang_cc1 -triple x86_64-unknown-windows-gnu -o - -emit-llvm -debug-info-kind=limited %s | FileCheck %s --check-prefix=WINDOWS
4+
// RUN: %clang_cc1 -triple x86_64-unknown-windows-cygnus -o - -emit-llvm -debug-info-kind=limited %s | FileCheck %s --check-prefix=WINDOWS
35
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -o - -emit-llvm -debug-info-kind=limited %s | FileCheck %s --check-prefix=LINUX32
46
// RUN: %clang_cc1 -triple armv7--linux-gnueabihf -o - -emit-llvm -debug-info-kind=limited %s | FileCheck %s --check-prefix=ARM
57

@@ -77,7 +79,7 @@ __attribute__((intel_ocl_bicc)) int add_inteloclbicc(int a, int b) {
7779
}
7880
#endif
7981

80-
#ifdef _WIN64
82+
#if defined(_WIN64) || defined(__CYGWIN__)
8183
// WINDOWS: !DISubprogram({{.*}}"add_sysvabi", {{.*}}type: ![[FTY:[0-9]+]]
8284
// WINDOWS: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_X86_64SysV,
8385
__attribute__((sysv_abi)) int add_sysvabi(int a, int b) {

clang/test/Parser/x64-windows-calling-convention-handling.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %clang_cc1 -triple x86_64-windows -fms-compatibility -fsyntax-only -verify %s
1+
// RUN: %clang_cc1 -triple x86_64-windows -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -triple x86_64-mingw -fsyntax-only -verify %s
3+
// RUN: %clang_cc1 -triple x86_64-cygwin -fsyntax-only -verify %s
24

35
int __cdecl cdecl(int a, int b, int c, int d) { // expected-no-diagnostics
46
return a + b + c + d;

clang/test/Sema/MicrosoftCompatibility-x64.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %clang_cc1 %s -Wmicrosoft -verify -fms-compatibility -triple x86_64-pc-win32
1+
// RUN: %clang_cc1 %s -Wmicrosoft -verify -triple x86_64-pc-win32
2+
// RUN: %clang_cc1 %s -Wmicrosoft -verify -triple x86_64-w64-mingw32
3+
// RUN: %clang_cc1 %s -Wmicrosoft -verify -triple x86_64-pc-cygwin
24

35
// None of these should warn. stdcall is treated as equivalent to cdecl on
46
// x64.

0 commit comments

Comments
 (0)