summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/CFLAliasAnalysis.cpp
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2016-05-02 18:09:19 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2016-05-02 18:09:19 +0000
commit6edb891c8efd1fb055ffce6611704da3906d68ec (patch)
treec0ccc5dc752495e3d8189c130fd93365ef600079 /llvm/lib/Analysis/CFLAliasAnalysis.cpp
parent0eace0bae572f667dff0ba7d202f7e211d1b2625 (diff)
downloadbcm5719-llvm-6edb891c8efd1fb055ffce6611704da3906d68ec.tar.gz
bcm5719-llvm-6edb891c8efd1fb055ffce6611704da3906d68ec.zip
[CFLAA] Fix a use-of-invalid-pointer bug.
As shown in the diff, we used to add to CFLAA's cache by doing `Cache[Fn] = buildSetsFrom(Fn)`. `buildSetsFrom(Fn)` may cause `Cache` to reallocate its underlying storage, if this happens and `Cache[Fn]` was evaluated prior to `buildSetsFrom(Fn)`, then we'll store the result to a bad address. Patch by Jia Chen. llvm-svn: 268269
Diffstat (limited to 'llvm/lib/Analysis/CFLAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/CFLAliasAnalysis.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/CFLAliasAnalysis.cpp b/llvm/lib/Analysis/CFLAliasAnalysis.cpp
index 3e3e4989ca6..1a6d87138d4 100644
--- a/llvm/lib/Analysis/CFLAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/CFLAliasAnalysis.cpp
@@ -994,7 +994,12 @@ void CFLAAResult::scan(Function *Fn) {
assert(InsertPair.second &&
"Trying to scan a function that has already been cached");
- Cache[Fn] = buildSetsFrom(Fn);
+ // Note that we can't do Cache[Fn] = buildSetsFrom(Fn) here: the function call
+ // may get evaluated after operator[], potentially triggering a DenseMap
+ // resize and invalidating the reference returned by operator[]
+ auto FunInfo = buildSetsFrom(Fn);
+ Cache[Fn] = std::move(FunInfo);
+
Handles.push_front(FunctionHandle(Fn, this));
}
OpenPOWER on IntegriCloud