diff options
author | Sean Hunt <scshunt@csclub.uwaterloo.ca> | 2010-08-18 23:23:40 +0000 |
---|---|---|
committer | Sean Hunt <scshunt@csclub.uwaterloo.ca> | 2010-08-18 23:23:40 +0000 |
commit | cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530 (patch) | |
tree | a4ad221a821125e6a865fe554a9bdd7305fa4706 /lib/Checker/MallocChecker.cpp | |
parent | ea94bbc4769697143e717df9b0310f874102b6c1 (diff) |
Generate Attr subclasses with TableGen.
Now all classes derived from Attr are generated from TableGen.
Additionally, Attr* is no longer its own linked list; SmallVectors or
Attr* are used. The accompanying LLVM commit contains the updates to
TableGen necessary for this.
Some other notes about newly-generated attribute classes:
- The constructor arguments are a SourceLocation and a Context&,
followed by the attributes arguments in the order that they were
defined in Attr.td
- Every argument in Attr.td has an appropriate accessor named getFoo,
and there are sometimes a few extra ones (such as to get the length
of a variadic argument).
Additionally, specific_attr_iterator has been introduced, which will
iterate over an AttrVec, but only over attributes of a certain type. It
can be accessed through either Decl::specific_attr_begin/end or
the global functions of the same name.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111455 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Checker/MallocChecker.cpp')
-rw-r--r-- | lib/Checker/MallocChecker.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/Checker/MallocChecker.cpp b/lib/Checker/MallocChecker.cpp index 0076e1e868..6e7faa7c07 100644 --- a/lib/Checker/MallocChecker.cpp +++ b/lib/Checker/MallocChecker.cpp @@ -176,19 +176,23 @@ bool MallocChecker::EvalCallExpr(CheckerContext &C, const CallExpr *CE) { // There can be multiple of these attributes. bool rv = false; if (FD->hasAttrs()) { - for (const Attr *attr = FD->getAttrs(); attr; attr = attr->getNext()) { - switch (attr->getKind()) { - case attr::OwnershipReturns: - MallocMemReturnsAttr(C, CE, cast<OwnershipAttr>(attr)); + for (specific_attr_iterator<OwnershipAttr> + i = FD->specific_attr_begin<OwnershipAttr>(), + e = FD->specific_attr_end<OwnershipAttr>(); + i != e; ++i) { + switch ((*i)->getOwnKind()) { + case OwnershipAttr::Returns: { + MallocMemReturnsAttr(C, CE, *i); rv = true; break; - case attr::OwnershipTakes: - case attr::OwnershipHolds: - FreeMemAttr(C, CE, cast<OwnershipAttr>(attr)); + } + case OwnershipAttr::Takes: + case OwnershipAttr::Holds: { + FreeMemAttr(C, CE, *i); rv = true; break; + } default: - // Ignore non-ownership attributes. break; } } @@ -204,10 +208,10 @@ void MallocChecker::MallocMem(CheckerContext &C, const CallExpr *CE) { void MallocChecker::MallocMemReturnsAttr(CheckerContext &C, const CallExpr *CE, const OwnershipAttr* Att) { - if (!Att->isModule("malloc")) + if (Att->getModule() != "malloc") return; - const unsigned *I = Att->begin(), *E = Att->end(); + OwnershipAttr::args_iterator I = Att->args_begin(), E = Att->args_end(); if (I != E) { const GRState *state = MallocMemAux(C, CE, CE->getArg(*I), UndefinedVal(), C.getState()); @@ -258,14 +262,15 @@ void MallocChecker::FreeMem(CheckerContext &C, const CallExpr *CE) { void MallocChecker::FreeMemAttr(CheckerContext &C, const CallExpr *CE, const OwnershipAttr* Att) { - if (!Att->isModule("malloc")) + if (Att->getModule() != "malloc") return; - for (const unsigned *I = Att->begin(), *E = Att->end(); I != E; ++I) { - const GRState *state = - FreeMemAux(C, CE, C.getState(), *I, isa<OwnershipHoldsAttr>(Att)); - if (state) - C.addTransition(state); + for (OwnershipAttr::args_iterator I = Att->args_begin(), E = Att->args_end(); + I != E; ++I) { + const GRState *state = FreeMemAux(C, CE, C.getState(), *I, + Att->getOwnKind() == OwnershipAttr::Holds); + if (state) + C.addTransition(state); } } |