if (!isa<nonloc::ConcreteInt>(val))
return UnknownVal();
+ // Handle casts to a boolean type.
+ if (castTy->isBooleanType()) {
+ bool b = cast<nonloc::ConcreteInt>(val).getValue().getBoolValue();
+ return makeTruthVal(b, castTy);
+ }
+
// Only handle casts from integers to integers - if val is an integer constant
// being cast to a non integer type, produce unknown.
if (!isLocType && !castTy->isIntegerType())
NonLoc *LeftIndex = dyn_cast<NonLoc>(&LeftIndexVal);
if (!LeftIndex)
return UnknownVal();
- LeftIndexVal = evalCastFromNonLoc(*LeftIndex, resultTy);
+ LeftIndexVal = evalCastFromNonLoc(*LeftIndex, ArrayIndexTy);
LeftIndex = dyn_cast<NonLoc>(&LeftIndexVal);
if (!LeftIndex)
return UnknownVal();
NonLoc *RightIndex = dyn_cast<NonLoc>(&RightIndexVal);
if (!RightIndex)
return UnknownVal();
- RightIndexVal = evalCastFromNonLoc(*RightIndex, resultTy);
+ RightIndexVal = evalCastFromNonLoc(*RightIndex, ArrayIndexTy);
RightIndex = dyn_cast<NonLoc>(&RightIndexVal);
if (!RightIndex)
return UnknownVal();
static const Rdar12755044_foo Rdar12755044_foo_list[] = { { { } } };
return Rdar12755044_foo_list; // no-warning
}
+
+// Test the correct handling of integer to bool conversions. Previously
+// this resulted in a false positive because integers were being truncated
+// and not tested for non-zero.
+void rdar12759044() {
+ int flag = 512;
+ if (!(flag & 512)) {
+ int *p = 0;
+ *p = 0xDEADBEEF; // no-warning
+ }
+}