[PATCH] D103837: [clang] Apply MS ABI details on __builtin_ms_va_list on non-windows platforms on x86_64
Martin Storsjö via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 7 12:50:43 PDT 2021
mstorsjo created this revision.
mstorsjo added a reviewer: rnk.
Herald added a subscriber: pengfei.
mstorsjo requested review of this revision.
Herald added a project: clang.
This fixes inconsistencies in the ms_abi.c testcase.
Also add a couple cases of missing double pointers in the windows part
of the testcase; the outcome of building that testcase on windows hasn't
changed, but the previous form of the test was imprecise (checking
for "%[[STRUCT_FOO]]*" when clang actually generates "%[[STRUCT_FOO]]**"),
which still used to match.
Ideally this would share code with the native Windows case, but
X86_64ABIInfo and WinX86_64ABIInfo aren't superclasses/subclasses of
each other so it's impractical, and the code to share currently only
consists of a couple lines.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103837
Files:
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/ms_abi.c
Index: clang/test/CodeGen/ms_abi.c
===================================================================
--- clang/test/CodeGen/ms_abi.c
+++ clang/test/CodeGen/ms_abi.c
@@ -45,12 +45,12 @@
// WIN64-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
// WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
- // FIXME: These are different now. We probably need __builtin_ms_va_arg.
double _Complex c = __builtin_va_arg(ap, double _Complex);
// FREEBSD: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
- // FREEBSD-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 16
+ // FREEBSD-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
// FREEBSD-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
- // FREEBSD-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
+ // FREEBSD-NEXT: %[[CUR2:.*]] = bitcast i8* %[[AP_CUR2]] to { double, double }**
+ // FREEBSD-NEXT: load { double, double }*, { double, double }** %[[CUR2]]
// WIN64: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
@@ -58,9 +58,10 @@
// WIN64-NEXT: load { double, double }*, { double, double }** %[[CUR2]]
struct foo d = __builtin_va_arg(ap, struct foo);
// FREEBSD: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
- // FREEBSD-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 16
+ // FREEBSD-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
// FREEBSD-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
- // FREEBSD-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
+ // FREEBSD-NEXT: %[[CUR3:.*]] = bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
+ // FREEBSD-NEXT: load %[[STRUCT_FOO]]*, %[[STRUCT_FOO]]** %[[CUR3]]
// WIN64: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
@@ -123,22 +124,22 @@
// WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
double _Complex c = __builtin_va_arg(ap, double _Complex);
// FREEBSD: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
- // FREEBSD-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 16
+ // FREEBSD-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
// FREEBSD-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
- // FREEBSD-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
+ // FREEBSD-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }**
// WIN64: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
- // WIN64-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
+ // WIN64-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }**
struct foo d = __builtin_va_arg(ap, struct foo);
// FREEBSD: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
- // FREEBSD-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 16
+ // FREEBSD-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
// FREEBSD-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
- // FREEBSD-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
+ // FREEBSD-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]**
// WIN64: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
- // WIN64-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
+ // WIN64-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]**
__builtin_ms_va_list ap2;
__builtin_ms_va_copy(ap2, ap);
// FREEBSD: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4161,7 +4161,12 @@
Address X86_64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
QualType Ty) const {
- return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*indirect*/ false,
+ // MS x64 ABI requirement: "Any argument that doesn't fit in 8 bytes, or is
+ // not 1, 2, 4, or 8 bytes, must be passed by reference."
+ uint64_t Width = getContext().getTypeSize(Ty);
+ bool IsIndirect = Width > 64 || !llvm::isPowerOf2_64(Width);
+
+ return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect,
CGF.getContext().getTypeInfoInChars(Ty),
CharUnits::fromQuantity(8),
/*allowHigherAlign*/ false);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103837.350393.patch
Type: text/x-patch
Size: 4816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210607/4ebcb086/attachment-0001.bin>
More information about the cfe-commits
mailing list