Skip to content

Commit 17e8777

Browse files
kikairoyajeremyd2019
authored andcommitted
[Clang] [Cygwin] va_list must be treated like normal Windows (llvm#143115)
Handling of va_list on Cygwin environment must be matched to normal Windows environment. The existing test `test/CodeGen/ms_abi.c` seems relevant, but it contains `__attribute__((sysv_abi))`, which is not supported on Cygwin. The new test is based on the `__attribute__((ms_abi))` portion of that test. --------- Co-authored-by: jeremyd2019 <[email protected]>
1 parent beb3381 commit 17e8777

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

clang/lib/Basic/Targets/X86.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,10 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
997997
if (Opts.CPlusPlus)
998998
Builder.defineMacro("_GNU_SOURCE");
999999
}
1000+
1001+
BuiltinVaListKind getBuiltinVaListKind() const override {
1002+
return TargetInfo::CharPtrBuiltinVaList;
1003+
}
10001004
};
10011005

10021006
class LLVM_LIBRARY_VISIBILITY DarwinX86_64TargetInfo
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm < %s | FileCheck %s
2+
// RUN: %clang_cc1 -triple x86_64-pc-cygwin -emit-llvm < %s | FileCheck %s
3+
4+
struct foo {
5+
int x;
6+
float y;
7+
char z;
8+
};
9+
// CHECK: %[[STRUCT_FOO:.*]] = type { i32, float, i8 }
10+
11+
void f(int a, ...) {
12+
// CHECK-LABEL: define dso_local void @f
13+
__builtin_va_list ap;
14+
__builtin_va_start(ap, a);
15+
// CHECK: %[[AP:.*]] = alloca ptr
16+
// CHECK: call void @llvm.va_start
17+
int b = __builtin_va_arg(ap, int);
18+
// CHECK: %[[AP_CUR:.*]] = load ptr, ptr %[[AP]]
19+
// CHECK-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, ptr %[[AP_CUR]], i64 8
20+
// CHECK-NEXT: store ptr %[[AP_NEXT]], ptr %[[AP]]
21+
double _Complex c = __builtin_va_arg(ap, double _Complex);
22+
// CHECK: %[[AP_CUR2:.*]] = load ptr, ptr %[[AP]]
23+
// CHECK-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, ptr %[[AP_CUR2]], i64 8
24+
// CHECK-NEXT: store ptr %[[AP_NEXT2]], ptr %[[AP]]
25+
// CHECK-NEXT: load ptr, ptr %[[AP_CUR2]]
26+
struct foo d = __builtin_va_arg(ap, struct foo);
27+
// CHECK: %[[AP_CUR3:.*]] = load ptr, ptr %[[AP]]
28+
// CHECK-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, ptr %[[AP_CUR3]], i64 8
29+
// CHECK-NEXT: store ptr %[[AP_NEXT3]], ptr %[[AP]]
30+
__builtin_va_list ap2;
31+
__builtin_va_copy(ap2, ap);
32+
// CHECK: call void @llvm.va_copy
33+
__builtin_va_end(ap);
34+
// CHECK: call void @llvm.va_end
35+
}

0 commit comments

Comments
 (0)