[PATCH] D27772: Add the ability to get attribute values as Optional<T>

Greg Clayton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 13:51:33 PST 2016


clayborg created this revision.
clayborg added reviewers: aprantl, dblaikie, echristo, probinson, llvm-commits.
Herald added subscribers: jgosnell, mehdi_amini.

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:

  uint64_t CallColumn = Die.getAttributeValueAsAddress(DW_AT_call_line, 0);

Has to be turned into:

  uint64_t CallColumn = 0;
  if (auto CallColumnValue = Die.getAttributeValueAsAddress(DW_AT_call_line))
      CallColumn = *CallColumnValue;

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:

  if (auto StmtOffset = Die.getAttributeValueAsSectionOffset(DW_AT_stmt_list)) {
    // Use StmtOffset
  }


https://reviews.llvm.org/D27772

Files:
  include/llvm/DebugInfo/DWARF/DWARFDie.h
  include/llvm/DebugInfo/DWARF/DWARFUnit.h
  lib/DebugInfo/DWARF/DWARFContext.cpp
  lib/DebugInfo/DWARF/DWARFDie.cpp
  lib/DebugInfo/DWARF/DWARFUnit.cpp
  tools/dsymutil/DwarfLinker.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27772.81460.patch
Type: text/x-patch
Size: 19323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161214/fbb94d1b/attachment.bin>


More information about the llvm-commits mailing list