UseListOrder: Correctly count the number of uses
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 16 Aug 2014 01:54:34 +0000 (01:54 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 16 Aug 2014 01:54:34 +0000 (01:54 +0000)
This is an off-by-one bug I found by inspection, which would only
trigger if the bitcode writer sees more uses of a `Value` than the
reader.  Since this is only relevant when an instruction gets upgraded
somehow, there unfortunately isn't a reasonable way to add test
coverage.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215804 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp

index 79085248770663705fe49b3098639fc9b4d1e0b0..66426c83c6693e68aa2307ce332e740933367da7 100644 (file)
@@ -1697,9 +1697,9 @@ std::error_code BitcodeReader::ParseUseLists() {
       unsigned NumUses = 0;
       SmallDenseMap<const Use *, unsigned, 16> Order;
       for (const Use &U : V->uses()) {
-        if (NumUses > Record.size())
+        if (++NumUses > Record.size())
           break;
-        Order[&U] = Record[NumUses++];
+        Order[&U] = Record[NumUses - 1];
       }
       if (Order.size() != Record.size() || NumUses > Record.size())
         // Mismatches can happen if the functions are being materialized lazily