This patch fixes several errors found by searching for code that does not correctly handle dbg.values with duplicate operands, such as DIArgList(i32 %a, i32 %a), following from the more specific errors found in D105129.
There are 2 types of errors fixed in this patch:
- The errors in llvm::salvageDebugInfoForDbgValues and HWAddressSanitizer::instrumentStack are caused by applying an update to the dbg.value for only the first instance of a duplicated operand, when the update needs to be applied for each instance.
- The errors in HWAddressSanitizer::sanitizeFunction and AArch64StackTagging::runOnFunction are caused by tracking values in the dbg.value that need to be replaced later, and then trying to replace the duplicated operand multiple times when it should only be replaced once.
In the longer term it will probably be easier to prevent duplicated operands from existing at all, but doing so requires further changes to prevent a DIArgList and its associated DIExpression from falling out of sync with each other. This can mostly be handled in DbgVariableIntrinsic and DIArgList::handleUpdatedOperand, but there are exceptions that may require a design change (such as joining the DIArgList and DIExpression in a single MDNode) to be handled in a generalized manner.
Can we add a comment here by explaining what is the intention of the code below?