Skip to content

Commit 58a70df

Browse files
authored
[msan] Add debugging for handleUnknownIntrinsic (#123381)
This adds an experimental flag, msan-dump-strict-intrinsics (modeled after msan-dump-strict-instructions), which prints out any intrinsics that are heuristically handled. Additionally, MSan will print out heuristically handled intrinsics when -debug is passed as a flag in debug builds. MSan's intrinsic handling can be broken down into: 1) special cases (usually highly accurate) 2) heuristic handling (sometimes erroneous) 3) not handled This patch's -msan-dump-strict-intrinsics is intended to help debug Case 2. Case 3) (which includes all the heuristics that are not handled by special cases nor heuristics) can be debugged using the existing -msan-dump-strict-instructions.
1 parent bbd871e commit 58a70df

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ static cl::opt<bool> ClDumpStrictInstructions(
318318
cl::desc("print out instructions with default strict semantics"),
319319
cl::Hidden, cl::init(false));
320320

321+
static cl::opt<bool> ClDumpStrictIntrinsics(
322+
"msan-dump-strict-intrinsics",
323+
cl::desc("Prints 'unknown' intrinsics that were handled heuristically. "
324+
"Use -msan-dump-strict-instructions to print intrinsics that "
325+
"could not be handled exactly nor heuristically."),
326+
cl::Hidden, cl::init(false));
327+
321328
static cl::opt<int> ClInstrumentationWithCallThreshold(
322329
"msan-instrumentation-with-call-threshold",
323330
cl::desc(
@@ -3014,7 +3021,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
30143021
///
30153022
/// We special-case intrinsics where this approach fails. See llvm.bswap
30163023
/// handling as an example of that.
3017-
bool handleUnknownIntrinsic(IntrinsicInst &I) {
3024+
bool handleUnknownIntrinsicUnlogged(IntrinsicInst &I) {
30183025
unsigned NumArgOperands = I.arg_size();
30193026
if (NumArgOperands == 0)
30203027
return false;
@@ -3040,6 +3047,18 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
30403047
return false;
30413048
}
30423049

3050+
bool handleUnknownIntrinsic(IntrinsicInst &I) {
3051+
if (handleUnknownIntrinsicUnlogged(I)) {
3052+
if (ClDumpStrictIntrinsics)
3053+
dumpInst(I);
3054+
3055+
LLVM_DEBUG(dbgs() << "UNKNOWN INTRINSIC HANDLED HEURISTICALLY: " << I
3056+
<< "\n");
3057+
return true;
3058+
} else
3059+
return false;
3060+
}
3061+
30433062
void handleInvariantGroup(IntrinsicInst &I) {
30443063
setShadow(&I, getShadow(&I, 0));
30453064
setOrigin(&I, getOrigin(&I, 0));

0 commit comments

Comments
 (0)