[PATCH] msan: Handle musttail calls

Reid Kleckner rnk at google.com
Mon Aug 11 17:21:49 PDT 2014


Closed by commit rL215415 (authored by @rnk).

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D4331

Files:
  llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll

Index: llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -2356,6 +2356,12 @@
       VAHelper->visitCallSite(CS, IRB);
     }
 
+    // If this is a musttail call site, we can't insert propagation code here.
+    // The return type of the caller must match the callee, so the shadow should
+    // already be set up for an immediate return.
+    if (CS.isMustTailCall())
+      return;
+
     // Now, get the shadow for the RetVal.
     if (!I.getType()->isSized()) return;
     IRBuilder<> IRBBefore(&I);
@@ -2389,6 +2395,10 @@
   }
 
   void visitReturnInst(ReturnInst &I) {
+    // Don't propagate shadow between musttail calls and the return.
+    if (I.getParent()->getTerminatingMustTailCall())
+      return;
+
     IRBuilder<> IRB(&I);
     Value *RetVal = I.getReturnValue();
     if (!RetVal) return;
Index: llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll
===================================================================
--- llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll
+++ llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll
@@ -878,3 +878,16 @@
 ; CHECK-LABEL: define void @MismatchedReturnTypeTailCall
 ; CHECK: tail call i32 @InnerTailCall
 ; CHECK: ret void
+
+declare i32 @InnerMustTailCall(i32 %a)
+
+define i32 @MustTailCall(i32 %a) {
+  %b = musttail call i32 @InnerMustTailCall(i32 %a)
+  ret i32 %b
+}
+
+; Test that 'musttail' is preserved.  The ABI should make this work.
+
+; CHECK-LABEL: define i32 @MustTailCall
+; CHECK: musttail call i32 @InnerMustTailCall
+; CHECK-NEXT: ret i32
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4331.12374.patch
Type: text/x-patch
Size: 1766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140812/e4881d7b/attachment.bin>


More information about the llvm-commits mailing list