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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct t12 {

template <decltype(ns::AnonEnum1)> void f10() {}

template <typename T, T V> void f11() {}

int main() {
struct {
} A;
Expand Down Expand Up @@ -239,8 +241,10 @@ int main() {
f1<void(t8)>();
operator_not_really<int>();
t12 v4;
f1<_BitInt(3)>();
f1<const unsigned _BitInt(5)>();
f11<_BitInt(3), 2>();
f11<const unsigned _BitInt(5), 2>();
f11<_BitInt(65), 2>();
f11<const unsigned _BitInt(65), 2>();
f1<void(t1<>, t1<>)>();
f1<int t1<>::*>();
void fcc() __attribute__((swiftcall));
Expand Down
43 changes: 39 additions & 4 deletions llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ template <typename DieType> struct DWARFTypePrinter {
}
return false;
}

/// If FormValue is a valid constant Form, print into \c OS the integral value
/// casted to the type referred to by \c Cast.
template <typename FormValueType>
void appendCastedValue(const FormValueType &FormValue, DieType Cast,
bool IsUnsigned);
};

template <typename DieType>
Expand Down Expand Up @@ -413,6 +419,31 @@ DieType DWARFTypePrinter<DieType>::appendQualifiedNameBefore(DieType D) {
return appendUnqualifiedNameBefore(D);
}

template <typename DieType>
template <typename FormValueType>
void DWARFTypePrinter<DieType>::appendCastedValue(
const FormValueType &FormValue, DieType Cast, bool IsUnsigned) {
std::string ValStr;
if (IsUnsigned) {
std::optional<uint64_t> UVal = FormValue.getAsUnsignedConstant();
if (!UVal)
return;

ValStr = std::to_string(*UVal);
} else {
std::optional<int64_t> SVal = FormValue.getAsSignedConstant();
if (!SVal)
return;

ValStr = std::to_string(*SVal);
}

OS << '(';
appendQualifiedName(Cast);
OS << ')';
OS << std::move(ValStr);
}

template <typename DieType>
bool DWARFTypePrinter<DieType>::appendTemplateParameters(DieType D,
bool *FirstParameter) {
Expand All @@ -438,13 +469,11 @@ bool DWARFTypePrinter<DieType>::appendTemplateParameters(DieType D,
DieType T = detail::resolveReferencedType(C);
Sep();
if (T.getTag() == dwarf::DW_TAG_enumeration_type) {
OS << '(';
appendQualifiedName(T);
OS << ')';
auto V = C.find(dwarf::DW_AT_const_value);
OS << std::to_string(*V->getAsSignedConstant());
appendCastedValue(*V, T, /*IsUnsigned=*/false);
continue;
}

// /Maybe/ we could do pointer/reference type parameters, looking for the
// symbol in the ELF symbol table to get back to the variable...
// but probably not worth it.
Expand Down Expand Up @@ -539,6 +568,12 @@ bool DWARFTypePrinter<DieType>::appendTemplateParameters(DieType D,
else
OS << llvm::format("'\\U%08" PRIx64 "'", Val);
}
// FIXME: Handle _BitInt's larger than 64-bits which are emitted as
// block data.
} else if (Name.starts_with("_BitInt")) {
appendCastedValue(*V, T, /*IsUnsigned=*/false);
} else if (Name.starts_with("unsigned _BitInt")) {
appendCastedValue(*V, T, /*IsUnsigned=*/true);
}
continue;
}
Expand Down
Loading
Loading