This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Add DW_AT_byte_size to vectors
ClosedPublic

Authored by mattd on Mar 2 2018, 3:47 PM.

Details

Summary

This patch adds the DW_AT_byte_size dwarf attribute to vectors.
This fixes PR21924

LLVM will round a vector up to the next alignable address, which can result in
the vector's representation in the object file being larger than what the
debugger will calculate via NumberOfElements * ElementSize. In such a case calling sizeof(MyVec) in the source will result in a different value than what a debugger might present. This situation can occur because LLVM permits non-power of two 'vector_size' attributes.

Diff Detail

Repository
rL LLVM

Event Timeline

mattd created this revision.Mar 2 2018, 3:47 PM
aprantl accepted this revision.Mar 2 2018, 4:45 PM

Minor comments inline, but otherwise this seems reasonable. Thanks!

lib/CodeGen/AsmPrinter/DwarfUnit.cpp
1426 ↗(On Diff #136870)

Could you add && "not a subrange" and make sure that the Verifier complains when this condition isn't met?

This revision is now accepted and ready to land.Mar 2 2018, 4:45 PM
probinson added inline comments.
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
1428 ↗(On Diff #136870)

I think get<ConstantInt *> instead of dyn_cast so this will assert if it isn't the right type.

echristo added inline comments.Mar 2 2018, 5:11 PM
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
1428 ↗(On Diff #136870)

Yes, because otherwise you could be grabbing a null pointer as well.

probinson added inline comments.Mar 2 2018, 5:37 PM
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
1428 ↗(On Diff #136870)

I'm not really familiar with PointerUnion; the value can be set but still null? So there needs to be an explicit assert here anyway.

echristo added inline comments.Mar 2 2018, 5:41 PM
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
1428 ↗(On Diff #136870)

dyn_cast returns null if the thing isn't of that type.

mattd updated this revision to Diff 137023.Mar 5 2018, 9:25 AM
mattd marked 2 inline comments as done.

Thanks for the feedback!

  • I made use of the PointerUnion::get() instead of dyn_cast. The former will assert instead of returning null when the item does not exist.
  • Added an assertion message when checking that a vector has a single item in its Elements array (an item of type subrange).
  • I will add a verifier check and accompanying test for the verifier in a separate patch.
This revision was automatically updated to reflect the committed changes.