<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 14, 2016 at 1:51 PM Greg Clayton via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">clayborg created this revision.<br class="gmail_msg">
clayborg added reviewers: aprantl, dblaikie, echristo, probinson, llvm-commits.<br class="gmail_msg">
Herald added subscribers: jgosnell, mehdi_amini.<br class="gmail_msg">
<br class="gmail_msg">
When getting attributes it is sometimes nicer to use Optional<T> some of the time instead of magic values. I tried to cut over to only using the Optional values but it made many of the call sites very messy, so it makes sense the leave in the calls that can return a default value. Otherwise code that looks like this:<br class="gmail_msg">
<br class="gmail_msg">
uint64_t CallColumn = Die.getAttributeValueAsAddress(DW_AT_call_line, 0);<br class="gmail_msg">
<br class="gmail_msg">
Has to be turned into:<br class="gmail_msg">
<br class="gmail_msg">
uint64_t CallColumn = 0;<br class="gmail_msg">
if (auto CallColumnValue = Die.getAttributeValueAsAddress(DW_AT_call_line))<br class="gmail_msg">
CallColumn = *CallColumnValue;<br class="gmail_msg"></blockquote><div><br></div><div>We could have a utility for this - either in Optional, or as a free function, so could write it as something like this:<br><br>auto CallColumn = Die.getAttributeValueAsAddress(DW_AT_call_line).withDefault(0);<br><br>for example.<br><br>(actually, since we'll probably want to migrate from llvm::Optional to std::optional one day (when we get it, etc) - probably best to keep it as a non-member:<br><br>= withDefault(..., 0);<br><br>)<br><br>Don't have to - just a thought.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="gmail_msg">
The first snippet of code looks much better. But in cases where you want an offset that may or may not be there, the following code looks better:<br class="gmail_msg">
<br class="gmail_msg">
if (auto StmtOffset = Die.getAttributeValueAsSectionOffset(DW_AT_stmt_list)) {<br class="gmail_msg">
// Use StmtOffset<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://reviews.llvm.org/D27772" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D27772</a><br class="gmail_msg">
<br class="gmail_msg">
Files:<br class="gmail_msg">
include/llvm/DebugInfo/DWARF/DWARFDie.h<br class="gmail_msg">
include/llvm/DebugInfo/DWARF/DWARFUnit.h<br class="gmail_msg">
lib/DebugInfo/DWARF/DWARFContext.cpp<br class="gmail_msg">
lib/DebugInfo/DWARF/DWARFDie.cpp<br class="gmail_msg">
lib/DebugInfo/DWARF/DWARFUnit.cpp<br class="gmail_msg">
tools/dsymutil/DwarfLinker.cpp<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>