[PATCH] D44513: [MSan] Introduce insertWarningFn(). NFC

Alexander Potapenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 15 04:29:22 PDT 2018


glider created this revision.
glider added reviewers: vitalybuka, dvyukov.
Herald added a subscriber: llvm-commits.

This is a step towards the upcoming KMSAN implementation patch.
KMSAN is going to use a different warning function, __msan_warning_32(uptr origin), so we'd better create the warning calls in one place.


Repository:
  rL LLVM

https://reviews.llvm.org/D44513

Files:
  lib/Transforms/Instrumentation/MemorySanitizer.cpp


Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -867,6 +867,19 @@
     }
   }
 
+/// \brief Helper function to insert a warning at IRB's current insert point.
+void insertWarningFn(IRBuilder<> &IRB, Value *Origin) {
+  if (!Origin) Origin = (Value *)IRB.getInt32(0);
+  if (MS.TrackOrigins) {
+    IRB.CreateStore(Origin, MS.OriginTLS);
+  }
+  IRB.CreateCall(MS.WarningFn, {});
+  IRB.CreateCall(MS.EmptyAsm, {});
+  // FIXME: Insert UnreachableInst if !MS.Recover?
+  // This may invalidate some of the following checks and needs to be done
+  // at the very end.
+}
+
   void materializeOneCheck(Instruction *OrigIns, Value *Shadow, Value *Origin,
                            bool AsCall) {
     IRBuilder<> IRB(OrigIns);
@@ -877,15 +890,7 @@
     Constant *ConstantShadow = dyn_cast_or_null<Constant>(ConvertedShadow);
     if (ConstantShadow) {
       if (ClCheckConstantShadow && !ConstantShadow->isZeroValue()) {
-        if (MS.TrackOrigins) {
-          IRB.CreateStore(Origin ? (Value *)Origin : (Value *)IRB.getInt32(0),
-                          MS.OriginTLS);
-        }
-        IRB.CreateCall(MS.WarningFn, {});
-        IRB.CreateCall(MS.EmptyAsm, {});
-        // FIXME: Insert UnreachableInst if !MS.Recover?
-        // This may invalidate some of the following checks and needs to be done
-        // at the very end.
+        insertWarningFn(IRB, Origin);
       }
       return;
     }
@@ -909,12 +914,7 @@
           /* Unreachable */ !MS.Recover, MS.ColdCallWeights);
 
       IRB.SetInsertPoint(CheckTerm);
-      if (MS.TrackOrigins) {
-        IRB.CreateStore(Origin ? (Value *)Origin : (Value *)IRB.getInt32(0),
-                        MS.OriginTLS);
-      }
-      IRB.CreateCall(MS.WarningFn, {});
-      IRB.CreateCall(MS.EmptyAsm, {});
+      insertWarningFn(IRB, Origin);
       DEBUG(dbgs() << "  CHECK: " << *Cmp << "\n");
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44513.138527.patch
Type: text/x-patch
Size: 2064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180315/430a512a/attachment.bin>


More information about the llvm-commits mailing list