<div dir="ltr">Hey Reid,<div><br></div><div>I've reverted this in r215532 because it causes MSan instrumented compiles to crash in the instrumentation pass pretty rampantly on our C++ code. I suspect a boot strap would reproduce, but I've also sent you (off list) an easy if un-reduced reproduction. I needed to revert it to get the tree green while you investigate.</div>
<div><br></div><div>Thanks,</div><div>-Chandler</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 11, 2014 at 5:12 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:reid@kleckner.net" target="_blank">reid@kleckner.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Mon Aug 11 19:12:43 2014<br>
New Revision: 215415<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=215415&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=215415&view=rev</a><br>
Log:<br>
msan: Handle musttail calls<br>
<br>
First, avoid calling setTailCall(false) on musttail calls.  The funciton<br>
prototypes should be "congruent", so the shadow layout should be exactly<br>
the same.<br>
<br>
Second, avoid inserting instrumentation after a musttail call to<br>
propagate the return value shadow.  We don't need to propagate the<br>
result of a tail call, it should already be in the right place.<br>
<br>
Reviewed By: eugenis<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D4331" target="_blank">http://reviews.llvm.org/D4331</a><br>
<br>
Modified:<br>
    llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp<br>
    llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll<br>
<br>
Modified: llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp?rev=215415&r1=215414&r2=215415&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp?rev=215415&r1=215414&r2=215415&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp Mon Aug 11 19:12:43 2014<br>
@@ -2356,6 +2356,12 @@ struct MemorySanitizerVisitor : public I<br>
       VAHelper->visitCallSite(CS, IRB);<br>
     }<br>
<br>
+    // If this is a musttail call site, we can't insert propagation code here.<br>
+    // The return type of the caller must match the callee, so the shadow should<br>
+    // already be set up for an immediate return.<br>
+    if (CS.isMustTailCall())<br>
+      return;<br>
+<br>
     // Now, get the shadow for the RetVal.<br>
     if (!I.getType()->isSized()) return;<br>
     IRBuilder<> IRBBefore(&I);<br>
@@ -2389,6 +2395,10 @@ struct MemorySanitizerVisitor : public I<br>
   }<br>
<br>
   void visitReturnInst(ReturnInst &I) {<br>
+    // Don't propagate shadow between musttail calls and the return.<br>
+    if (I.getParent()->getTerminatingMustTailCall())<br>
+      return;<br>
+<br>
     IRBuilder<> IRB(&I);<br>
     Value *RetVal = I.getReturnValue();<br>
     if (!RetVal) return;<br>
<br>
Modified: llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll?rev=215415&r1=215414&r2=215415&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll?rev=215415&r1=215414&r2=215415&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll (original)<br>
+++ llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll Mon Aug 11 19:12:43 2014<br>
@@ -878,3 +878,16 @@ define void @MismatchedReturnTypeTailCal<br>
 ; CHECK-LABEL: define void @MismatchedReturnTypeTailCall<br>
 ; CHECK: tail call i32 @InnerTailCall<br>
 ; CHECK: ret void<br>
+<br>
+declare i32 @InnerMustTailCall(i32 %a)<br>
+<br>
+define i32 @MustTailCall(i32 %a) {<br>
+  %b = musttail call i32 @InnerMustTailCall(i32 %a)<br>
+  ret i32 %b<br>
+}<br>
+<br>
+; Test that 'musttail' is preserved.  The ABI should make this work.<br>
+<br>
+; CHECK-LABEL: define i32 @MustTailCall<br>
+; CHECK: musttail call i32 @InnerMustTailCall<br>
+; CHECK-NEXT: ret i32<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>