[all-commits] [llvm/llvm-project] 70982e: [clang] Add clang::preferred_type attribute for bi...

Vlad Serebrennikov via All-commits all-commits at lists.llvm.org
Mon Oct 23 11:22:14 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 70982ef9d17ce57909ab202dc0850182b29c7da1
      https://github.com/llvm/llvm-project/commit/70982ef9d17ce57909ab202dc0850182b29c7da1
  Author: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
  Date:   2023-10-23 (Mon, 23 Oct 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Basic/AttrDocs.td
    M clang/include/clang/Basic/DiagnosticGroups.td
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/CodeGen/CGDebugInfo.cpp
    M clang/lib/Sema/SemaDeclAttr.cpp
    A clang/test/CodeGen/debug-info-preferred-type.cpp
    A clang/test/Sema/attr-preferred-type.cpp

  Log Message:
  -----------
  [clang] Add clang::preferred_type attribute for bitfields (#69104)

This attribute allows user to specify type of the bitfield that will be
emitted to debug info without affecting semantics of the program. Since
it doesn't affect semantics, this attribute can be safely ignored by
other compilers.

This is useful when user is forced to use the same type for all
bitfields in a class to get better
[layout](https://godbolt.org/z/ovWqzqv9x) and
[codegen](https://godbolt.org/z/bdoqvz9e6) from MSVC, because it allows
debuggers to interpret the value of bitfield in the most human-friendly
way (e.g. when value actually comes from an enum). This is driven by my
work on LLDB formatters for Clang. I have two use cases for this:
```cpp
namespace Clang {
class Type {
  enum TypeClass { ... };
  struct TypeBitfields {
    [[clang::preferred_type(clang::Type::TypeClass)]] unsigned TC: 8;
    [[clang::preferred_type(bool)]] mutable unsigned FromAST : 1;
  };
};
}
```




More information about the All-commits mailing list