diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -462,8 +462,17 @@ auto Index = getContributionIndex(Kind); if (Kind != DW_SECT_EXT_TYPES) { CurEntry.Contributions[Index].Offset = ContributionOffsets[Index]; - ContributionOffsets[Index] += - (CurEntry.Contributions[Index].Length = Contents.size()); + APInt Offset{32, ContributionOffsets[Index], false}; + APInt NewLength{ + 32, CurEntry.Contributions[Index].Length = Contents.size(), false}; + bool Overflow = false; + APInt NewOffset = Offset.uadd_ov(NewLength, Overflow); + if (Overflow) { + std::string SectionName = SectionPair->first().str(); + return make_error( + std::string("Section size overflow in " + SectionName)); + } + ContributionOffsets[Index] = NewOffset.getLimitedValue(); } switch (Kind) {