Skip to content

Commit a93d7f6

Browse files
[llvm-debuginfo-analyzer] Fix crash with WebAssembly dead code
#136772 Incorrect handling of 'tombstone' value for WebAssembly. Address reviewes comments: - Reduce the test case. - Use std::optional to illustrate the set/unset state. - Rebase with main branch.
1 parent a563faa commit a93d7f6

File tree

4 files changed

+30
-338
lines changed

4 files changed

+30
-338
lines changed

llvm/include/llvm/DebugInfo/LogicalView/Core/LVObject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ using LVOffsets = SmallVector<LVOffset, 8>;
9292
// 0xffffffff when the size of an address is 32 bits).
9393
//
9494
// -1 (0xffffffff) => Valid tombstone
95-
// -2 (0xfffffffe) => Undefined tomstone
9695
const LVAddress MaxAddress = std::numeric_limits<uint64_t>::max();
97-
const LVAddress InvalidTombstone = MaxAddress - 1;
9896

9997
enum class LVBinaryType { NONE, ELF, COFF };
10098
enum class LVComparePass { Missing, Added };

llvm/include/llvm/DebugInfo/LogicalView/Core/LVRange.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ class LLVM_ABI LVRange final : public LVObject {
5555
LVAllocator Allocator;
5656
LVRangesTree RangesTree;
5757
LVRangeEntries RangeEntries;
58-
LVAddress TombstoneAddress;
59-
LVAddress Lower;
58+
std::optional<LVAddress> TombstoneAddress;
59+
LVAddress Lower = 0;
6060
LVAddress Upper = 0;
6161

6262
public:
63-
LVRange(LVAddress Address = InvalidTombstone)
63+
LVRange(std::optional<LVAddress> Address = std::nullopt)
6464
: LVObject(), RangesTree(Allocator), TombstoneAddress(Address),
65-
Lower(Address) {}
65+
Lower(Address ? Address.value() : MaxAddress) {}
6666
LVRange(const LVRange &) = delete;
6767
LVRange &operator=(const LVRange &) = delete;
6868
~LVRange() = default;
@@ -79,7 +79,7 @@ class LLVM_ABI LVRange final : public LVObject {
7979

8080
void clear() {
8181
RangeEntries.clear();
82-
Lower = TombstoneAddress;
82+
Lower = TombstoneAddress ? TombstoneAddress.value() : MaxAddress;
8383
Upper = 0;
8484
}
8585
bool empty() const { return RangeEntries.empty(); }

llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class LLVM_ABI LVReader {
157157
LVRange *getSectionRanges(LVSectionIndex SectionIndex);
158158

159159
// The value is updated for each Compile Unit that is processed.
160-
LVAddress TombstoneAddress = InvalidTombstone;
160+
std::optional<LVAddress> TombstoneAddress;
161161

162162
// Record Compilation Unit entry.
163163
void addCompileUnitOffset(LVOffset Offset, LVScopeCompileUnit *CompileUnit) {
@@ -287,8 +287,8 @@ class LLVM_ABI LVReader {
287287

288288
void setTombstoneAddress(LVAddress Address) { TombstoneAddress = Address; }
289289
LVAddress getTombstoneAddress() const {
290-
assert(TombstoneAddress != InvalidTombstone && "Invalid tombstone value");
291-
return TombstoneAddress;
290+
assert(TombstoneAddress && "Unset tombstone value");
291+
return TombstoneAddress.value();
292292
}
293293

294294
// Access to the scopes root.

0 commit comments

Comments
 (0)