From d5aa73376966339caad04013510626ec2e42c760 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 6 Sep 2016 20:36:24 +0000 Subject: [PATCH] Avoid using alignas and constexpr. This requires removing the custom allocator, since Demangle cannot depend on Support and so cannot use Compiler.h. llvm-svn: 280750 --- llvm/lib/Demangle/ItaniumDemangle.cpp | 141 ++-------------------------------- 1 file changed, 5 insertions(+), 136 deletions(-) diff --git a/llvm/lib/Demangle/ItaniumDemangle.cpp b/llvm/lib/Demangle/ItaniumDemangle.cpp index d261aa0..1d3080c 100644 --- a/llvm/lib/Demangle/ItaniumDemangle.cpp +++ b/llvm/lib/Demangle/ItaniumDemangle.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Demangle/Demangle.h" -#include "llvm/Support/Compiler.h" // This file exports a single function: llvm::itanium_demangle. // It also has no dependencies on the rest of llvm. It is implemented this way @@ -4210,134 +4209,7 @@ static void demangle(const char *first, const char *last, C &db, int &status) { } namespace { -template class arena { - static const std::size_t alignment = 16; - LLVM_ALIGNAS(16) char buf_[N]; - char *ptr_; - - std::size_t align_up(std::size_t n) LLVM_NOEXCEPT { - return (n + (alignment - 1)) & ~(alignment - 1); - } - - bool pointer_in_buffer(char *p) LLVM_NOEXCEPT { - return buf_ <= p && p <= buf_ + N; - } - -public: - arena() LLVM_NOEXCEPT : ptr_(buf_) {} - ~arena() { ptr_ = nullptr; } - arena(const arena &) = delete; - arena &operator=(const arena &) = delete; - - char *allocate(std::size_t n); - void deallocate(char *p, std::size_t n) LLVM_NOEXCEPT; - - static LLVM_CONSTEXPR std::size_t size() { return N; } - std::size_t used() const { return static_cast(ptr_ - buf_); } - void reset() { ptr_ = buf_; } -}; - -template char *arena::allocate(std::size_t n) { - n = align_up(n); - if (static_cast(buf_ + N - ptr_) >= n) { - char *r = ptr_; - ptr_ += n; - return r; - } - return static_cast(std::malloc(n)); -} - -template -void arena::deallocate(char *p, std::size_t n) LLVM_NOEXCEPT { - if (pointer_in_buffer(p)) { - n = align_up(n); - if (p + n == ptr_) - ptr_ = p; - } else - std::free(p); -} - -template class short_alloc { - arena &a_; - -public: - typedef T value_type; - -public: - template struct rebind { typedef short_alloc<_Up, N> other; }; - - short_alloc(arena &a) LLVM_NOEXCEPT : a_(a) {} - template - short_alloc(const short_alloc &a) LLVM_NOEXCEPT : a_(a.a_) {} - short_alloc(const short_alloc &) = default; - short_alloc &operator=(const short_alloc &) = delete; - - T *allocate(std::size_t n) { - return reinterpret_cast(a_.allocate(n * sizeof(T))); - } - void deallocate(T *p, std::size_t n) LLVM_NOEXCEPT { - a_.deallocate(reinterpret_cast(p), n * sizeof(T)); - } - - template - friend bool operator==(const short_alloc &x, - const short_alloc &y) LLVM_NOEXCEPT; - - template friend class short_alloc; -}; - -template -inline bool operator==(const short_alloc &x, - const short_alloc &y) LLVM_NOEXCEPT { - return N == M && &x.a_ == &y.a_; -} - -template -inline bool operator!=(const short_alloc &x, - const short_alloc &y) LLVM_NOEXCEPT { - return !(x == y); -} - -template class malloc_alloc { -public: - typedef T value_type; - typedef T &reference; - typedef const T &const_reference; - typedef T *pointer; - typedef const T *const_pointer; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - - malloc_alloc() = default; - template malloc_alloc(const malloc_alloc &) LLVM_NOEXCEPT {} - - T *allocate(std::size_t n) { - return static_cast(std::malloc(n * sizeof(T))); - } - void deallocate(T *p, std::size_t) LLVM_NOEXCEPT { std::free(p); } - - template struct rebind { using other = malloc_alloc; }; - template void construct(U *p, Args &&... args) { - ::new ((void *)p) U(std::forward(args)...); - } - void destroy(T *p) { p->~T(); } -}; - -template -inline bool operator==(const malloc_alloc &, - const malloc_alloc &) LLVM_NOEXCEPT { - return true; -} - -template -inline bool operator!=(const malloc_alloc &x, - const malloc_alloc &y) LLVM_NOEXCEPT { - return !(x == y); -} - -const size_t bs = 4 * 1024; -template using Alloc = short_alloc; -template using Vector = std::vector>; +template using Vector = std::vector; template struct string_pair { StrT first; @@ -4354,7 +4226,7 @@ template struct string_pair { }; struct Db { - typedef std::basic_string, malloc_alloc> + typedef std::basic_string> String; typedef Vector> sub_type; typedef Vector template_param_type; @@ -4369,9 +4241,7 @@ struct Db { bool fix_forward_references; bool try_to_parse_template_args; - template - Db(arena &ar) - : names(ar), subs(0, names, ar), template_param(0, subs, ar) {} + Db() : subs(0, names), template_param(0, subs) {} }; } @@ -4383,14 +4253,13 @@ char *llvm::itaniumDemangle(const char *mangled_name, char *buf, size_t *n, return nullptr; } size_t internal_size = buf != nullptr ? *n : 0; - arena a; - Db db(a); + Db db; db.cv = 0; db.ref = 0; db.encoding_depth = 0; db.parsed_ctor_dtor_cv = false; db.tag_templates = true; - db.template_param.emplace_back(a); + db.template_param.emplace_back(); db.fix_forward_references = false; db.try_to_parse_template_args = true; int internal_status = success; -- 2.7.4