[llvm-branch-commits] [cfe-branch] r118578 - in /cfe/branches/Apple/whitney: lib/Checker/AttrNonNullChecker.cpp test/Analysis/misc-ps-region-store.m
Daniel Dunbar
daniel at zuster.org
Tue Nov 9 09:32:51 PST 2010
Author: ddunbar
Date: Tue Nov 9 11:32:51 2010
New Revision: 118578
URL: http://llvm.org/viewvc/llvm-project?rev=118578&view=rev
Log:
Merge r118473:
--
Author: Ted Kremenek <kremenek at apple.com>
Date: Tue Nov 9 02:11:43 2010 +0000
Teach AttrNonNullChecker about transparent unions. Fixes crash reported in <rdar://problem/8642434>.
Modified:
cfe/branches/Apple/whitney/lib/Checker/AttrNonNullChecker.cpp
cfe/branches/Apple/whitney/test/Analysis/misc-ps-region-store.m
Modified: cfe/branches/Apple/whitney/lib/Checker/AttrNonNullChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Checker/AttrNonNullChecker.cpp?rev=118578&r1=118577&r2=118578&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Checker/AttrNonNullChecker.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Checker/AttrNonNullChecker.cpp Tue Nov 9 11:32:51 2010
@@ -67,6 +67,28 @@
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);
Modified: cfe/branches/Apple/whitney/test/Analysis/misc-ps-region-store.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Analysis/misc-ps-region-store.m?rev=118578&r1=118577&r2=118578&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Analysis/misc-ps-region-store.m (original)
+++ cfe/branches/Apple/whitney/test/Analysis/misc-ps-region-store.m Tue Nov 9 11:32:51 2010
@@ -1188,4 +1188,18 @@
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}}
+}
More information about the llvm-branch-commits
mailing list