This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Correctly handle arrays with 0-width elements in GEP salvaging
ClosedPublic

Authored by StephenTozer on Oct 14 2021, 8:01 AM.

Details

Summary

Fixes a bug observed here: https://reviews.llvm.org/rGc72705678c47#inline-6620

Currently when salvaging a GEP instruction, we calculate variable offsets (such as %offset in getelementptr inbounds %struct.S, %struct.S* %ptr, i64 %offset) by appending {<var>, DW_OP_constu, <type-width>, DW_OP_mul, DW_OP_plus} to the existing expression, or in otherwords adding ... + (<var> * <type-width>). When calculating variable offsets however, we make no special allowances for variable offsets where the type-width is 0; such an offset will always be 0 and hence a no-op that needlessly lengthens the DIExpression and adds a new argument (potentially causing the dbg.value to start using a DIArgList).

This patch fixes this issue by ignoring these always-0 offsets. It also fixes a bug (linked above) where an assertion assert(Offset.second.isStrictlyPositive()) would trigger in the above case, causing a crash for valid code.

Diff Detail

Event Timeline

StephenTozer created this revision.Oct 14 2021, 8:01 AM
StephenTozer requested review of this revision.Oct 14 2021, 8:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2021, 8:01 AM

Can't say much besides that it makes sense to fix the problem at the source (and not appending to the list) instead of simply weakening the assert.

aprantl accepted this revision.Oct 15 2021, 11:22 AM
This revision is now accepted and ready to land.Oct 15 2021, 11:22 AM
This revision was landed with ongoing or failed builds.Oct 18 2021, 4:19 AM
This revision was automatically updated to reflect the committed changes.