<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 10, 2016, at 3:28 PM, Peter Collingbourne <<a href="mailto:peter@pcc.me.uk" class="">peter@pcc.me.uk</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Tue, May 10, 2016 at 3:03 PM, Adrian Prantl<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On May 9, 2016, at 4:42 PM, Peter Collingbourne via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><br class=""><br class=""><div class="gmail_quote">On Mon, May 9, 2016 at 4:26 PM, David Blaikie<span class=""> </span><span dir="ltr" class=""><<a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><div class=""><div class="">On Mon, May 9, 2016 at 3:38 PM, Peter Collingbourne<span class=""> </span><span dir="ltr" class=""><<a href="mailto:peter@pcc.me.uk" target="_blank" class="">peter@pcc.me.uk</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Mon, May 9, 2016 at 3:17 PM, Peter Collingbourne<span class=""> </span><span dir="ltr" class=""><<a href="mailto:peter@pcc.me.uk" target="_blank" class="">peter@pcc.me.uk</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Mon, May 9, 2016 at 2:33 PM, David Blaikie<span class=""> </span><span dir="ltr" class=""><<a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Mon, May 9, 2016 at 1:53 PM, Peter Collingbourne<span class=""> </span><span dir="ltr" class=""><<a href="mailto:peter@pcc.me.uk" target="_blank" class="">peter@pcc.me.uk</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Fri, May 6, 2016 at 2:10 PM, David Blaikie<span class=""> </span><span dir="ltr" class=""><<a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Fri, May 6, 2016 at 2:09 PM, David Blaikie<span class=""> </span><span dir="ltr" class=""><<a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Fri, May 6, 2016 at 1:55 PM, Peter Collingbourne via llvm-dev<span class=""> </span><span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Fri, May 6, 2016 at 1:21 PM, Duncan P. N. Exon Smith<span class=""> </span><span dir="ltr" class=""><<a href="mailto:dexonsmith@apple.com" target="_blank" class="">dexonsmith@apple.com</a>></span><span class=""> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><span class=""><br class="">> On 2016-May-06, at 13:17, Peter Collingbourne <<a href="mailto:peter@pcc.me.uk" target="_blank" class="">peter@pcc.me.uk</a>> wrote:<br class="">><br class="">> Hi all,<br class="">><br class="">> I'd like to add support for metadata attachments for global variables in the same way as we did for functions.<br class="">><br class="">> Syntax would be pretty simple:<br class="">> @foo = global i32 0, !foo !0, !bar !1<br class="">> (the extra commas are required to disambiguate from a named metadata on the next line)<br class=""><br class=""></span>SGTM.<br class=""><span class=""><br class="">> Benefits:<br class="">> 1) Lets us reverse the DIGlobalVariable -> GlobalVariable edge, which should hopefully clear the way for removing the<span class=""> </span><a href="http://llvm.dbg.cu/" rel="noreferrer" target="_blank" class="">llvm.dbg.cu</a><span class=""> </span>named metadata node.<br class=""><br class=""></span>A little harder than it sounds (need to somehow support a GlobalVariable that is RAUW'ed with a ConstantInt), but I think this is important to do.<br class=""></blockquote><div class=""><br class=""></div></span><div class="">How can a GlobalVariable be replaced with a ConstantInt? Wouldn't that just be an absolute address?</div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">If the global variable has a known constant value & the address is never needed, then we might optimize away the storage and still want debug info describing the constant. </div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">I'm not sure under what conditions, if any, that currently works - so this may be more of a "nice to have" or "be good to think about how any future design wouldn't preclude fixing this gap" sort of thing.</div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">It looks like this is how debug info for static data members used to look until r172591 landed back in 2013.</div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Could you explain more what you mean by "<this> is how it worked until" - 'this' being how it used to work and how you're proposing to make it work? I'm not quite following.</div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Sorry, I meant that prior to r172591 we would represent a static data member with something that looked like what a DIGlobalVariable looks like today, but with a ConstantInt representing the initializer in the variable field (which is where the GlobalVariable is normally stored). The change moved the initializer to an associated "static member type" (yes, it's not really a type), which as a side effect caused us to (as far as I can tell) no longer store ConstantInts in the variable field.</div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Actually this isn't accurate, we still produce a ConstantInt in the variable field of DIGlobalVariable for constants in the global scope (e.g. test/CodeGen/2010-08-10-DbgConstant.c in clang). I'll have to think more about what the right representation is for that then.</div></div></div></div></blockquote><div class=""><br class=""></div></div></div><div class="">Looks like this might be broken/have regressed at some point:<br class=""><br class="">static const int x = 3;</div><div class="">void f1(int);<br class="">void f2(int*);</div><div class="">void f3() {<br class=""> <span class=""> </span>f1(x);<br class=""> <span class=""> </span>f2(&x);</div><div class="">}<br class=""><br class="">Now we generate two global variables named 'x', one with a constant value, the other with an address.<br class=""><br class="">We probably only want the one with the address. (but, then again, we probably want to turn the one with an address to having a constant value if its storage gets optimized away)</div></div></div></div></blockquote></div><br class="">Thanks David. I was thinking about this representational change for DIGlobalVariable:</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">1) replace the Variable field with a Value field of type ConstantData, and use it exclusively for constant initializers</div></div></div></blockquote><div class=""><br class=""></div></div></div><div class="">I would prefer a DIExpression field for holding the constant value. Besides it being generally useful; if we use a constant, GlobalOpts will believe the constant to be dead and remove it.</div><div class="">Such as the problem with ASAN GEPs outlined in <a href="http://reviews.llvm.org/D18109" target="_blank" class="">http://reviews.llvm.org/D18109</a>.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Would that work though? Unless I'm misunderstanding something, the DIExpression would appear as a DW_AT_location attribute on the global variable, which would tell the debugger how to calculate its address. But if the global has no address we would instead need a DW_AT_const_value attribute to represent the value, wouldn't we?</div></div></div></blockquote><div><br class=""></div><div>What I’m envisioning is that we would have a DIExpression(DW_OP_constu, <the constant value>, DW_OP_stack_value), which we then could either directly emit as DWARF 5 or translate into a DW_AT_const_value in the Dwarf backend for better compatibility and more efficient encoding. This way we don’t need to fear the optimization passes, and get to use complex expressions on global variables.</div><div><br class=""></div><div>-- adrian</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class=""></div><div class="">Peter</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><span class=""><font color="#888888" class=""><div class="">-- adrian</div><br class=""></font></span><blockquote type="cite" class=""><div class=""><span class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra">2) change the logic in the debug info emitter (DwarfCompileUnit::getOrCreateGlobalVariableDIE) to look like this:</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">if (the DIGlobalVariable was attached to a GlobalVariable) {</div><div class="gmail_extra"> <span class="Apple-converted-space"> </span>// add a location to the variable DIE</div><div class="gmail_extra">} else if (the DIGlobalVariable has an associated value) {</div><div class="gmail_extra"> <span class="Apple-converted-space"> </span>// add a constant to the variable DIE</div><div class="gmail_extra">}</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">It seems that this way we would be able to do "emit an address, or a constant if optimized away" if we modify clang to emit a single DIGlobalVariable for constant globals with an appropriate initializer, and add it to the list of globals in the DICompileUnit.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">Thanks,</div><div class="gmail_extra">--<span class=""> </span><br class=""><div class=""><div dir="ltr" class="">-- <div class="">Peter</div></div></div></div></div></span><span class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">LLVM Developers mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><a href="mailto:llvm-dev@lists.llvm.org" target="_blank" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class="">llvm-dev@lists.llvm.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></span></div></blockquote></div><br class=""></div></blockquote></div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br clear="all" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div dir="ltr" class="">-- <div class="">Peter</div></div></div></div></blockquote></div><br class=""></body></html>