getAnalysisUsage(), instead of triggering an appropriate
error message, a double delete of the pass happens.
This patch prevents that double free by moving the delete point around.
This also ensures that a helpful assert (which already exists) is triggered
instead.
Unfortunately, there are other issues exposed by this patch.
Because the Legacy Pass Manager's ModulePass is itself not heavily exercised in LLVM, and the required ImmutablePass's (such as DataLayout) are not properly propagated over to the other Analysis passes (e.g. ScalarEvolution gets a NULL DataLayout)
Even though the ModulePass gets the "proper" DataLayout, when it does a getAnalysis<ScalarEvolution>(), the DataLayout instance returned to ScalarEvolution::runOnFunctiion() is NULL.
This problem persists onto the other analysis passes (such as DependenceAnalysis - i.e. it always results in MayAlias being produced)..
Apologies for the delay in posting this patch.