[llvm] r215415 - msan: Handle musttail calls

Chandler Carruth chandlerc at google.com
Wed Aug 13 02:28:47 PDT 2014


Hey Reid,

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.

Thanks,
-Chandler


On Mon, Aug 11, 2014 at 5:12 PM, Reid Kleckner <reid at kleckner.net> wrote:

> Author: rnk
> Date: Mon Aug 11 19:12:43 2014
> New Revision: 215415
>
> URL: http://llvm.org/viewvc/llvm-project?rev=215415&view=rev
> Log:
> msan: Handle musttail calls
>
> First, avoid calling setTailCall(false) on musttail calls.  The funciton
> prototypes should be "congruent", so the shadow layout should be exactly
> the same.
>
> Second, avoid inserting instrumentation after a musttail call to
> propagate the return value shadow.  We don't need to propagate the
> result of a tail call, it should already be in the right place.
>
> Reviewed By: eugenis
>
> Differential Revision: http://reviews.llvm.org/D4331
>
> Modified:
>     llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
>     llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll
>
> Modified: llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp?rev=215415&r1=215414&r2=215415&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp Mon Aug
> 11 19:12:43 2014
> @@ -2356,6 +2356,12 @@ struct MemorySanitizerVisitor : public I
>        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 @@ struct MemorySanitizerVisitor : public I
>    }
>
>    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;
>
> Modified: llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll?rev=215415&r1=215414&r2=215415&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll
> (original)
> +++ llvm/trunk/test/Instrumentation/MemorySanitizer/msan_basic.ll Mon Aug
> 11 19:12:43 2014
> @@ -878,3 +878,16 @@ define void @MismatchedReturnTypeTailCal
>  ; 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
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140813/430554f0/attachment.html>


More information about the llvm-commits mailing list