2009-06-02 17:58:47 +00:00
|
|
|
//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the AttributeList class implementation
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-09-17 15:54:40 +00:00
|
|
|
#include "clang/Sema/AttributeList.h"
|
2011-05-02 19:39:53 +00:00
|
|
|
#include "clang/AST/Expr.h"
|
2009-06-02 17:58:47 +00:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2009-11-04 15:04:32 +00:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2009-06-02 17:58:47 +00:00
|
|
|
using namespace clang;
|
|
|
|
|
2011-05-02 19:39:53 +00:00
|
|
|
size_t AttributeList::allocated_size() const {
|
|
|
|
if (IsAvailability) return AttributeFactory::AvailabilityAllocSize;
|
|
|
|
return (sizeof(AttributeList) + NumArgs * sizeof(Expr*));
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeFactory::AttributeFactory() {
|
|
|
|
// Go ahead and configure all the inline capacity. This is just a memset.
|
|
|
|
FreeLists.resize(InlineFreeListsCapacity);
|
|
|
|
}
|
|
|
|
AttributeFactory::~AttributeFactory() {}
|
|
|
|
|
|
|
|
static size_t getFreeListIndexForSize(size_t size) {
|
|
|
|
assert(size >= sizeof(AttributeList));
|
|
|
|
assert((size % sizeof(void*)) == 0);
|
|
|
|
return ((size - sizeof(AttributeList)) / sizeof(void*));
|
|
|
|
}
|
|
|
|
|
|
|
|
void *AttributeFactory::allocate(size_t size) {
|
|
|
|
// Check for a previously reclaimed attribute.
|
|
|
|
size_t index = getFreeListIndexForSize(size);
|
|
|
|
if (index < FreeLists.size()) {
|
|
|
|
if (AttributeList *attr = FreeLists[index]) {
|
|
|
|
FreeLists[index] = attr->NextInPool;
|
|
|
|
return attr;
|
|
|
|
}
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2011-05-02 19:39:53 +00:00
|
|
|
|
|
|
|
// Otherwise, allocate something new.
|
|
|
|
return Alloc.Allocate(size, llvm::AlignOf<AttributeFactory>::Alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeFactory::reclaimPool(AttributeList *cur) {
|
|
|
|
assert(cur && "reclaiming empty pool!");
|
|
|
|
do {
|
|
|
|
// Read this here, because we're going to overwrite NextInPool
|
|
|
|
// when we toss 'cur' into the appropriate queue.
|
|
|
|
AttributeList *next = cur->NextInPool;
|
|
|
|
|
|
|
|
size_t size = cur->allocated_size();
|
|
|
|
size_t freeListIndex = getFreeListIndexForSize(size);
|
|
|
|
|
|
|
|
// Expand FreeLists to the appropriate size, if required.
|
|
|
|
if (freeListIndex >= FreeLists.size())
|
|
|
|
FreeLists.resize(freeListIndex+1);
|
|
|
|
|
|
|
|
// Add 'cur' to the appropriate free-list.
|
|
|
|
cur->NextInPool = FreeLists[freeListIndex];
|
|
|
|
FreeLists[freeListIndex] = cur;
|
|
|
|
|
|
|
|
cur = next;
|
|
|
|
} while (cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributePool::takePool(AttributeList *pool) {
|
|
|
|
assert(pool);
|
|
|
|
|
|
|
|
// Fast path: this pool is empty.
|
|
|
|
if (!Head) {
|
|
|
|
Head = pool;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reverse the pool onto the current head. This optimizes for the
|
|
|
|
// pattern of pulling a lot of pools into a single pool.
|
|
|
|
do {
|
|
|
|
AttributeList *next = pool->NextInPool;
|
|
|
|
pool->NextInPool = Head;
|
|
|
|
Head = pool;
|
|
|
|
pool = next;
|
|
|
|
} while (pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeList *
|
|
|
|
AttributePool::createIntegerAttribute(ASTContext &C, IdentifierInfo *Name,
|
|
|
|
SourceLocation TokLoc, int Arg) {
|
|
|
|
Expr *IArg = IntegerLiteral::Create(C, llvm::APInt(32, (uint64_t) Arg),
|
|
|
|
C.IntTy, TokLoc);
|
|
|
|
return create(Name, TokLoc, 0, TokLoc, 0, TokLoc, &IArg, 1, 0);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
|
2011-10-20 21:14:49 +00:00
|
|
|
StringRef AttrName = Name->getName();
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
// Normalize the attribute name, __foo__ becomes foo.
|
2009-10-23 14:22:18 +00:00
|
|
|
if (AttrName.startswith("__") && AttrName.endswith("__"))
|
|
|
|
AttrName = AttrName.substr(2, AttrName.size() - 4);
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-11-04 15:04:32 +00:00
|
|
|
return llvm::StringSwitch<AttributeList::Kind>(AttrName)
|
|
|
|
.Case("weak", AT_weak)
|
2010-03-03 17:28:16 +00:00
|
|
|
.Case("weakref", AT_weakref)
|
2011-07-17 15:40:56 +00:00
|
|
|
.Case("objc_arc_weak_reference_unavailable", AT_arc_weakref_unavailable)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("pure", AT_pure)
|
|
|
|
.Case("mode", AT_mode)
|
|
|
|
.Case("used", AT_used)
|
|
|
|
.Case("alias", AT_alias)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("align", AT_aligned)
|
2009-11-18 14:59:57 +00:00
|
|
|
.Case("cdecl", AT_cdecl)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("const", AT_const)
|
2011-02-20 13:06:31 +00:00
|
|
|
.Case("__const", AT_const) // some GCC headers do contain this spelling
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("blocks", AT_blocks)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("format", AT_format)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("malloc", AT_malloc)
|
|
|
|
.Case("packed", AT_packed)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("unused", AT_unused)
|
|
|
|
.Case("aligned", AT_aligned)
|
|
|
|
.Case("cleanup", AT_cleanup)
|
2011-02-20 13:06:31 +00:00
|
|
|
.Case("naked", AT_naked)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("nodebug", AT_nodebug)
|
|
|
|
.Case("nonnull", AT_nonnull)
|
|
|
|
.Case("nothrow", AT_nothrow)
|
|
|
|
.Case("objc_gc", AT_objc_gc)
|
|
|
|
.Case("regparm", AT_regparm)
|
|
|
|
.Case("section", AT_section)
|
|
|
|
.Case("stdcall", AT_stdcall)
|
|
|
|
.Case("annotate", AT_annotate)
|
|
|
|
.Case("fastcall", AT_fastcall)
|
2010-03-03 17:28:16 +00:00
|
|
|
.Case("ibaction", AT_IBAction)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("iboutlet", AT_IBOutlet)
|
2010-05-27 15:17:06 +00:00
|
|
|
.Case("iboutletcollection", AT_IBOutletCollection)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("noreturn", AT_noreturn)
|
|
|
|
.Case("noinline", AT_noinline)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("sentinel", AT_sentinel)
|
|
|
|
.Case("NSObject", AT_nsobject)
|
|
|
|
.Case("dllimport", AT_dllimport)
|
|
|
|
.Case("dllexport", AT_dllexport)
|
2011-02-20 13:06:31 +00:00
|
|
|
.Case("may_alias", AT_may_alias)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("base_check", AT_base_check)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("deprecated", AT_deprecated)
|
2011-05-02 19:39:53 +00:00
|
|
|
.Case("availability", AT_availability)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("visibility", AT_visibility)
|
|
|
|
.Case("destructor", AT_destructor)
|
|
|
|
.Case("format_arg", AT_format_arg)
|
|
|
|
.Case("gnu_inline", AT_gnu_inline)
|
|
|
|
.Case("weak_import", AT_weak_import)
|
2010-09-17 15:54:40 +00:00
|
|
|
.Case("vecreturn", AT_vecreturn)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("vector_size", AT_vector_size)
|
|
|
|
.Case("constructor", AT_constructor)
|
|
|
|
.Case("unavailable", AT_unavailable)
|
|
|
|
.Case("overloadable", AT_overloadable)
|
|
|
|
.Case("address_space", AT_address_space)
|
2011-05-02 19:39:53 +00:00
|
|
|
.Case("opencl_image_access", AT_opencl_image_access)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("always_inline", AT_always_inline)
|
2011-10-20 21:14:49 +00:00
|
|
|
.Case("returns_twice", AT_returns_twice)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("vec_type_hint", IgnoredAttribute)
|
|
|
|
.Case("objc_exception", AT_objc_exception)
|
2011-05-02 19:39:53 +00:00
|
|
|
.Case("objc_method_family", AT_objc_method_family)
|
2011-10-20 21:14:49 +00:00
|
|
|
.Case("objc_returns_inner_pointer", AT_objc_returns_inner_pointer)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("ext_vector_type", AT_ext_vector_type)
|
2011-02-20 13:06:31 +00:00
|
|
|
.Case("neon_vector_type", AT_neon_vector_type)
|
|
|
|
.Case("neon_polyvector_type", AT_neon_polyvector_type)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("transparent_union", AT_transparent_union)
|
|
|
|
.Case("analyzer_noreturn", AT_analyzer_noreturn)
|
|
|
|
.Case("warn_unused_result", AT_warn_unused_result)
|
2009-12-01 11:08:04 +00:00
|
|
|
.Case("carries_dependency", AT_carries_dependency)
|
2011-10-20 21:14:49 +00:00
|
|
|
.Case("ns_bridged", AT_ns_bridged)
|
2011-02-20 13:06:31 +00:00
|
|
|
.Case("ns_consumed", AT_ns_consumed)
|
|
|
|
.Case("ns_consumes_self", AT_ns_consumes_self)
|
|
|
|
.Case("ns_returns_autoreleased", AT_ns_returns_autoreleased)
|
2010-03-03 17:28:16 +00:00
|
|
|
.Case("ns_returns_not_retained", AT_ns_returns_not_retained)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("ns_returns_retained", AT_ns_returns_retained)
|
2011-10-20 21:14:49 +00:00
|
|
|
.Case("cf_audited_transfer", AT_cf_audited_transfer)
|
2011-02-20 13:06:31 +00:00
|
|
|
.Case("cf_consumed", AT_cf_consumed)
|
2010-03-03 17:28:16 +00:00
|
|
|
.Case("cf_returns_not_retained", AT_cf_returns_not_retained)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("cf_returns_retained", AT_cf_returns_retained)
|
2011-07-17 15:40:56 +00:00
|
|
|
.Case("cf_returns_autoreleased", AT_cf_returns_autoreleased)
|
2011-10-20 21:14:49 +00:00
|
|
|
.Case("cf_unknown_transfer", AT_cf_unknown_transfer)
|
2011-07-17 15:40:56 +00:00
|
|
|
.Case("ns_consumes_self", AT_ns_consumes_self)
|
|
|
|
.Case("ns_consumed", AT_ns_consumed)
|
|
|
|
.Case("objc_ownership", AT_objc_ownership)
|
|
|
|
.Case("objc_precise_lifetime", AT_objc_precise_lifetime)
|
2010-09-17 15:54:40 +00:00
|
|
|
.Case("ownership_returns", AT_ownership_returns)
|
|
|
|
.Case("ownership_holds", AT_ownership_holds)
|
|
|
|
.Case("ownership_takes", AT_ownership_takes)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("reqd_work_group_size", AT_reqd_wg_size)
|
2010-07-13 17:21:42 +00:00
|
|
|
.Case("init_priority", AT_init_priority)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Case("no_instrument_function", AT_no_instrument_function)
|
2010-05-27 15:17:06 +00:00
|
|
|
.Case("thiscall", AT_thiscall)
|
2011-02-20 13:06:31 +00:00
|
|
|
.Case("bounded", IgnoredAttribute) // OpenBSD
|
2010-09-17 15:54:40 +00:00
|
|
|
.Case("pascal", AT_pascal)
|
2010-05-27 15:17:06 +00:00
|
|
|
.Case("__cdecl", AT_cdecl)
|
|
|
|
.Case("__stdcall", AT_stdcall)
|
|
|
|
.Case("__fastcall", AT_fastcall)
|
|
|
|
.Case("__thiscall", AT_thiscall)
|
2010-09-17 15:54:40 +00:00
|
|
|
.Case("__pascal", AT_pascal)
|
2011-02-20 13:06:31 +00:00
|
|
|
.Case("constant", AT_constant)
|
|
|
|
.Case("device", AT_device)
|
|
|
|
.Case("global", AT_global)
|
|
|
|
.Case("host", AT_host)
|
|
|
|
.Case("shared", AT_shared)
|
|
|
|
.Case("launch_bounds", AT_launch_bounds)
|
|
|
|
.Case("common", AT_common)
|
|
|
|
.Case("nocommon", AT_nocommon)
|
|
|
|
.Case("opencl_kernel_function", AT_opencl_kernel_function)
|
|
|
|
.Case("uuid", AT_uuid)
|
2011-05-02 19:39:53 +00:00
|
|
|
.Case("pcs", AT_pcs)
|
|
|
|
.Case("ms_struct", AT_MsStruct)
|
2011-10-20 21:14:49 +00:00
|
|
|
.Case("guarded_var", AT_guarded_var)
|
|
|
|
.Case("pt_guarded_var", AT_pt_guarded_var)
|
|
|
|
.Case("scoped_lockable", AT_scoped_lockable)
|
|
|
|
.Case("lockable", AT_lockable)
|
|
|
|
.Case("no_thread_safety_analysis", AT_no_thread_safety_analysis)
|
|
|
|
.Case("guarded_by", AT_guarded_by)
|
|
|
|
.Case("pt_guarded_by", AT_pt_guarded_by)
|
|
|
|
.Case("acquired_after", AT_acquired_after)
|
|
|
|
.Case("acquired_before", AT_acquired_before)
|
|
|
|
.Case("exclusive_lock_function", AT_exclusive_lock_function)
|
|
|
|
.Case("exclusive_locks_required", AT_exclusive_locks_required)
|
|
|
|
.Case("exclusive_trylock_function", AT_exclusive_trylock_function)
|
|
|
|
.Case("lock_returned", AT_lock_returned)
|
|
|
|
.Case("locks_excluded", AT_locks_excluded)
|
|
|
|
.Case("shared_lock_function", AT_shared_lock_function)
|
|
|
|
.Case("shared_locks_required", AT_shared_locks_required)
|
|
|
|
.Case("shared_trylock_function", AT_shared_trylock_function)
|
|
|
|
.Case("unlock_function", AT_unlock_function)
|
2009-11-04 15:04:32 +00:00
|
|
|
.Default(UnknownAttribute);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|