[cfe-commits] r123943 - in /cfe/trunk: lib/Analysis/UninitializedValuesV2.cpp test/SemaCXX/uninit-variables.cpp
Ted Kremenek
kremenek at apple.com
Thu Jan 20 13:25:31 PST 2011
Author: kremenek
Date: Thu Jan 20 15:25:31 2011
New Revision: 123943
URL: http://llvm.org/viewvc/llvm-project?rev=123943&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp
cfe/trunk/test/SemaCXX/uninit-variables.cpp
Modified: cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp?rev=123943&r1=123942&r2=123943&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp Thu Jan 20 15:25:31 2011
@@ -156,7 +156,7 @@
llvm::BitVector &CFGBlockValues::getBitVector(const CFGBlock *block,
const CFGBlock *dstBlock) {
unsigned idx = block->getBlockID();
- if (dstBlock && block->succ_size() == 2) {
+ if (dstBlock && block->succ_size() == 2 && block->pred_size() == 2) {
assert(block->getTerminator());
if (getLogicalOperatorInChain(block)) {
if (*block->succ_begin() == dstBlock)
@@ -460,20 +460,19 @@
UninitVariablesHandler *handler = 0) {
if (const BinaryOperator *b = getLogicalOperatorInChain(block)) {
- assert(block->pred_size() == 2);
- assert(block->succ_size() == 2);
- assert(block->getTerminatorCondition() == b);
-
- BVPair valsAB = vals.getPredBitVectors(block);
- vals.mergeIntoScratch(*valsAB.first, true);
- vals.mergeIntoScratch(*valsAB.second, false);
- valsAB.second = &vals.getScratch();
- if (b->getOpcode() == BO_LOr) {
- // Ensure the invariant that 'first' corresponds to the true
- // branch and 'second' to the false.
- std::swap(valsAB.first, valsAB.second);
+ if (block->pred_size() == 2 && block->succ_size() == 2) {
+ assert(block->getTerminatorCondition() == b);
+ BVPair valsAB = vals.getPredBitVectors(block);
+ vals.mergeIntoScratch(*valsAB.first, true);
+ vals.mergeIntoScratch(*valsAB.second, false);
+ valsAB.second = &vals.getScratch();
+ if (b->getOpcode() == BO_LOr) {
+ // Ensure the invariant that 'first' corresponds to the true
+ // branch and 'second' to the false.
+ std::swap(valsAB.first, valsAB.second);
+ }
+ return vals.updateBitVectors(block, valsAB);
}
- return vals.updateBitVectors(block, valsAB);
}
// Default behavior: merge in values of predecessor blocks.
Modified: cfe/trunk/test/SemaCXX/uninit-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninit-variables.cpp?rev=123943&r1=123942&r2=123943&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninit-variables.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninit-variables.cpp Thu Jan 20 15:25:31 2011
@@ -13,3 +13,31 @@
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'}}
+}
+
More information about the cfe-commits
mailing list