This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Prevent error when updating location operands for a dbg.value
ClosedPublic

Authored by StephenTozer on Jun 29 2021, 9:27 AM.

Details

Summary

This patch fixes the issue observed at https://bugs.chromium.org/p/chromium/issues/detail?id=1224338, mentioned in D91722.

The above issue occurs in CodeGenPrepare::fixupDbgValue, where we attempt to update the location operands of a dbg.value. The error occurs when the dbg.value uses a DIArgList that contains the same value multiple times; currently the update is performed by iterating over the location operands, and updating them within that loop by calling replaceVariableLocationOp, which invalidates the iterator; specifically, it continues to point to the old list of values, and so the loop attempts to replace the same value again when it isn't present in the list anymore, resulting in the observed error.

This has been fixed by first collecting the dbg.value's location operands into a set and then iterating over that, ensuring that we don't invalidate our loop iterator or attempt to replace a non-existing operand. Upon investigating, I discovered that the same issue exists in HWAddressSanitizer::sanitizeFunction, and have added the same fix as part of this patch.

Diff Detail

Event Timeline

StephenTozer created this revision.Jun 29 2021, 9:27 AM
StephenTozer requested review of this revision.Jun 29 2021, 9:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2021, 9:27 AM

I don't know this code so I can't comment on the patch, but it'd be good to add a test :)

Add simple test to check for crashes in CodeGenPrepare.

This LGTM.

Do we need a test for the HWAddressSanitizer as well?

Do we need a test for the HWAddressSanitizer as well?

Probably, I checked to see if there's an existing test that can be adapted but it looks as though this block for handling debug info specifically is untested at the moment.

Do we need a test for the HWAddressSanitizer as well?

Probably, I checked to see if there's an existing test that can be adapted but it looks as though this block for handling debug info specifically is untested at the moment.

Oh, I see... If you don't mind, I'd vote for adding a test for it as well. :)

Added test for the HWAddressSanitizer side of the fix.

djtodoro accepted this revision.Jul 5 2021, 1:37 AM

Thanks!

This revision is now accepted and ready to land.Jul 5 2021, 1:37 AM