Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,14 +1146,16 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
}

llvm::DIType *CGDebugInfo::CreateType(const BitIntType *Ty) {

StringRef Name = Ty->isUnsigned() ? "unsigned _BitInt" : "_BitInt";
SmallString<32> Name;
llvm::raw_svector_ostream OS(Name);
OS << (Ty->isUnsigned() ? "unsigned _BitInt(" : "_BitInt(")
<< Ty->getNumBits() << ")";
llvm::dwarf::TypeKind Encoding = Ty->isUnsigned()
? llvm::dwarf::DW_ATE_unsigned
: llvm::dwarf::DW_ATE_signed;

return DBuilder.createBasicType(Name, CGM.getContext().getTypeSize(Ty),
Encoding);
Encoding, llvm::DINode::FlagZero, 0,
Ty->getNumBits());
}

llvm::DIType *CGDebugInfo::CreateType(const ComplexType *Ty) {
Expand Down
8 changes: 8 additions & 0 deletions clang/test/CodeGen/bit-int.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -x c++ %s -debug-info-kind=standalone -gno-column-info -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 -x c %s -debug-info-kind=standalone -gno-column-info -emit-llvm -o - | FileCheck %s

unsigned _BitInt(17) a;
_BitInt(2) b;

// CHECK: !DIBasicType(name: "_BitInt(2)", size: 8, dataSize: 2, encoding: DW_ATE_signed)
// CHECK: !DIBasicType(name: "unsigned _BitInt(17)", size: 32, dataSize: 17, encoding: DW_ATE_unsigned)
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/CompilerType.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class CompilerType {
std::optional<uint64_t>
GetByteStride(ExecutionContextScope *exe_scope) const;

lldb::Encoding GetEncoding(uint64_t &count) const;
lldb::Encoding GetEncoding() const;

lldb::Format GetFormat() const;

Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ class Type : public std::enable_shared_from_this<Type>, public UserID {

lldb::Format GetFormat();

lldb::Encoding GetEncoding(uint64_t &count);
lldb::Encoding GetEncoding();

SymbolContextScope *GetSymbolContextScope() { return m_context; }
const SymbolContextScope *GetSymbolContextScope() const { return m_context; }
Expand Down
3 changes: 1 addition & 2 deletions lldb/include/lldb/Symbol/TypeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ class TypeSystem : public PluginInterface,
GetByteStride(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) = 0;

virtual lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
uint64_t &count) = 0;
virtual lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type) = 0;

virtual lldb::Format GetFormat(lldb::opaque_compiler_type_t type) = 0;

Expand Down
17 changes: 13 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) {
byte_size = form_value.Unsigned();
break;

case DW_AT_bit_size:
data_bit_size = form_value.Unsigned();
break;

case DW_AT_alignment:
alignment = form_value.Unsigned();
break;
Expand Down Expand Up @@ -839,13 +843,18 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
// there...
[[fallthrough]];

case DW_TAG_base_type:
case DW_TAG_base_type: {
resolve_state = Type::ResolveState::Full;
// If a builtin type's size isn't a multiple of a byte, DWARF producers may
// add a precise bit-size to the type. Use the most precise bit-size
// possible.
const uint64_t bit_size = attrs.data_bit_size
? *attrs.data_bit_size
: attrs.byte_size.value_or(0) * 8;
clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize(
attrs.name.GetStringRef(), attrs.encoding,
attrs.byte_size.value_or(0) * 8);
attrs.name.GetStringRef(), attrs.encoding, bit_size);
break;

}
case DW_TAG_pointer_type:
encoding_data_type = Type::eEncodingIsPointerUID;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ struct ParsedDWARFTypeAttributes {
lldb_private::plugin::dwarf::DWARFFormValue type;
lldb::LanguageType class_language = lldb::eLanguageTypeUnknown;
std::optional<uint64_t> byte_size;
std::optional<uint64_t> data_bit_size;
std::optional<uint64_t> alignment;
size_t calling_convention = llvm::dwarf::DW_CC_normal;
uint32_t bit_stride = 0;
Expand Down
21 changes: 14 additions & 7 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,8 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(

case DW_ATE_signed:
if (!type_name.empty()) {
if (type_name.starts_with("_BitInt"))
return GetType(ast.getBitIntType(/*Unsigned=*/false, bit_size));
if (type_name == "wchar_t" &&
QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy) &&
(getTargetInfo() &&
Expand Down Expand Up @@ -1043,6 +1045,8 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(

case DW_ATE_unsigned:
if (!type_name.empty()) {
if (type_name.starts_with("unsigned _BitInt"))
return GetType(ast.getBitIntType(/*Unsigned=*/true, bit_size));
if (type_name == "wchar_t") {
if (QualTypeMatchesBitSize(bit_size, ast, ast.WCharTy)) {
if (!(getTargetInfo() &&
Expand Down Expand Up @@ -3925,6 +3929,13 @@ TypeSystemClang::GetTypeInfo(lldb::opaque_compiler_type_t type,
->getModifiedType()
.getAsOpaquePtr(),
pointee_or_element_clang_type);
case clang::Type::BitInt: {
uint32_t type_flags = eTypeIsScalar | eTypeIsInteger | eTypeHasValue;
if (qual_type->isSignedIntegerType())
type_flags |= eTypeIsSigned;

return type_flags;
}
case clang::Type::Builtin: {
const clang::BuiltinType *builtin_type =
llvm::cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
Expand Down Expand Up @@ -4955,12 +4966,10 @@ TypeSystemClang::GetTypeBitAlign(lldb::opaque_compiler_type_t type,
return {};
}

lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
uint64_t &count) {
lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type) {
if (!type)
return lldb::eEncodingInvalid;

count = 1;
clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));

switch (qual_type->getTypeClass()) {
Expand Down Expand Up @@ -4996,7 +5005,6 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
case clang::Type::DependentVector:
case clang::Type::ExtVector:
case clang::Type::Vector:
// TODO: Set this to more than one???
break;

case clang::Type::BitInt:
Expand Down Expand Up @@ -5196,11 +5204,10 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
const clang::ComplexType *complex_type =
qual_type->getAsComplexIntegerType();
if (complex_type)
encoding = GetType(complex_type->getElementType()).GetEncoding(count);
encoding = GetType(complex_type->getElementType()).GetEncoding();
else
encoding = lldb::eEncodingSint;
}
count = 2;
return encoding;
}

Expand Down Expand Up @@ -5256,7 +5263,7 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
case clang::Type::HLSLInlineSpirv:
break;
}
count = 0;

return lldb::eEncodingInvalid;
}

Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,7 @@ class TypeSystemClang : public TypeSystem {
return {};
}

lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
uint64_t &count) override;
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type) override;

lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;

Expand Down
7 changes: 2 additions & 5 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6775,11 +6775,9 @@ SwiftASTContext::GetTypeBitAlign(opaque_compiler_type_t type,
return {};
}

lldb::Encoding SwiftASTContext::GetEncoding(opaque_compiler_type_t type,
uint64_t &count) {
lldb::Encoding SwiftASTContext::GetEncoding(opaque_compiler_type_t type) {
VALID_OR_RETURN_CHECK_TYPE(type, lldb::eEncodingInvalid);

count = 1;
swift::CanType swift_can_type(GetCanonicalSwiftType(type));

const swift::TypeKind type_kind = swift_can_type->getKind();
Expand Down Expand Up @@ -6842,7 +6840,7 @@ lldb::Encoding SwiftASTContext::GetEncoding(opaque_compiler_type_t type,
case swift::TypeKind::UnownedStorage:
case swift::TypeKind::WeakStorage:
return ToCompilerType(swift_can_type->getReferenceStorageReferent())
.GetEncoding(count);
.GetEncoding();
break;

case swift::TypeKind::ExistentialMetatype:
Expand Down Expand Up @@ -6877,7 +6875,6 @@ lldb::Encoding SwiftASTContext::GetEncoding(opaque_compiler_type_t type,
assert(false && "Not a canonical type");
break;
}
count = 0;
return lldb::eEncodingInvalid;
}

Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,7 @@ class SwiftASTContext : public TypeSystemSwift {
GetByteStride(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) override;

lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
uint64_t &count) override;
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type) override;

llvm::Expected<uint32_t>
GetNumChildren(lldb::opaque_compiler_type_t type,
Expand Down
19 changes: 5 additions & 14 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4016,14 +4016,12 @@ TypeSystemSwiftTypeRef::GetByteStride(opaque_compiler_type_t type,
(ReconstructType(type, exe_scope), exe_scope));
}

lldb::Encoding TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type,
uint64_t &count) {
lldb::Encoding
TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type) {
auto impl = [&]() -> lldb::Encoding {
if (!type)
return lldb::eEncodingInvalid;

count = 1;

using namespace swift::Demangle;
Demangler dem;
auto *node = DemangleCanonicalOutermostType(dem, type);
Expand All @@ -4045,13 +4043,10 @@ lldb::Encoding TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type,
node->getText() == swift::BUILTIN_TYPE_NAME_BRIDGEOBJECT ||
node->getText() == swift::BUILTIN_TYPE_NAME_RAWUNSAFECONTINUATION)
return lldb::eEncodingUint;
if (node->getText().starts_with(swift::BUILTIN_TYPE_NAME_VEC)) {
count = 0;
if (node->getText().starts_with(swift::BUILTIN_TYPE_NAME_VEC))
return lldb::eEncodingInvalid;
}

assert(false && "Unhandled builtin");
count = 0;
return lldb::eEncodingInvalid;
}

Expand All @@ -4077,23 +4072,19 @@ lldb::Encoding TypeSystemSwiftTypeRef::GetEncoding(opaque_compiler_type_t type,
const auto *mangled_name = AsMangledName(type);
auto flavor = SwiftLanguageRuntime::GetManglingFlavor(mangled_name);
auto referent_type = RemangleAsType(dem, referent_node, flavor);
return referent_type.GetEncoding(count);
return referent_type.GetEncoding();
}
default:
LLDB_LOGF(GetLog(LLDBLog::Types), "No encoding for type %s",
AsMangledName(type));
break;
}

count = 0;
return lldb::eEncodingInvalid;
};

#ifndef NDEBUG
uint64_t validation_count = 0;
#endif
VALIDATE_AND_RETURN(impl, GetEncoding, type, g_no_exe_ctx,
(ReconstructType(type), validation_count));
(ReconstructType(type)));
}

