[SCCP] Avoid modifying AdditionalUsers while iterating over it
commit6abb92f2103a58d097620b4410054c5bb18c48ec
authorDimitry Andric <dimitry@andric.com>
Sun, 14 Mar 2021 16:41:21 +0000 (14 17:41 +0100)
committerDimitry Andric <dimitry@andric.com>
Fri, 2 Apr 2021 17:05:59 +0000 (2 19:05 +0200)
tree6a3a1a5cfe37ed0b520bdbd0d21c34bd798745df
parent55978f914e88dc12bcc62666128c175c86adfd22
[SCCP] Avoid modifying AdditionalUsers while iterating over it

When run under valgrind, or with a malloc that poisons freed memory,
this can lead to segfaults or other problems.

To avoid modifying the AdditionalUsers DenseMap while still iterating,
save the instructions to be notified in a separate SmallPtrSet, and use
this to later call OperandChangedState on each instruction.

Fixes PR49582.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D98602
llvm/lib/Transforms/Scalar/SCCP.cpp
llvm/test/Transforms/SCCP/pr49582-iterator-invalidation.ll [new file with mode: 0644]