Skip to content

Commit 44ca7d0

Browse files
committed
Use FunctionType::get to reduce duplication for creating _instname
variants
1 parent c639c69 commit 44ca7d0

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,15 @@ void MemorySanitizer::createKernelApi(Module &M, const TargetLibraryInfo &TLI) {
830830
VAArgOriginTLS = nullptr;
831831
VAArgOverflowSizeTLS = nullptr;
832832

833-
if (ClEmbedFaultingInst != MSanEmbedFaultingInstructionMode::None)
834-
WarningFn = M.getOrInsertFunction(
835-
"__msan_warning_instname", TLI.getAttrList(C, {0}, /*Signed=*/false),
836-
IRB.getVoidTy(), IRB.getInt32Ty(), IRB.getPtrTy());
837-
else
838-
WarningFn = M.getOrInsertFunction("__msan_warning",
839-
TLI.getAttrList(C, {0}, /*Signed=*/false),
840-
IRB.getVoidTy(), IRB.getInt32Ty());
833+
SmallVector<Type *, 4> ArgsTy = {IRB.getInt32Ty()};
834+
StringRef FnName = "__msan_warning";
835+
if (ClEmbedFaultingInst != MSanEmbedFaultingInstructionMode::None) {
836+
ArgsTy.push_back(IRB.getPtrTy());
837+
FnName = "__msan_warning_instname";
838+
}
839+
WarningFn = M.getOrInsertFunction(
840+
FnName, FunctionType::get(IRB.getVoidTy(), ArgsTy, false),
841+
TLI.getAttrList(C, {0}, /*Signed=*/false));
841842

842843
// Requests the per-task context state (kmsan_context_state*) from the
843844
// runtime library.
@@ -889,37 +890,32 @@ void MemorySanitizer::createUserspaceApi(Module &M,
889890
const TargetLibraryInfo &TLI) {
890891
IRBuilder<> IRB(*C);
891892

892-
Type *Int8Ptr = PointerType::getUnqual(*C);
893-
894893
// Create the callback.
895894
// FIXME: this function should have "Cold" calling conv,
896895
// which is not yet implemented.
897896
if (TrackOrigins) {
897+
SmallVector<Type *, 4> ArgsTy = {IRB.getInt32Ty()};
898+
StringRef WarningFnName = Recover ? "__msan_warning_with_origin"
899+
: "__msan_warning_with_origin_noreturn";
898900
if (ClEmbedFaultingInst != MSanEmbedFaultingInstructionMode::None) {
899-
StringRef WarningFnName =
900-
Recover ? "__msan_warning_with_origin_instname"
901-
: "__msan_warning_with_origin_noreturn_instname";
902-
WarningFn = M.getOrInsertFunction(
903-
WarningFnName, TLI.getAttrList(C, {0}, /*Signed=*/false),
904-
IRB.getVoidTy(), IRB.getInt32Ty(), Int8Ptr);
905-
} else {
906-
StringRef WarningFnName = Recover ? "__msan_warning_with_origin"
907-
: "__msan_warning_with_origin_noreturn";
908-
WarningFn = M.getOrInsertFunction(
909-
WarningFnName, TLI.getAttrList(C, {0}, /*Signed=*/false),
910-
IRB.getVoidTy(), IRB.getInt32Ty());
901+
ArgsTy.push_back(IRB.getPtrTy());
902+
WarningFnName = Recover ? "__msan_warning_with_origin_instname"
903+
: "__msan_warning_with_origin_noreturn_instname";
911904
}
905+
WarningFn = M.getOrInsertFunction(
906+
WarningFnName, FunctionType::get(IRB.getVoidTy(), ArgsTy, false),
907+
TLI.getAttrList(C, {0}, /*Signed=*/false));
912908
} else {
909+
SmallVector<Type *, 4> ArgsTy = {};
910+
StringRef WarningFnName =
911+
Recover ? "__msan_warning" : "__msan_warning_noreturn";
913912
if (ClEmbedFaultingInst != MSanEmbedFaultingInstructionMode::None) {
914-
StringRef WarningFnName = Recover ? "__msan_warning_instname"
915-
: "__msan_warning_noreturn_instname";
916-
WarningFn =
917-
M.getOrInsertFunction(WarningFnName, IRB.getVoidTy(), Int8Ptr);
918-
} else {
919-
StringRef WarningFnName =
920-
Recover ? "__msan_warning" : "__msan_warning_noreturn";
921-
WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy());
913+
ArgsTy.push_back(IRB.getPtrTy());
914+
WarningFnName = Recover ? "__msan_warning_instname"
915+
: "__msan_warning_noreturn_instname";
922916
}
917+
WarningFn = M.getOrInsertFunction(
918+
WarningFnName, FunctionType::get(IRB.getVoidTy(), ArgsTy, false));
923919
}
924920

925921
// Create the global TLS variables.

0 commit comments

Comments
 (0)