llvm::Expected<uint32_t>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
std::optional<uint64_t>
GetByteStride(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) override;
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
uint64_t &count) override;
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type) override;
llvm::Expected<uint32_t>
GetNumChildren(lldb::opaque_compiler_type_t type,
bool omit_empty_base_classes,
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Symbol/CompilerType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,10 @@ CompilerType::GetTypeBitAlign(ExecutionContextScope *exe_scope) const {
return {};
}

lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const {
lldb::Encoding CompilerType::GetEncoding() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetEncoding(m_type, count);
return type_system_sp->GetEncoding(m_type);
return lldb::eEncodingInvalid;
}

Expand Down Expand Up @@ -1146,10 +1146,10 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
if (0 == (GetTypeInfo() & eTypeHasValue)) {
return false; // Aggregate types don't have scalar values
} else {
uint64_t count = 0;
lldb::Encoding encoding = GetEncoding(count);
// FIXME: check that type is scalar instead of checking encoding?
lldb::Encoding encoding = GetEncoding();

if (encoding == lldb::eEncodingInvalid || count != 1)
if (encoding == lldb::eEncodingInvalid || (GetTypeInfo() & eTypeIsComplex))
return false;

auto byte_size_or_err = GetByteSize(exe_scope);
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Symbol/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,9 @@ lldb::TypeSP Type::GetTypedefType() {

lldb::Format Type::GetFormat() { return GetForwardCompilerType().GetFormat(); }

lldb::Encoding Type::GetEncoding(uint64_t &count) {
lldb::Encoding Type::GetEncoding() {
// Make sure we resolve our type if it already hasn't been.
return GetForwardCompilerType().GetEncoding(count);
return GetForwardCompilerType().GetEncoding();
}

bool Type::ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t addr,
Expand Down
6 changes: 2 additions & 4 deletions lldb/source/ValueObject/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,7 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) {
return false;
}

uint64_t count = 0;
const Encoding encoding = GetCompilerType().GetEncoding(count);
const Encoding encoding = GetCompilerType().GetEncoding();

const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0);

Expand Down Expand Up @@ -1679,8 +1678,7 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) {
return false;
}

uint64_t count = 0;
const Encoding encoding = GetCompilerType().GetEncoding(count);
const Encoding encoding = GetCompilerType().GetEncoding();

const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0);

Expand Down
Loading