diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-07-31 01:52:11 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-07-31 01:52:11 +0000 |
commit | dd0e490c24aeade2c59ca4cae171199f6af9f02e (patch) | |
tree | 6fbe261cccc17fa85e01252bb7422f932f1d9b0b /lib/AST/AttrImpl.cpp | |
parent | cc5888d833caf90ebda37f24da40d2cd06b4d820 (diff) |
After a lengthy design discussion, add support for "ownership attributes" for malloc/free checking. Patch by Andrew McGregor!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109939 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/AttrImpl.cpp')
-rw-r--r-- | lib/AST/AttrImpl.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/AST/AttrImpl.cpp b/lib/AST/AttrImpl.cpp index 7277bbce24..4146248fb0 100644 --- a/lib/AST/AttrImpl.cpp +++ b/lib/AST/AttrImpl.cpp @@ -48,6 +48,43 @@ NonNullAttr::NonNullAttr(ASTContext &C, unsigned* arg_nums, unsigned size) memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size); } +OwnershipAttr::OwnershipAttr(attr::Kind AK, ASTContext &C, unsigned* arg_nums, + unsigned size, + llvm::StringRef module, + OwnershipKind kind) : + AttrWithString(AK, C, module), ArgNums(0), Size(0), OKind(kind) { + if (size == 0) + return; + assert(arg_nums); + ArgNums = new (C) unsigned[size]; + Size = size; + AKind = AK; + OKind = kind; + memcpy(ArgNums, arg_nums, sizeof(*ArgNums) * size); +} + + +void OwnershipAttr::Destroy(ASTContext &C) { + if (ArgNums) + C.Deallocate(ArgNums); +} + +OwnershipTakesAttr::OwnershipTakesAttr(ASTContext &C, unsigned* arg_nums, + unsigned size, llvm::StringRef module) : + OwnershipAttr(attr::OwnershipTakes, C, arg_nums, size, module, Takes) { +} + +OwnershipHoldsAttr::OwnershipHoldsAttr(ASTContext &C, unsigned* arg_nums, + unsigned size, llvm::StringRef module) : + OwnershipAttr(attr::OwnershipHolds, C, arg_nums, size, module, Holds) { +} + +OwnershipReturnsAttr::OwnershipReturnsAttr(ASTContext &C, unsigned* arg_nums, + unsigned size, + llvm::StringRef module) : + OwnershipAttr(attr::OwnershipReturns, C, arg_nums, size, module, Returns) { +} + #define DEF_SIMPLE_ATTR_CLONE(ATTR) \ Attr *ATTR##Attr::clone(ASTContext &C) const { \ return ::new (C) ATTR##Attr; \ @@ -147,6 +184,22 @@ Attr *NonNullAttr::clone(ASTContext &C) const { return ::new (C) NonNullAttr(C, ArgNums, Size); } +Attr *OwnershipAttr::clone(ASTContext &C) const { + return ::new (C) OwnershipAttr(AKind, C, ArgNums, Size, getModule(), OKind); +} + +Attr *OwnershipReturnsAttr::clone(ASTContext &C) const { + return ::new (C) OwnershipReturnsAttr(C, ArgNums, Size, getModule()); +} + +Attr *OwnershipTakesAttr::clone(ASTContext &C) const { + return ::new (C) OwnershipTakesAttr(C, ArgNums, Size, getModule()); +} + +Attr *OwnershipHoldsAttr::clone(ASTContext &C) const { + return ::new (C) OwnershipHoldsAttr(C, ArgNums, Size, getModule()); +} + Attr *FormatAttr::clone(ASTContext &C) const { return ::new (C) FormatAttr(C, getType(), formatIdx, firstArg); } |