<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 9, 2015 at 9:39 AM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div><blockquote type="cite"><div>On Feb 6, 2015, at 2:57 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 4, 2015 at 5:29 PM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><br>
> On Feb 4, 2015, at 11:47 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
><br>
> Author: dblaikie<br>
> Date: Wed Feb  4 13:47:54 2015<br>
> New Revision: 228181<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=228181&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=228181&view=rev</a><br>
> Log:<br>
> DebugInfo: Attribute cleanup code to the end of the scope, not the end of the function.<br>
><br>
> Now if you break on a dtor and go 'up' in your debugger (or you get an<br>
> asan failure in a dtor) during an exception unwind, you'll have more<br>
> context. Instead of all dtors appearing to be called from the '}' of the<br>
> function, they'll be attributed to the end of the scope of the variable,<br>
> the same as the non-exceptional dtor call.<br>
><br>
> This doesn't /quite/ remove all uses of CurEHLocation (which might be<br>
> nice to remove, for a few reasons) - it's still used to choose the<br>
> location for some other work in the landing pad. It'd be nice to<br>
> attribute that code to the same location as the exception calls within<br>
> the block and to remove CurEHLocation.<br>
><br>
> Modified:<br>
>    cfe/trunk/lib/CodeGen/CGCleanup.cpp<br>
>    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
>    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
>    cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
>    cfe/trunk/test/CodeGenCXX/debug-info-line.cpp<br>
>    cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp<br>
>    cfe/trunk/test/CodeGenObjC/arc-linetable.m<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGCleanup.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=228181&r1=228180&r2=228181&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=228181&r1=228180&r2=228181&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGCleanup.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGCleanup.cpp Wed Feb  4 13:47:54 2015<br>
> @@ -861,8 +861,6 @@ void CodeGenFunction::PopCleanupBlock(bo<br>
><br>
>   // Emit the EH cleanup if required.<br>
>   if (RequiresEHCleanup) {<br>
> -    auto AL = ApplyDebugLocation::CreateDefaultArtificial(*this, CurEHLocation);<br>
> -<br>
<br>
</div></div>You can’t just remove this here: If CurEHLocation is a nullptr ((as it would be in an artificial function), or after removing this - the current location) we still need to set the location to *something* valid or we will create an unattributed call which will after inlining trigger the famous "scope does not describe function” assertion.<br></blockquote><div><br>When does that happen (CurEHLocation being nullptr or the current location being unset)?</div></div></div></div></div></blockquote><div><br></div></div></div><div>In the wonderful language that is Objective C++; when there is an invocation to a C++ destructor in an ObjC destroy block helper, such as in the <span style="font-family:Menlo-Regular">cfe/trunk/test/CodeGenObjCXX/<a href="http://nested-ehlocation.mm" target="_blank">nested-ehlocation.mm</a> </span>testcase. Copy/Destroy helpers are artificial locations, so CurEHLocation is an empty SourceLocation(). I might be wrong about that the current location ever being unset after all the recent changes, but I would feel more comfortable if we at least had an assertion about it there, to make sure that there is a valid location. The earlier we can catch the problem, the better.</div></div></div></blockquote><div><br>Could an assert in here that just calls Builder.getCurrentDebugLocation().isValid(), if that suits... <br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
<br>
>     CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();<br>
><br>
>     EmitBlock(EHEntry);<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=228181&r1=228180&r2=228181&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=228181&r1=228180&r2=228181&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Feb  4 13:47:54 2015<br>
> @@ -55,7 +55,6 @@ CGDebugInfo::~CGDebugInfo() {<br>
> ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,<br>
>                                        SourceLocation TemporaryLocation)<br>
>     : CGF(CGF) {<br>
> -  assert(!TemporaryLocation.isInvalid() && "invalid location”);<br>
<br>
</span>Please don’t. I’d like to keep a clear separation between the uses of ApplyDebugLocation were a location is mandatory (for example, when we will be emitting a call/invoke) and the ones were it is optional.<br></blockquote><div><br>Given that the ApplyDebugLocation(CGF, Expr) ctor already allows expressions with invalid SourceLocations as no-ops, this seemed consistent. Is there a reason to treat these differently? Or should we have 4 flavors here ({SL,Expr}x{mandatory,optional})?<br></div></div></div></div></div></blockquote><div><br></div></span><div>The Expr flavor is only (hopefully) used within the body of a function where it is safe to assume that a previous location was set and can be reused as a somewhat reasonable default, so I think we can get away with just having only one version. But for anything that might be used in the function epilogue/cleanup blocks we need to be more careful.</div></div></div></blockquote><div><br>I'm not quite sure I see the distinction between those two cases - the problem occurs with any call instruction without a debug location (where the call site is in a function with debug info, an the call is to a function with debug info, and the call is inlinable - unfortunately I tried enforcing stronger contracts such that any call within a function with debug info needed a debug location, but that didn't hold - it might be possible to make it hold). So the epilogue/cleanup isn't especilaly special - any call, anywhere in the function, could have this issue.<br><br>& I'm not sure why Expr locations are more likely to be preceeded by an existing location than cleanup/epilogue instructions are.<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span><font color="#888888"><div><br></div><div>-- adrian</div></font></span><div><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div>>   init(TemporaryLocation);<br>
> }<br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=228181&r1=228180&r2=228181&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=228181&r1=228180&r2=228181&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Feb  4 13:47:54 2015<br>
> @@ -241,8 +241,6 @@ void CodeGenFunction::FinishFunction(Sou<br>
>   // edges will be *really* confused.<br>
>   bool EmitRetDbgLoc = true;<br>
>   if (EHStack.stable_begin() != PrologueCleanupDepth) {<br>
> -    PopCleanupBlocks(PrologueCleanupDepth);<br>
> -<br>
>     // Make sure the line table doesn't jump back into the body for<br>
>     // the ret after it's been at EndLoc.<br>
>     EmitRetDbgLoc = false;<br>
> @@ -250,6 +248,8 @@ void CodeGenFunction::FinishFunction(Sou<br>
>     if (CGDebugInfo *DI = getDebugInfo())<br>
>       if (OnlySimpleReturnStmts)<br>
>         DI->EmitLocation(Builder, EndLoc);<br>
> +<br>
> +    PopCleanupBlocks(PrologueCleanupDepth);<br>
>   }<br>
><br>
>   // Emit function epilog (to return).<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=228181&r1=228180&r2=228181&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=228181&r1=228180&r2=228181&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)<br>
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Feb  4 13:47:54 2015<br>
> @@ -567,7 +567,10 @@ public:<br>
><br>
>       // If we should perform a cleanup, force them now.  Note that<br>
>       // this ends the cleanup scope before rescoping any labels.<br>
> -      if (PerformCleanup) ForceCleanup();<br>
> +      if (PerformCleanup) {<br>
> +        ApplyDebugLocation DL(CGF, Range.getEnd());<br>
> +        ForceCleanup();<br>
> +      }<br>
<br>
</div></div>This also looks super-dangerous for the same reason. What if the last location was empty?<br>
<span><font color="#888888"><br>
-- adrian<br>
</font></span><div><div>>     }<br>
><br>
>     /// \brief Force the emission of cleanups now, instead of waiting<br>
><br>
> Modified: cfe/trunk/test/CodeGenCXX/debug-info-line.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=228181&r1=228180&r2=228181&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=228181&r1=228180&r2=228181&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGenCXX/debug-info-line.cpp (original)<br>
> +++ cfe/trunk/test/CodeGenCXX/debug-info-line.cpp Wed Feb  4 13:47:54 2015<br>
> @@ -259,6 +259,21 @@ void f21() {<br>
>   f21_b();<br>
> }<br>
><br>
> +// CHECK-LABEL: define<br>
> +struct f22_dtor {<br>
> +  ~f22_dtor();<br>
> +};<br>
> +void f22() {<br>
> +  {<br>
> +    f22_dtor f;<br>
> +    src();<br>
> +// CHECK: call {{.*}}src<br>
> +// CHECK: call {{.*}}, !dbg [[DBG_F22:![0-9]*]]<br>
> +// CHECK: call {{.*}}, !dbg [[DBG_F22]]<br>
> +#line 2400<br>
> +  }<br>
> +}<br>
> +<br>
> // CHECK: [[DBG_F1]] = !MDLocation(line: 100,<br>
> // CHECK: [[DBG_FOO_VALUE]] = !MDLocation(line: 200,<br>
> // CHECK: [[DBG_FOO_REF]] = !MDLocation(line: 202,<br>
><br>
> Modified: cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp?rev=228181&r1=228180&r2=228181&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp?rev=228181&r1=228180&r2=228181&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp (original)<br>
> +++ cfe/trunk/test/CodeGenCXX/linetable-cleanup.cpp Wed Feb  4 13:47:54 2015<br>
> @@ -4,8 +4,8 @@<br>
> // simple return expressions.<br>
><br>
> // CHECK: define {{.*}}foo<br>
> -// CHECK: call void @_ZN1CD1Ev(%class.C* {{.*}}), !dbg ![[CLEANUP:[0-9]+]]<br>
> -// CHECK: ret i32 0, !dbg ![[RET:[0-9]+]]<br>
> +// CHECK: call void @_ZN1CD1Ev(%class.C* {{.*}}), !dbg ![[RET:[0-9]+]]<br>
> +// CHECK: ret i32 0, !dbg ![[RET]]<br>
><br>
> // CHECK: define {{.*}}bar<br>
> // CHECK: ret void, !dbg ![[RETBAR:[0-9]+]]<br>
> @@ -23,9 +23,8 @@ int foo()<br>
> {<br>
>   C c;<br>
>   c.i = 42;<br>
> -  // This breakpoint should be at/before the cleanup code.<br>
> -  // CHECK: ![[CLEANUP]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})<br>
>   return 0;<br>
> +  // This breakpoint should be at/before the cleanup code.<br>
>   // CHECK: ![[RET]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})<br>
> }<br>
><br>
><br>
> Modified: cfe/trunk/test/CodeGenObjC/arc-linetable.m<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-linetable.m?rev=228181&r1=228180&r2=228181&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-linetable.m?rev=228181&r1=228180&r2=228181&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGenObjC/arc-linetable.m (original)<br>
> +++ cfe/trunk/test/CodeGenObjC/arc-linetable.m Wed Feb  4 13:47:54 2015<br>
> @@ -4,8 +4,8 @@<br>
><br>
> // CHECK: define {{.*}}testNoSideEffect<br>
> // CHECK: call void @objc_storeStrong{{.*}}<br>
> -// CHECK: call void @objc_storeStrong{{.*}} !dbg ![[ARC1:[0-9]+]]<br>
> -// CHECK: ret {{.*}} !dbg ![[RET1:[0-9]+]]<br>
> +// CHECK: call void @objc_storeStrong{{.*}} !dbg ![[RET1:[0-9]+]]<br>
> +// CHECK: ret {{.*}} !dbg ![[RET1]]<br>
><br>
> // CHECK: define {{.*}}testNoCleanup<br>
> // CHECK: ret {{.*}} !dbg ![[RET2:[0-9]+]]<br>
> @@ -21,8 +21,8 @@<br>
><br>
> // CHECK: define {{.*}}testVoid<br>
> // CHECK: call void @objc_storeStrong{{.*}}<br>
> -// CHECK: call void @objc_storeStrong{{.*}} !dbg ![[ARC5:[0-9]+]]<br>
> -// CHECK: ret {{.*}} !dbg ![[RET5:[0-9]+]]<br>
> +// CHECK: call void @objc_storeStrong{{.*}} !dbg ![[RET5:[0-9]+]]<br>
> +// CHECK: ret {{.*}} !dbg ![[RET5]]<br>
><br>
> // CHECK: define {{.*}}testVoidNoReturn<br>
> // CHECK: @objc_msgSend{{.*}} !dbg ![[MSG6:[0-9]+]]<br>
> @@ -57,9 +57,8 @@ typedef signed char BOOL;<br>
> // CHECK: ![[TESTNOSIDEEFFECT:.*]] = {{.*}}[ DW_TAG_subprogram ] [line [[@LINE+1]]] [local] [def] [-[AppDelegate testNoSideEffect:]]<br>
> - (int)testNoSideEffect:(NSString *)foo {<br>
>   int x = 1;<br>
> -  // CHECK: ![[ARC1]] = !MDLocation(line: [[@LINE+1]], scope: ![[TESTNOSIDEEFFECT]])<br>
>   return 1; // Return expression<br>
> -  // CHECK: ![[RET1]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})<br>
> +  // CHECK: ![[RET1]] = !MDLocation(line: [[@LINE+1]], scope: ![[TESTNOSIDEEFFECT]])<br>
> }           // Cleanup + Ret<br>
><br>
> - (int)testNoCleanup {<br>
> @@ -82,7 +81,6 @@ typedef signed char BOOL;<br>
> }<br>
><br>
> - (void)testVoid:(NSString *)foo {<br>
> -  // CHECK: ![[ARC5]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})<br>
>   return;<br>
>   // CHECK: ![[RET5]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})<br>
> }<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br>
</div></div></blockquote></div><br></div></div>
</div></blockquote></div></div></div><br></div></blockquote></div><br></div></div>