From 7afc7db7fc807a4a7ee623db491622698e8edcca Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Fri, 15 Sep 2023 09:10:53 +0100 Subject: [Assignment Tracking] Trim assignments for untagged out of bounds stores (#66095) Fixes #65004 by trimming assignments from out of bounds stores (out of bounds of either the base variable or the backing alloca). If there's no overlap at all or the out of bounds access starts at a negative offset from the alloca, the assignment is simply skipped. --- llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp') diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp index 5ef850d..5b569755 100644 --- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp +++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp @@ -1979,20 +1979,23 @@ static AssignmentTrackingLowering::OverlapMap buildOverlapMapAndRecordDeclares( I, Fn.getParent()->getDataLayout())) { // Find markers linked to this alloca. for (DbgAssignIntrinsic *DAI : at::getAssignmentMarkers(Info->Base)) { - // Discard the fragment if it covers the entire variable. - std::optional FragInfo = - [&Info, DAI]() -> std::optional { - DIExpression::FragmentInfo F; - F.OffsetInBits = Info->OffsetInBits; - F.SizeInBits = Info->SizeInBits; - if (auto ExistingFrag = DAI->getExpression()->getFragmentInfo()) - F.OffsetInBits += ExistingFrag->OffsetInBits; - if (auto Sz = DAI->getVariable()->getSizeInBits()) { - if (F.OffsetInBits == 0 && F.SizeInBits == *Sz) - return std::nullopt; - } - return F; - }(); + std::optional FragInfo; + + // Skip this assignment if the affected bits are outside of the + // variable fragment. + if (!at::calculateFragmentIntersect( + I.getModule()->getDataLayout(), Info->Base, + Info->OffsetInBits, Info->SizeInBits, DAI, FragInfo) || + (FragInfo && FragInfo->SizeInBits == 0)) + continue; + + // FragInfo from calculateFragmentIntersect is nullopt if the + // resultant fragment matches DAI's fragment or entire variable - in + // which case copy the fragment info from DAI. If FragInfo is still + // nullopt after the copy it means "no fragment info" instead, which + // is how it is usually interpreted. + if (!FragInfo) + FragInfo = DAI->getExpression()->getFragmentInfo(); DebugVariable DV = DebugVariable(DAI->getVariable(), FragInfo, DAI->getDebugLoc().getInlinedAt()); -- cgit v1.1