Skip to content

Instantly share code, notes, and snippets.

@pgavlin
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgavlin/cd9f77ff5115d3d60085 to your computer and use it in GitHub Desktop.
Save pgavlin/cd9f77ff5115d3d60085 to your computer and use it in GitHub Desktop.
LLILC patch to normalize bad X86-64 calling conventions
diff --git a/lib/Reader/abisignature.cpp b/lib/Reader/abisignature.cpp
index 140c248..55e8635 100644
--- a/lib/Reader/abisignature.cpp
+++ b/lib/Reader/abisignature.cpp
@@ -42,6 +42,21 @@ static CallingConv::ID getLLVMCallingConv(CorInfoCallConv CC) {
}
}
+static CorInfoCallConv
+getNormalizedCallingConvention(const ReaderCallSignature &Signature) {
+ // NOTE: this is only correct for X86-64
+
+ CorInfoCallConv CC = Signature.getCallingConvention();
+ switch (CC) {
+ case CORINFO_CALLCONV_STDCALL:
+ case CORINFO_CALLCONV_THISCALL:
+ case CORINFO_CALLCONV_FASTCALL:
+ return CORINFO_CALLCONV_C;
+ default:
+ return CC;
+ }
+}
+
ABISignature::ABISignature(const ReaderCallSignature &Signature, GenIR &Reader,
const ABIInfo &TheABIInfo) {
const CallArgType &ResultType = Signature.getResultType();
@@ -56,7 +71,8 @@ ABISignature::ABISignature(const ReaderCallSignature &Signature, GenIR &Reader,
LLVMArgTypes[I++] = Reader.getType(Arg.CorType, Arg.Class);
}
- CallingConv::ID CC = getLLVMCallingConv(Signature.getCallingConvention());
+ CallingConv::ID CC =
+ getLLVMCallingConv(getNormalizedCallingConvention(Signature));
TheABIInfo.computeSignatureInfo(CC, LLVMResultType, LLVMArgTypes, Result,
Args);
@@ -157,7 +173,7 @@ Value *ABICallSignature::emitCall(GenIR &Reader, llvm::Value *Target,
assert(Signature.getCallingConvention() == CORINFO_CALLCONV_DEFAULT);
CC = CallingConv::CLR_VirtualDispatchStub;
} else {
- CC = getLLVMCallingConv(Signature.getCallingConvention());
+ CC = getLLVMCallingConv(getNormalizedCallingConvention(Signature));
}
Call->setCallingConv(CC);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment