Teach AttrNonNullChecker about transparent unions. Fixes crash reported in <rdar://problem/8642434>.

llvm-svn: 118473
This commit is contained in:
Ted Kremenek 2010-11-09 02:11:43 +00:00
parent 16e6026f01
commit dcf85a8d18
2 changed files with 36 additions and 0 deletions

View File

@ -67,6 +67,28 @@ void AttrNonNullChecker::PreVisitCallExpr(CheckerContext &C,
if (!DV)
continue;
if (!isa<Loc>(*DV)) {
// If the argument is a union type, we want to handle a potential
// transparent_unoin GCC extension.
QualType T = (*I)->getType();
const RecordType *UT = T->getAsUnionType();
if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>())
continue;
if (nonloc::CompoundVal *CSV = dyn_cast<nonloc::CompoundVal>(DV)) {
nonloc::CompoundVal::iterator CSV_I = CSV->begin();
assert(CSV_I != CSV->end());
V = *CSV_I;
DV = dyn_cast<DefinedSVal>(&V);
assert(++CSV_I == CSV->end());
if (!DV)
continue;
}
else {
// FIXME: Handle LazyCompoundVals?
continue;
}
}
ConstraintManager &CM = C.getConstraintManager();
const GRState *stateNotNull, *stateNull;
llvm::tie(stateNotNull, stateNull) = CM.AssumeDual(state, *DV);

View File

@ -1188,4 +1188,18 @@ static void RDar8424269_B(RDar8424269_A *p, unsigned char *RDar8424269_D,
tmp2 = tmp2t[2];
}
// <rdar://problem/8642434> - Handle transparent unions with the AttrNonNullChecker.
typedef union {
struct rdar_8642434_typeA *_dq;
}
rdar_8642434_typeB __attribute__((transparent_union));
__attribute__((visibility("default"))) __attribute__((__nonnull__)) __attribute__((__nothrow__))
void rdar_8642434_funcA(rdar_8642434_typeB object);
void rdar_8642434_funcB(struct rdar_8642434_typeA *x, struct rdar_8642434_typeA *y) {
rdar_8642434_funcA(x);
if (!y)
rdar_8642434_funcA(y); // expected-warning{{Null pointer passed as an argument to a 'nonnull' parameter}}
}