forked from OSchip/llvm-project
Relax CFG assertions in UninitializedValuesV2 when
handling pseudo-path sensitivity, and instead use those assertion conditions as dynamic checks. These assertions would be violated when analyzing a CFG where some branches where optimized away during CFG construction because their branch conditions could be trivially determined. llvm-svn: 123943
This commit is contained in:
parent
f07426b40d
commit
cdca8fa97d
|
@ -156,7 +156,7 @@ static BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) {
|
||||||
llvm::BitVector &CFGBlockValues::getBitVector(const CFGBlock *block,
|
llvm::BitVector &CFGBlockValues::getBitVector(const CFGBlock *block,
|
||||||
const CFGBlock *dstBlock) {
|
const CFGBlock *dstBlock) {
|
||||||
unsigned idx = block->getBlockID();
|
unsigned idx = block->getBlockID();
|
||||||
if (dstBlock && block->succ_size() == 2) {
|
if (dstBlock && block->succ_size() == 2 && block->pred_size() == 2) {
|
||||||
assert(block->getTerminator());
|
assert(block->getTerminator());
|
||||||
if (getLogicalOperatorInChain(block)) {
|
if (getLogicalOperatorInChain(block)) {
|
||||||
if (*block->succ_begin() == dstBlock)
|
if (*block->succ_begin() == dstBlock)
|
||||||
|
@ -460,10 +460,8 @@ static bool runOnBlock(const CFGBlock *block, const CFG &cfg,
|
||||||
UninitVariablesHandler *handler = 0) {
|
UninitVariablesHandler *handler = 0) {
|
||||||
|
|
||||||
if (const BinaryOperator *b = getLogicalOperatorInChain(block)) {
|
if (const BinaryOperator *b = getLogicalOperatorInChain(block)) {
|
||||||
assert(block->pred_size() == 2);
|
if (block->pred_size() == 2 && block->succ_size() == 2) {
|
||||||
assert(block->succ_size() == 2);
|
|
||||||
assert(block->getTerminatorCondition() == b);
|
assert(block->getTerminatorCondition() == b);
|
||||||
|
|
||||||
BVPair valsAB = vals.getPredBitVectors(block);
|
BVPair valsAB = vals.getPredBitVectors(block);
|
||||||
vals.mergeIntoScratch(*valsAB.first, true);
|
vals.mergeIntoScratch(*valsAB.first, true);
|
||||||
vals.mergeIntoScratch(*valsAB.second, false);
|
vals.mergeIntoScratch(*valsAB.second, false);
|
||||||
|
@ -475,6 +473,7 @@ static bool runOnBlock(const CFGBlock *block, const CFG &cfg,
|
||||||
}
|
}
|
||||||
return vals.updateBitVectors(block, valsAB);
|
return vals.updateBitVectors(block, valsAB);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Default behavior: merge in values of predecessor blocks.
|
// Default behavior: merge in values of predecessor blocks.
|
||||||
vals.resetScratch();
|
vals.resetScratch();
|
||||||
|
|
|
@ -13,3 +13,31 @@ int test2_aux() {
|
||||||
return x; // no-warning
|
return x; // no-warning
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle cases where the CFG may constant fold some branches, thus
|
||||||
|
// mitigating the need for some path-sensitivity in the analysis.
|
||||||
|
unsigned test3_aux();
|
||||||
|
unsigned test3() {
|
||||||
|
unsigned x = 0;
|
||||||
|
const bool flag = true;
|
||||||
|
if (flag && (x = test3_aux()) == 0) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
unsigned test3_b() {
|
||||||
|
unsigned x ;
|
||||||
|
const bool flag = true;
|
||||||
|
if (flag && (x = test3_aux()) == 0) {
|
||||||
|
x = 1;
|
||||||
|
}
|
||||||
|
return x; // no-warning
|
||||||
|
}
|
||||||
|
unsigned test3_c() {
|
||||||
|
unsigned x ;
|
||||||
|
const bool flag = false;
|
||||||
|
if (flag && (x = test3_aux()) == 0) {
|
||||||
|
x = 1;
|
||||||
|
}
|
||||||
|
return x; // expected-warning{{use of uninitialized variable 'x'}}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue