Skip to content

Commit 7f302b7

Browse files
committed
Don't compute the shadow of the trailing argument to TBL/TBX
1 parent e39097a commit 7f302b7

File tree

2 files changed

+197
-42
lines changed

2 files changed

+197
-42
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,19 +3944,33 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
39443944
}
39453945
}
39463946

3947-
/// Handle intrinsics by applying the intrinsic to the shadows.
3948-
/// The origin is approximated using setOriginForNaryOp.
3947+
/// Handle intrinsics by applying the intrinsic to the shadows. The trailing
3948+
/// arguments are passed verbatim e.g., for an intrinsic with one trailing
3949+
/// verbatim argument:
3950+
/// out = intrinsic(var1, var2, opType)
3951+
/// we compute:
3952+
/// shadow[out] = intrinsic(shadow[var1], shadow[var2], opType)
39493953
///
39503954
/// For example, this can be applied to the Arm NEON vector table intrinsics
39513955
/// (tbl{1,2,3,4}).
3952-
void handleIntrinsicByApplyingToShadow(IntrinsicInst &I) {
3956+
///
3957+
/// The origin is approximated using setOriginForNaryOp.
3958+
void handleIntrinsicByApplyingToShadow(IntrinsicInst &I, unsigned int trailingVerbatimArgs) {
39533959
IRBuilder<> IRB(&I);
39543960

3961+
assert (trailingVerbatimArgs < I.arg_size());
3962+
39553963
SmallVector<Value *, 8> ShadowArgs;
39563964
// Don't use getNumOperands() because it includes the callee
39573965
for (unsigned int i = 0; i < I.arg_size(); i++) {
3958-
Value *Shadow = getShadow(&I, i);
3959-
ShadowArgs.append(1, Shadow);
3966+
if (i < I.arg_size() - trailingVerbatimArgs) {
3967+
Value *Shadow = getShadow(&I, i);
3968+
ShadowArgs.append(1, Shadow);
3969+
} else {
3970+
Value *Arg = I.getArgOperand(i);
3971+
insertShadowCheck(Arg, &I);
3972+
ShadowArgs.append(1, Arg);
3973+
}
39603974
}
39613975

39623976
CallInst *CI =
@@ -4358,7 +4372,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
43584372
case Intrinsic::aarch64_neon_tbx2:
43594373
case Intrinsic::aarch64_neon_tbx3:
43604374
case Intrinsic::aarch64_neon_tbx4: {
4361-
handleIntrinsicByApplyingToShadow(I);
4375+
// The last trailing argument (index register) should be handled verbatim
4376+
handleIntrinsicByApplyingToShadow(I, 1);
43624377
break;
43634378
}
43644379

0 commit comments

Comments
 (0)