forked from OSchip/llvm-project
fix insertion of values in BBMap
In GDB when "step" through generateScalarLoad and "finish" the call, the returned value is non NULL, however when printing the value contained in BBMap[Load] after this stmt: BBMap[Load] = generateScalarLoad(...); the value in BBMap[Load] is NULL, and the BBMap.count(Load) is 1. The only intuitive idea that I have to explain this behavior is that we are playing with the undefined behavior of eval order of the params for the function standing for "BBMap[Load] = generateScalarLoad()". "BBMap[Load] = " may be executed before generateScalarLoad is called. Here are some other possible explanations from Will Dietz <w@wdtz.org>: The error is likely due to BBMap[Load] being evaluated first (creating a {Load -> uninitialized } entry in the DenseMap), then generateScalarLoad eventually accesses the same element and finds it to be NULL (DenseMap[Old]).. Offhand I'm not sure if this is guaranteed to be NULL or if it's uninitialized and happens to be NULL. The same issue can also go wrong in an even worse way: the second DenseMap access can trigger a rehash and *invalidate* the an earlier evaluated expression (for example LHS of the assignment), leading to a crash when performing the assignment store. llvm-svn: 182655
This commit is contained in:
parent
c2c4467690
commit
753d43f974
|
@ -185,6 +185,7 @@ Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
|
|||
}
|
||||
|
||||
if (BBMap.count(Old)) {
|
||||
assert(BBMap[Old] && "BBMap[Old] should not be NULL!");
|
||||
return BBMap[Old];
|
||||
}
|
||||
|
||||
|
@ -354,12 +355,14 @@ void BlockGenerator::copyInstruction(const Instruction *Inst, ValueMapT &BBMap,
|
|||
return;
|
||||
|
||||
if (const LoadInst *Load = dyn_cast<LoadInst>(Inst)) {
|
||||
BBMap[Load] = generateScalarLoad(Load, BBMap, GlobalMap, LTS);
|
||||
Value *NewLoad = generateScalarLoad(Load, BBMap, GlobalMap, LTS);
|
||||
BBMap[Load] = NewLoad;
|
||||
return;
|
||||
}
|
||||
|
||||
if (const StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
|
||||
BBMap[Store] = generateScalarStore(Store, BBMap, GlobalMap, LTS);
|
||||
Value *NewStore = generateScalarStore(Store, BBMap, GlobalMap, LTS);
|
||||
BBMap[Store] = NewStore;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue