diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-11-09 02:11:43 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-11-09 02:11:43 +0000 |
commit | bb0ba0bca7896e76f8ce9b709ee881cc505e4d5e (patch) | |
tree | b7f9c685737d757a6e19f649ae8905f737ad3d71 | |
parent | c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3 (diff) |
Teach AttrNonNullChecker about transparent unions. Fixes crash reported in <rdar://problem/8642434>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118473 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Checker/AttrNonNullChecker.cpp | 22 | ||||
-rw-r--r-- | test/Analysis/misc-ps-region-store.m | 14 |
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/Checker/AttrNonNullChecker.cpp b/lib/Checker/AttrNonNullChecker.cpp index d0bccb27b4..54b7b72d43 100644 --- a/lib/Checker/AttrNonNullChecker.cpp +++ b/lib/Checker/AttrNonNullChecker.cpp @@ -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); diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m index ed285b422b..0a6884be06 100644 --- a/test/Analysis/misc-ps-region-store.m +++ b/test/Analysis/misc-ps-region-store.m @@ -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}} +} |