Skip to content

[Cygwin] va_list must be treated like normal Windows #143115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,10 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
if (Opts.CPlusPlus)
Builder.defineMacro("_GNU_SOURCE");
}

BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::CharPtrBuiltinVaList;
}
};

class LLVM_LIBRARY_VISIBILITY DarwinX86_64TargetInfo
Expand Down
35 changes: 35 additions & 0 deletions clang/test/CodeGen/X86/cygwin-varargs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm < %s | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-pc-cygwin -emit-llvm < %s | FileCheck %s

struct foo {
int x;
float y;
char z;
};
// CHECK: %[[STRUCT_FOO:.*]] = type { i32, float, i8 }

void f(int a, ...) {
// CHECK-LABEL: define dso_local void @f
__builtin_va_list ap;
__builtin_va_start(ap, a);
// CHECK: %[[AP:.*]] = alloca ptr
// CHECK: call void @llvm.va_start
int b = __builtin_va_arg(ap, int);
// CHECK: %[[AP_CUR:.*]] = load ptr, ptr %[[AP]]
// CHECK-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, ptr %[[AP_CUR]], i64 8
// CHECK-NEXT: store ptr %[[AP_NEXT]], ptr %[[AP]]
double _Complex c = __builtin_va_arg(ap, double _Complex);
// CHECK: %[[AP_CUR2:.*]] = load ptr, ptr %[[AP]]
// CHECK-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, ptr %[[AP_CUR2]], i64 8
// CHECK-NEXT: store ptr %[[AP_NEXT2]], ptr %[[AP]]
// CHECK-NEXT: load ptr, ptr %[[AP_CUR2]]
struct foo d = __builtin_va_arg(ap, struct foo);
// CHECK: %[[AP_CUR3:.*]] = load ptr, ptr %[[AP]]
// CHECK-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, ptr %[[AP_CUR3]], i64 8
// CHECK-NEXT: store ptr %[[AP_NEXT3]], ptr %[[AP]]
__builtin_va_list ap2;
__builtin_va_copy(ap2, ap);
// CHECK: call void @llvm.va_copy
__builtin_va_end(ap);
// CHECK: call void @llvm.va_end
}
Loading