Skip to content

Commit 93eba6d

Browse files
committed
Fix builtinvalistkind
1 parent afdf295 commit 93eba6d

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

clang/lib/Basic/Targets/X86.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,10 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
857857
"i64:64-i128:128-f80:128-n8:16:32:64-S128");
858858
}
859859

860+
BuiltinVaListKind getBuiltinVaListKind() const override {
861+
return TargetInfo::CharPtrBuiltinVaList;
862+
}
863+
860864
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
861865
switch (CC) {
862866
case CC_C:

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,8 +3038,30 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction &CGF,
30383038
return Address(Res, LTy, Align);
30393039
}
30403040

3041+
static RValue EmitMSABIVAArg(CodeGenFunction &CGF, Address VAListAddr,
3042+
QualType Ty, AggValueSlot Slot,
3043+
ASTContext &context) {
3044+
// MS x64 ABI requirement: "Any argument that doesn't fit in 8 bytes, or is
3045+
// not 1, 2, 4, or 8 bytes, must be passed by reference."
3046+
uint64_t Width = context.getTypeSize(Ty);
3047+
bool IsIndirect = Width > 64 || !llvm::isPowerOf2_64(Width);
3048+
3049+
return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect,
3050+
CGF.getContext().getTypeInfoInChars(Ty),
3051+
CharUnits::fromQuantity(8),
3052+
/*allowHigherAlign*/ false, Slot);
3053+
}
3054+
30413055
RValue X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
30423056
QualType Ty, AggValueSlot Slot) const {
3057+
3058+
// Emit MS ABI compliant va_list for X86_64 targets which use Microsoft CXX
3059+
// ABI and CharPtrBuiltinVaList.
3060+
if (CGF.getTarget().getCXXABI().isMicrosoft() &&
3061+
CGF.getTarget().getBuiltinVaListKind() ==
3062+
clang::TargetInfo::CharPtrBuiltinVaList)
3063+
return EmitMSABIVAArg(CGF, VAListAddr, Ty, Slot, getContext());
3064+
30433065
// Assume that va_list type is correct; should be pointer to LLVM type:
30443066
// struct {
30453067
// i32 gp_offset;
@@ -3486,15 +3508,7 @@ void WinX86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
34863508

34873509
RValue WinX86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
34883510
QualType Ty, AggValueSlot Slot) const {
3489-
// MS x64 ABI requirement: "Any argument that doesn't fit in 8 bytes, or is
3490-
// not 1, 2, 4, or 8 bytes, must be passed by reference."
3491-
uint64_t Width = getContext().getTypeSize(Ty);
3492-
bool IsIndirect = Width > 64 || !llvm::isPowerOf2_64(Width);
3493-
3494-
return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect,
3495-
CGF.getContext().getTypeInfoInChars(Ty),
3496-
CharUnits::fromQuantity(8),
3497-
/*allowHigherAlign*/ false, Slot);
3511+
return EmitMSABIVAArg(CGF, VAListAddr, Ty, Slot, getContext());
34983512
}
34993513

35003514
std::unique_ptr<TargetCodeGenInfo> CodeGen::createX86_32TargetCodeGenInfo(

0 commit comments

Comments
 (0)