[DebugInfo] CGP+HWasan: Handle dbg.values with duplicate location ops
authorStephen Tozer <Stephen.Tozer@Sony.com>
Mon, 5 Jul 2021 08:45:08 +0000 (09:45 +0100)
committerStephen Tozer <Stephen.Tozer@Sony.com>
Mon, 5 Jul 2021 09:35:19 +0000 (10:35 +0100)
commit14b62f7e2f07db548779fc17550a5265ef374413
tree483edf1514b2190bbaef07028f4e8b1498ec1cd7
parentb8173c317812a51354e2874ee6dd5c3150d98ac8
[DebugInfo] CGP+HWasan: Handle dbg.values with duplicate location ops

This patch fixes an issue which occurred in CodeGenPrepare and
HWAddressSanitizer, which both at some point create a map of Old->New
instructions and update dbg.value uses of these. They did this by
iterating over the dbg.value's location operands, and if an instance of
the old instruction was found, replaceVariableLocationOp would be
called on that dbg.value. This would cause an error if the same operand
appeared multiple times as a location operand, as the first call to
replaceVariableLocationOp would update all uses of the old instruction,
invalidating the old iterator and eventually hitting an assertion.

This has been fixed by no longer iterating over the dbg.value's location
operands directly, but by first collecting them into a set and then
iterating over that, ensuring that we never attempt to replace a
duplicated operand multiple times.

Differential Revision: https://reviews.llvm.org/D105129
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
llvm/test/DebugInfo/X86/codegenprep-addrsink.ll
llvm/test/Instrumentation/HWAddressSanitizer/alloca.ll