Skip to content

Commit 3e45e3b

Browse files
committed
[Core] Use GetAPInt instead of constructing APInts in place
GetAPInt should be able to handle all cases. I have plans to generalize the float dumping logic and this makes it easier to do later. llvm-svn: 370255
1 parent 7080ffa commit 3e45e3b

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lldb/source/Core/DumpDataExtractor.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,13 @@ lldb::offset_t lldb_private::DumpDataExtractor(
567567
size_t item_bit_size = item_byte_size * 8;
568568

569569
if (item_bit_size == ast->getTypeSize(ast->FloatTy)) {
570-
llvm::APInt apint(item_bit_size,
571-
DE.GetMaxU64(&offset, item_byte_size));
572-
llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->FloatTy),
573-
apint);
574-
apfloat.toString(sv, format_precision, format_max_padding);
570+
llvm::Optional<llvm::APInt> apint =
571+
GetAPInt(DE, &offset, item_byte_size);
572+
if (apint.hasValue()) {
573+
llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->FloatTy),
574+
apint.getValue());
575+
apfloat.toString(sv, format_precision, format_max_padding);
576+
}
575577
} else if (item_bit_size == ast->getTypeSize(ast->DoubleTy)) {
576578
llvm::Optional<llvm::APInt> apint =
577579
GetAPInt(DE, &offset, item_byte_size);
@@ -595,10 +597,13 @@ lldb::offset_t lldb_private::DumpDataExtractor(
595597
apfloat.toString(sv, format_precision, format_max_padding);
596598
}
597599
} else if (item_bit_size == ast->getTypeSize(ast->HalfTy)) {
598-
llvm::APInt apint(item_bit_size, DE.GetU16(&offset));
599-
llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->HalfTy),
600-
apint);
601-
apfloat.toString(sv, format_precision, format_max_padding);
600+
llvm::Optional<llvm::APInt> apint =
601+
GetAPInt(DE, &offset, item_byte_size);
602+
if (apint.hasValue()) {
603+
llvm::APFloat apfloat(ast->getFloatTypeSemantics(ast->HalfTy),
604+
apint.getValue());
605+
apfloat.toString(sv, format_precision, format_max_padding);
606+
}
602607
}
603608

604609
if (!sv.empty()) {

0 commit comments

Comments
 (0)