[all-commits] [llvm/llvm-project] 67c588: [lldb] Generalize empty record size computation to...

Raphael Isemann via All-commits all-commits at lists.llvm.org
Thu Jul 22 04:31:15 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 67c588c481bb2fb9f72459fbc205c3e1ee8c4b3b
      https://github.com/llvm/llvm-project/commit/67c588c481bb2fb9f72459fbc205c3e1ee8c4b3b
  Author: Raphael Isemann <teemperor at gmail.com>
  Date:   2021-07-22 (Thu, 22 Jul 2021)

  Changed paths:
    M lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    A lldb/test/API/lang/c/sizeof/Makefile
    A lldb/test/API/lang/c/sizeof/TestCSizeof.py
    A lldb/test/API/lang/c/sizeof/main.c
    A lldb/test/API/lang/cpp/sizeof/Makefile
    A lldb/test/API/lang/cpp/sizeof/TestCPPSizeof.py
    A lldb/test/API/lang/cpp/sizeof/main.cpp

  Log Message:
  -----------
  [lldb] Generalize empty record size computation to avoid giving empty C++ structs a size of 0

C doesn't allow empty structs but Clang/GCC support them and give them a size of 0.

LLDB implements this by checking the tag kind and if it's `DW_TAG_structure_type` then
we give it a size of 0 via an empty external RecordLayout. This is done because our
internal TypeSystem is always in C++ mode (which means we would give them a size
of 1).

The current check for when we have this special case is currently too lax as types with
`DW_TAG_structure_type` can also occur in C++ with types defined using the `struct`
keyword. This means that in a C++ program with `struct Empty{};`, LLDB would return
`0` for `sizeof(Empty)` even though the correct size is 1.

This patch removes this special case and replaces it with a generic approach that just
assigns empty structs the byte_size as specified in DWARF. The GCC/Clang special
case is handles as they both emit an explicit `DW_AT_byte_size` of 0. And if another
compiler decides to use a different byte size for this case then this should also be
handled by the same code as long as that information is provided via `DW_AT_byte_size`.

Reviewed By: werat, shafik

Differential Revision: https://reviews.llvm.org/D105471




More information about the All-commits mailing list