Skip to content

Commit cdf5671

Browse files
committed
More simplification with FunctionType::get
1 parent 44ca7d0 commit cdf5671

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -947,19 +947,16 @@ void MemorySanitizer::createUserspaceApi(Module &M,
947947
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
948948
AccessSizeIndex++) {
949949
unsigned AccessSize = 1 << AccessSizeIndex;
950-
std::string FunctionName;
950+
std::string FunctionName = "__msan_maybe_warning_" + itostr(AccessSize);
951+
SmallVector<Type *, 4> ArgsTy = {IRB.getIntNTy(AccessSize * 8),
952+
IRB.getInt32Ty()};
951953
if (ClEmbedFaultingInst != MSanEmbedFaultingInstructionMode::None) {
952954
FunctionName = "__msan_maybe_warning_instname_" + itostr(AccessSize);
953-
MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction(
954-
FunctionName, TLI.getAttrList(C, {0, 1}, /*Signed=*/false),
955-
IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), IRB.getInt32Ty(),
956-
IRB.getPtrTy());
957-
} else {
958-
FunctionName = "__msan_maybe_warning_" + itostr(AccessSize);
959-
MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction(
960-
FunctionName, TLI.getAttrList(C, {0, 1}, /*Signed=*/false),
961-
IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), IRB.getInt32Ty());
955+
ArgsTy.push_back(IRB.getPtrTy());
962956
}
957+
MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction(
958+
FunctionName, FunctionType::get(IRB.getVoidTy(), ArgsTy, false),
959+
TLI.getAttrList(C, {0, 1}, /*Signed=*/false));
963960

964961
FunctionName = "__msan_maybe_store_origin_" + itostr(AccessSize);
965962
MaybeStoreOriginFn[AccessSizeIndex] = M.getOrInsertFunction(
@@ -1452,17 +1449,13 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
14521449
}
14531450
}
14541451

1455-
if (ClEmbedFaultingInst != MSanEmbedFaultingInstructionMode::None) {
1456-
if (MS.CompileKernel || MS.TrackOrigins)
1457-
IRB.CreateCall(MS.WarningFn, {Origin, InstName})->setCannotMerge();
1458-
else
1459-
IRB.CreateCall(MS.WarningFn, {InstName})->setCannotMerge();
1460-
} else {
1461-
if (MS.CompileKernel || MS.TrackOrigins)
1462-
IRB.CreateCall(MS.WarningFn, Origin)->setCannotMerge();
1463-
else
1464-
IRB.CreateCall(MS.WarningFn)->setCannotMerge();
1465-
}
1452+
SmallVector<Value *, 4> Args;
1453+
if (MS.CompileKernel || MS.TrackOrigins)
1454+
Args.push_back(Origin);
1455+
if (ClEmbedFaultingInst != MSanEmbedFaultingInstructionMode::None)
1456+
Args.push_back(InstName);
1457+
IRB.CreateCall(MS.WarningFn, Args)->setCannotMerge();
1458+
14661459
// FIXME: Insert UnreachableInst if !MS.Recover?
14671460
// This may invalidate some of the following checks and needs to be done
14681461
// at the very end.
@@ -1480,17 +1473,14 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
14801473
ConvertedShadow = convertShadowToScalar(ConvertedShadow, IRB);
14811474
Value *ConvertedShadow2 =
14821475
IRB.CreateZExt(ConvertedShadow, IRB.getIntNTy(8 * (1 << SizeIndex)));
1483-
CallBase *CB;
1476+
1477+
SmallVector<Value *, 4> Args = {
1478+
ConvertedShadow2,
1479+
MS.TrackOrigins && Origin ? Origin : (Value *)IRB.getInt32(0)};
14841480
if (ClEmbedFaultingInst != MSanEmbedFaultingInstructionMode::None)
1485-
CB = IRB.CreateCall(
1486-
Fn, {ConvertedShadow2,
1487-
MS.TrackOrigins && Origin ? Origin : (Value *)IRB.getInt32(0),
1488-
InstName});
1489-
else
1490-
CB = IRB.CreateCall(Fn,
1491-
{ConvertedShadow2, MS.TrackOrigins && Origin
1492-
? Origin
1493-
: (Value *)IRB.getInt32(0)});
1481+
Args.push_back(InstName);
1482+
1483+
CallBase *CB = IRB.CreateCall(Fn, Args);
14941484

14951485
CB->addParamAttr(0, Attribute::ZExt);
14961486
CB->addParamAttr(1, Attribute::ZExt);

0 commit comments

Comments
 (0)