]> granicus.if.org Git - llvm/commit
UseListOrder: Fix undefined behaviour
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 30 Jul 2014 01:20:26 +0000 (01:20 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 30 Jul 2014 01:20:26 +0000 (01:20 +0000)
commitc128f3b34ceac52bd3b0e2473dbb2b27a0091fbf
tree00ba9f0a56b4538f096e514f18f6804c28a2e52a
parent8ad24437bd7d84fc8ffc5e83d37bd67dc50733f0
UseListOrder: Fix undefined behaviour

This commit fixes undefined behaviour that caused the revert in r214249.

The problem was two unsequenced operations on a `DenseMap<>`, giving
different behaviour in GCC and Clang.  This:

    DenseMap<T*, unsigned> DM;
    for (auto &X : ...)
      DM[&X] = DM.size() + 1;

should have been:

    DenseMap<T*, unsigned> DM;
    for (auto &X : ...) {
      unsigned Size = DM.size();
      DM[&X] = Size + 1;
    }

Until r214242, this difference between compilers didn't matter.  In
r214242, `OrderMap::LastGlobalValueID` was introduced and compared
against IDs, which in GCC were off-by-one my expectations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214270 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Bitcode/Writer/ValueEnumerator.cpp