<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Mar 6, 2017 at 7:27 PM Adrian Prantl <<a href="mailto:aprantl@apple.com">aprantl@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="gmail_msg">
> On Mar 6, 2017, at 2:42 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="gmail_msg" target="_blank">dblaikie@gmail.com</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
> Might need to revert and discuss this further.<br class="gmail_msg">
><br class="gmail_msg">
> When I implemented the infamous assert many years ago I hit cases like this and specifically crafted the assert to work around/allow situations like this because they came up in reality:<br class="gmail_msg">
><br class="gmail_msg">
>   void f1();<br class="gmail_msg">
>   inline __attribute__((alwaysinline)) void f2() {<br class="gmail_msg">
>     f1();<br class="gmail_msg">
>   }<br class="gmail_msg">
>   inline __attribute__((alwaysinline)) __attribute__((nodebug)) void f3() {<br class="gmail_msg">
>     f2();<br class="gmail_msg">
>   }<br class="gmail_msg">
>   void f4() {<br class="gmail_msg">
>     f3();<br class="gmail_msg">
>   }<br class="gmail_msg">
><br class="gmail_msg">
> Even in this case, there's value in keeping the deubg info in f3 after f2 is inlined into it so that when examining f4 there's inline info about f2. It ends up appearing as though f3 were never there - but f2 and f4 were totally there/meaningful/etc.<br class="gmail_msg">
<br class="gmail_msg">
I did not consider the possibility of the nodebug function being inlined into a debuggable function, and I'm surprised that this works — but after studying the code it looks like this might actually work.<br class="gmail_msg"></blockquote><div><br></div><div>Yep, didn't occur to me at first until I was testing all the cases for that assert a few years ago - and verified that that situation works/seems intentional/etc.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I can't immediately revert this because this will now violate the verifier, (r296543), but I can instead relax the check there to allow for this situation and then revert.<br class="gmail_msg">
<br class="gmail_msg">
I'll look into this tomorrow.<br class="gmail_msg"></blockquote><div><br>Thanks!<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="gmail_msg">
-- adrian<br class="gmail_msg">
><br class="gmail_msg">
> Another reason/way to look at this is consistency: If the nodebug function were inlined first, then f2 was inlined - it would produce debug info for f2 and f4. It would be weird if the order of inlining produced substantially different debug info like this.<br class="gmail_msg">
><br class="gmail_msg">
> If I'm understanding all this correctly...<br class="gmail_msg">
><br class="gmail_msg">
> On Tue, Feb 28, 2017 at 9:09 AM Adrian Prantl via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg">
> Author: adrian<br class="gmail_msg">
> Date: Tue Feb 28 10:58:13 2017<br class="gmail_msg">
> New Revision: 296488<br class="gmail_msg">
><br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=296488&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=296488&view=rev</a><br class="gmail_msg">
> Log:<br class="gmail_msg">
> Strip debug info when inlining into a nodebug function.<br class="gmail_msg">
><br class="gmail_msg">
> The LLVM backend cannot produce any debug info for an llvm::Function<br class="gmail_msg">
> without a DISubprogram attachment. When inlining a debug-info-carrying<br class="gmail_msg">
> function into a nodebug function, there is therefore no reason to keep<br class="gmail_msg">
> any debug info intrinsic calls or debug locations on the instructions.<br class="gmail_msg">
><br class="gmail_msg">
> This fixes a problem discovered in PR32042.<br class="gmail_msg">
><br class="gmail_msg">
> rdar://problem/30679307<br class="gmail_msg">
><br class="gmail_msg">
> Added:<br class="gmail_msg">
>     llvm/trunk/test/Transforms/Inline/nodebug.ll<br class="gmail_msg">
> Modified:<br class="gmail_msg">
>     llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp<br class="gmail_msg">
>     llvm/trunk/test/Transforms/Inline/local-as-metadata-undominated-use.ll<br class="gmail_msg">
><br class="gmail_msg">
> Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp<br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=296488&r1=296487&r2=296488&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=296488&r1=296487&r2=296488&view=diff</a><br class="gmail_msg">
> ==============================================================================<br class="gmail_msg">
> --- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)<br class="gmail_msg">
> +++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Tue Feb 28 10:58:13 2017<br class="gmail_msg">
> @@ -1343,22 +1343,26 @@ static bool allocaWouldBeStaticInEntry(c<br class="gmail_msg">
>    return isa<Constant>(AI->getArraySize()) && !AI->isUsedWithInAlloca();<br class="gmail_msg">
>  }<br class="gmail_msg">
><br class="gmail_msg">
> -/// Update inlined instructions' line numbers to<br class="gmail_msg">
> -/// to encode location where these instructions are inlined.<br class="gmail_msg">
> -static void fixupLineNumbers(Function *Fn, Function::iterator FI,<br class="gmail_msg">
> -                             Instruction *TheCall, bool CalleeHasDebugInfo) {<br class="gmail_msg">
> +/// Update inlined instructions' line numbers to to encode location where these<br class="gmail_msg">
> +/// instructions are inlined.  Also strip all debug intrinsics that were inlined<br class="gmail_msg">
> +/// into a nodebug function; there is no debug info the backend could produce<br class="gmail_msg">
> +/// for a function without a DISubprogram attachment.<br class="gmail_msg">
> +static void fixupDebugInfo(Function *Fn, Function::iterator FI,<br class="gmail_msg">
> +                           Instruction *TheCall, bool CalleeHasDebugInfo) {<br class="gmail_msg">
> +  bool CallerHasDebugInfo = Fn->getSubprogram();<br class="gmail_msg">
> +  bool StripDebugInfo = !CallerHasDebugInfo && CalleeHasDebugInfo;<br class="gmail_msg">
> +  SmallVector<DbgInfoIntrinsic *, 8> IntrinsicsToErase;<br class="gmail_msg">
>    const DebugLoc &TheCallDL = TheCall->getDebugLoc();<br class="gmail_msg">
> -  if (!TheCallDL)<br class="gmail_msg">
> -    return;<br class="gmail_msg">
><br class="gmail_msg">
>    auto &Ctx = Fn->getContext();<br class="gmail_msg">
> -  DILocation *InlinedAtNode = TheCallDL;<br class="gmail_msg">
> +  DILocation *InlinedAtNode = nullptr;<br class="gmail_msg">
><br class="gmail_msg">
>    // Create a unique call site, not to be confused with any other call from the<br class="gmail_msg">
>    // same location.<br class="gmail_msg">
> -  InlinedAtNode = DILocation::getDistinct(<br class="gmail_msg">
> -      Ctx, InlinedAtNode->getLine(), InlinedAtNode->getColumn(),<br class="gmail_msg">
> -      InlinedAtNode->getScope(), InlinedAtNode->getInlinedAt());<br class="gmail_msg">
> +  if (TheCallDL)<br class="gmail_msg">
> +    InlinedAtNode = DILocation::getDistinct(<br class="gmail_msg">
> +        Ctx, TheCallDL->getLine(), TheCallDL->getColumn(),<br class="gmail_msg">
> +        TheCallDL->getScope(), TheCallDL->getInlinedAt());<br class="gmail_msg">
><br class="gmail_msg">
>    // Cache the inlined-at nodes as they're built so they are reused, without<br class="gmail_msg">
>    // this every instruction's inlined-at chain would become distinct from each<br class="gmail_msg">
> @@ -1368,6 +1372,17 @@ static void fixupLineNumbers(Function *F<br class="gmail_msg">
>    for (; FI != Fn->end(); ++FI) {<br class="gmail_msg">
>      for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();<br class="gmail_msg">
>           BI != BE; ++BI) {<br class="gmail_msg">
> +      if (StripDebugInfo) {<br class="gmail_msg">
> +        // Inlining into a nodebug function.<br class="gmail_msg">
> +        if (auto *DI = dyn_cast<DbgInfoIntrinsic>(BI))<br class="gmail_msg">
> +          // Mark dead debug intrinsics for deletion.<br class="gmail_msg">
> +          IntrinsicsToErase.push_back(DI);<br class="gmail_msg">
> +        else<br class="gmail_msg">
> +          // Remove the dangling debug location.<br class="gmail_msg">
> +          BI->setDebugLoc(DebugLoc());<br class="gmail_msg">
> +        continue;<br class="gmail_msg">
> +      }<br class="gmail_msg">
> +<br class="gmail_msg">
>        if (DebugLoc DL = BI->getDebugLoc()) {<br class="gmail_msg">
>          BI->setDebugLoc(<br class="gmail_msg">
>              updateInlinedAtInfo(DL, InlinedAtNode, BI->getContext(), IANodes));<br class="gmail_msg">
> @@ -1390,6 +1405,9 @@ static void fixupLineNumbers(Function *F<br class="gmail_msg">
>        BI->setDebugLoc(TheCallDL);<br class="gmail_msg">
>      }<br class="gmail_msg">
>    }<br class="gmail_msg">
> +<br class="gmail_msg">
> +  for (auto *DI : IntrinsicsToErase)<br class="gmail_msg">
> +    DI->eraseFromParent();<br class="gmail_msg">
>  }<br class="gmail_msg">
>  /// Update the block frequencies of the caller after a callee has been inlined.<br class="gmail_msg">
>  ///<br class="gmail_msg">
> @@ -1710,8 +1728,8 @@ bool llvm::InlineFunction(CallSite CS, I<br class="gmail_msg">
>      // For 'nodebug' functions, the associated DISubprogram is always null.<br class="gmail_msg">
>      // Conservatively avoid propagating the callsite debug location to<br class="gmail_msg">
>      // instructions inlined from a function whose DISubprogram is not null.<br class="gmail_msg">
> -    fixupLineNumbers(Caller, FirstNewBlock, TheCall,<br class="gmail_msg">
> -                     CalledFunc->getSubprogram() != nullptr);<br class="gmail_msg">
> +    fixupDebugInfo(Caller, FirstNewBlock, TheCall,<br class="gmail_msg">
> +                   CalledFunc->getSubprogram() != nullptr);<br class="gmail_msg">
><br class="gmail_msg">
>      // Clone existing noalias metadata if necessary.<br class="gmail_msg">
>      CloneAliasScopeMetadata(CS, VMap);<br class="gmail_msg">
><br class="gmail_msg">
> Modified: llvm/trunk/test/Transforms/Inline/local-as-metadata-undominated-use.ll<br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/local-as-metadata-undominated-use.ll?rev=296488&r1=296487&r2=296488&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/local-as-metadata-undominated-use.ll?rev=296488&r1=296487&r2=296488&view=diff</a><br class="gmail_msg">
> ==============================================================================<br class="gmail_msg">
> --- llvm/trunk/test/Transforms/Inline/local-as-metadata-undominated-use.ll (original)<br class="gmail_msg">
> +++ llvm/trunk/test/Transforms/Inline/local-as-metadata-undominated-use.ll Tue Feb 28 10:58:13 2017<br class="gmail_msg">
> @@ -16,14 +16,14 @@ entry:<br class="gmail_msg">
>  }<br class="gmail_msg">
><br class="gmail_msg">
>  ; CHECK-LABEL: define i32 @caller(<br class="gmail_msg">
> -define i32 @caller(i32 %i) {<br class="gmail_msg">
> +define i32 @caller(i32 %i) !dbg !3 {<br class="gmail_msg">
>  ; CHECK-NEXT: entry:<br class="gmail_msg">
>  entry:<br class="gmail_msg">
>  ; Although the inliner shouldn't crash, it can't be expected to get the<br class="gmail_msg">
>  ; "correct" SSA value since its assumptions have been violated.<br class="gmail_msg">
>  ; CHECK-NEXT:   tail call void @llvm.dbg.value(metadata ![[EMPTY:[0-9]+]],<br class="gmail_msg">
>  ; CHECK-NEXT:   %{{.*}} = add nsw<br class="gmail_msg">
> -  %call = tail call i32 @foo(i32 %i)<br class="gmail_msg">
> +  %call = tail call i32 @foo(i32 %i), !dbg !14<br class="gmail_msg">
>    ret i32 %call<br class="gmail_msg">
>  }<br class="gmail_msg">
><br class="gmail_msg">
> @@ -34,9 +34,9 @@ declare void @llvm.dbg.value(metadata, i<br class="gmail_msg">
><br class="gmail_msg">
>  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 265634) (llvm/trunk 265637)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)<br class="gmail_msg">
>  !1 = !DIFile(filename: "t.c", directory: "/path/to/tests")<br class="gmail_msg">
> -<br class="gmail_msg">
>  ; CHECK: ![[EMPTY]] = !{}<br class="gmail_msg">
>  !2 = !{}<br class="gmail_msg">
> +!3 = distinct !DISubprogram(name: "caller", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0)<br class="gmail_msg">
>  !4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0)<br class="gmail_msg">
>  !5 = !DISubroutineType(types: !6)<br class="gmail_msg">
>  !6 = !{!7, !7}<br class="gmail_msg">
> @@ -47,3 +47,4 @@ declare void @llvm.dbg.value(metadata, i<br class="gmail_msg">
>  !11 = !DILocation(line: 2, column: 13, scope: !4)<br class="gmail_msg">
>  !12 = !DILocation(line: 2, column: 27, scope: !4)<br class="gmail_msg">
>  !13 = !DILocation(line: 2, column: 18, scope: !4)<br class="gmail_msg">
> +!14 = !DILocation(line: 3, scope: !3)<br class="gmail_msg">
><br class="gmail_msg">
> Added: llvm/trunk/test/Transforms/Inline/nodebug.ll<br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/nodebug.ll?rev=296488&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/nodebug.ll?rev=296488&view=auto</a><br class="gmail_msg">
> ==============================================================================<br class="gmail_msg">
> --- llvm/trunk/test/Transforms/Inline/nodebug.ll (added)<br class="gmail_msg">
> +++ llvm/trunk/test/Transforms/Inline/nodebug.ll Tue Feb 28 10:58:13 2017<br class="gmail_msg">
> @@ -0,0 +1,36 @@<br class="gmail_msg">
> +; RUN: opt -inline -S -o - < %s | FileCheck %s<br class="gmail_msg">
> +; Check that debug info is stripped when inlining into a nodebug function.<br class="gmail_msg">
> +<br class="gmail_msg">
> +declare void @llvm.dbg.declare(metadata, metadata, metadata)<br class="gmail_msg">
> +declare void @llvm.dbg.value(metadata, i64, metadata, metadata)<br class="gmail_msg">
> +<br class="gmail_msg">
> +define void @foo() !dbg !2 {<br class="gmail_msg">
> +entry:<br class="gmail_msg">
> +  %a = alloca i32<br class="gmail_msg">
> +  call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !3, metadata !DIExpression()), !dbg !6<br class="gmail_msg">
> +  store i32 0, i32* %a, !dbg !6<br class="gmail_msg">
> +  ret void, !dbg !6<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +; CHECK: define void @bar()<br class="gmail_msg">
> +define void @bar() {<br class="gmail_msg">
> +; CHECK-NEXT: entry<br class="gmail_msg">
> +entry:<br class="gmail_msg">
> +; CHECK-NEXT: alloca i32<br class="gmail_msg">
> +; CHECK-NOT: dbg<br class="gmail_msg">
> +; CHECK: ret void<br class="gmail_msg">
> +  call void @foo()<br class="gmail_msg">
> +  ret void<br class="gmail_msg">
> +}<br class="gmail_msg">
> +<br class="gmail_msg">
> +!<a href="http://llvm.dbg.cu" rel="noreferrer" class="gmail_msg" target="_blank">llvm.dbg.cu</a> = !{!0}<br class="gmail_msg">
> +!llvm.module.flags = !{!7, !8}<br class="gmail_msg">
> +<br class="gmail_msg">
> +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", emissionKind: FullDebug)<br class="gmail_msg">
> +!1 = !DIFile(filename: "x.c", directory: "/")<br class="gmail_msg">
> +!2 = distinct !DISubprogram(name: "foo", scope: !0, isDefinition: true, unit: !0)<br class="gmail_msg">
> +!3 = !DILocalVariable(name: "a", arg: 1, scope: !2, file: !1, line: 1, type: !5)<br class="gmail_msg">
> +!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br class="gmail_msg">
> +!6 = !DILocation(line: 1, scope: !2)<br class="gmail_msg">
> +!7 = !{i32 2, !"Dwarf Version", i32 4}<br class="gmail_msg">
> +!8 = !{i32 1, !"Debug Info Version", i32 3}<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> _______________________________________________<br class="gmail_msg">
> llvm-commits mailing list<br class="gmail_msg">
> <a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>