Skip to content

Commit c64472a

Browse files
committed
[Cygwin] va_list must be treated like normal Windows
Handling of va_list on Cygwin environment must be matched to normal Windows environment. A new test file is added as existing test contains a unsupported functionality.
1 parent ac4893d commit c64472a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

clang/lib/Basic/Targets/X86.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,9 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
979979
if (Opts.CPlusPlus)
980980
Builder.defineMacro("_GNU_SOURCE");
981981
}
982+
BuiltinVaListKind getBuiltinVaListKind() const override {
983+
return TargetInfo::CharPtrBuiltinVaList;
984+
}
982985
};
983986

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

0 commit comments

Comments
 (0)