[llvm] [msan] Generalize handleIntrinsicByApplyingToShadow by adding bitcasting (PR #123474)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 18 12:06:10 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Thurston Dang (thurstond)
<details>
<summary>Changes</summary>
handleIntrinsicByApplyingToShadow (introduced in
https://github.com/llvm/llvm-project/pull/114490) requires that the intrinsic supports integer-ish operands; this is not the case for all intrinsics. This patch generalizes the function to bitcast the shadow arguments to be the same type as the original intrinsic, thus guaranteeing that the intrinsic exists. Additionally, it casts the computed shadow to be an appropriate shadow type.
This function assumes that the intrinsic will handle arbitrary bit-patterns (for example, if the intrinsic only accepts floats for var1, we require that it doesn't care if inputs are NaNs).
---
Full diff: https://github.com/llvm/llvm-project/pull/123474.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+10-2)
``````````diff
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 6daee7a3b6e815..7b5a3fa4066a70 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -4008,6 +4008,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
/// shadow[out] =
/// intrinsic(shadow[var1], shadow[var2], opType) | shadow[opType]
///
+ /// CAUTION: this assumes that the intrinsic will handle arbitrary
+ /// bit-patterns (for example, if the intrinsic only accepts floats
+ /// for var1, we require that it doesn't care if inputs are NaNs).
+ ///
/// For example, this can be applied to the Arm NEON vector table intrinsics
/// (tbl{1,2,3,4}).
///
@@ -4022,7 +4026,11 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
// Don't use getNumOperands() because it includes the callee
for (unsigned int i = 0; i < I.arg_size() - trailingVerbatimArgs; i++) {
Value *Shadow = getShadow(&I, i);
- ShadowArgs.push_back(Shadow);
+
+ // Shadows are integer-ish types but some intrinsics require a
+ // different (e.g., floating-point) type.
+ ShadowArgs.push_back(
+ IRB.CreateBitCast(Shadow, I.getArgOperand(i)->getType()));
}
for (unsigned int i = I.arg_size() - trailingVerbatimArgs; i < I.arg_size();
@@ -4043,7 +4051,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
CombinedShadow = IRB.CreateOr(Shadow, CombinedShadow, "_msprop");
}
- setShadow(&I, CombinedShadow);
+ setShadow(&I, IRB.CreateBitCast(CombinedShadow, getShadowTy(&I)));
setOriginForNaryOp(I);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/123474
More information about the llvm-commits
mailing list