Analysis: Remove implicit ilist iterator conversions
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 10 Oct 2015 00:53:03 +0000 (00:53 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 10 Oct 2015 00:53:03 +0000 (00:53 +0000)
commitd3a5adc5ba41464aadb5e046e29127b849f163fc
tree1fd82b81f0fb716cc25bcc4eb08757959e1cdbc2
parentf2e1e0eaf4ae600b2158fe785f1ba2d91734b006
Analysis: Remove implicit ilist iterator conversions

Remove implicit ilist iterator conversions from LLVMAnalysis.

I came across something really scary in `llvm::isKnownNotFullPoison()`
which relied on `Instruction::getNextNode()` being completely broken
(not surprising, but scary nevertheless).  This function is documented
(and coded to) return `nullptr` when it gets to the sentinel, but with
an `ilist_half_node` as a sentinel, the sentinel check looks into some
other memory and we don't recognize we've hit the end.

Rooting out these scary cases is the reason I'm removing the implicit
conversions before doing anything else with `ilist`; I'm not at all
surprised that clients rely on badness.

I found another scary case -- this time, not relying on badness, just
bad (but I guess getting lucky so far) -- in
`ObjectSizeOffsetEvaluator::compute_()`.  Here, we save out the
insertion point, do some things, and then restore it.  Previously, we
let the iterator auto-convert to `Instruction*`, and then set it back
using the `Instruction*` version:

    Instruction *PrevInsertPoint = Builder.GetInsertPoint();

    /* Logic that may change insert point */

    if (PrevInsertPoint)
      Builder.SetInsertPoint(PrevInsertPoint);

The check for `PrevInsertPoint` doesn't protect correctly against bad
accesses.  If the insertion point has been set to the end of a basic
block (i.e., `SetInsertPoint(SomeBB)`), then `GetInsertPoint()` returns
an iterator pointing at the list sentinel.  The version of
`SetInsertPoint()` that's getting called will then call
`PrevInsertPoint->getParent()`, which explodes horribly.  The only
reason this hasn't blown up is that it's fairly unlikely the builder is
adding to the end of the block; usually, we're adding instructions
somewhere before the terminator.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249925 91177308-0d34-0410-b5e6-96231b3b80d8
22 files changed:
lib/Analysis/AliasAnalysis.cpp
lib/Analysis/AliasAnalysisEvaluator.cpp
lib/Analysis/AliasSetTracker.cpp
lib/Analysis/BasicAliasAnalysis.cpp
lib/Analysis/BlockFrequencyInfo.cpp
lib/Analysis/BranchProbabilityInfo.cpp
lib/Analysis/CFG.cpp
lib/Analysis/CodeMetrics.cpp
lib/Analysis/CostModel.cpp
lib/Analysis/DivergenceAnalysis.cpp
lib/Analysis/IVUsers.cpp
lib/Analysis/InlineCost.cpp
lib/Analysis/Lint.cpp
lib/Analysis/Loads.cpp
lib/Analysis/LoopAccessAnalysis.cpp
lib/Analysis/MemoryBuiltins.cpp
lib/Analysis/MemoryDependenceAnalysis.cpp
lib/Analysis/ObjCARCInstKind.cpp
lib/Analysis/ScalarEvolutionExpander.cpp
lib/Analysis/ScalarEvolutionNormalization.cpp
lib/Analysis/SparsePropagation.cpp
lib/Analysis/ValueTracking.cpp