llvm.org GIT mirror llvm / 6b15e98
Fix ItaniumDemangle.cpp build with MSVC 2013 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280740 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 3 years ago
1 changed file(s) with 20 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include
9 #include "llvm/Demangle/Demangle.h"
10 #include "llvm/Support/Compiler.h"
1011
1112 // This file exports a single function: llvm::itanium_demangle.
1213 // It also has no dependencies on the rest of llvm. It is implemented this way
42104211 namespace {
42114212 template class arena {
42124213 static const std::size_t alignment = 16;
4213 alignas(alignment) char buf_[N];
4214 LLVM_ALIGNAS(16) char buf_[N];
42144215 char *ptr_;
42154216
4216 std::size_t align_up(std::size_t n) noexcept {
4217 std::size_t align_up(std::size_t n) LLVM_NOEXCEPT {
42174218 return (n + (alignment - 1)) & ~(alignment - 1);
42184219 }
42194220
4220 bool pointer_in_buffer(char *p) noexcept {
4221 bool pointer_in_buffer(char *p) LLVM_NOEXCEPT {
42214222 return buf_ <= p && p <= buf_ + N;
42224223 }
42234224
42244225 public:
4225 arena() noexcept : ptr_(buf_) {}
4226 arena() LLVM_NOEXCEPT : ptr_(buf_) {}
42264227 ~arena() { ptr_ = nullptr; }
42274228 arena(const arena &) = delete;
42284229 arena &operator=(const arena &) = delete;
42294230
42304231 char *allocate(std::size_t n);
4231 void deallocate(char *p, std::size_t n) noexcept;
4232
4233 static constexpr std::size_t size() { return N; }
4232 void deallocate(char *p, std::size_t n) LLVM_NOEXCEPT;
4233
4234 static LLVM_CONSTEXPR std::size_t size() { return N; }
42344235 std::size_t used() const { return static_cast(ptr_ - buf_); }
42354236 void reset() { ptr_ = buf_; }
42364237 };
42464247 }
42474248
42484249 template
4249 void arena::deallocate(char *p, std::size_t n) noexcept {
4250 void arena::deallocate(char *p, std::size_t n) LLVM_NOEXCEPT {
42504251 if (pointer_in_buffer(p)) {
42514252 n = align_up(n);
42524253 if (p + n == ptr_)
42644265 public:
42654266 template struct rebind { typedef short_alloc<_Up, N> other; };
42664267
4267 short_alloc(arena &a) noexcept : a_(a) {}
4268 short_alloc(arena &a) LLVM_NOEXCEPT : a_(a) {}
42684269 template
4269 short_alloc(const short_alloc &a) noexcept : a_(a.a_) {}
4270 short_alloc(const short_alloc &a) LLVM_NOEXCEPT : a_(a.a_) {}
42704271 short_alloc(const short_alloc &) = default;
42714272 short_alloc &operator=(const short_alloc &) = delete;
42724273
42734274 T *allocate(std::size_t n) {
42744275 return reinterpret_cast(a_.allocate(n * sizeof(T)));
42754276 }
4276 void deallocate(T *p, std::size_t n) noexcept {
4277 void deallocate(T *p, std::size_t n) LLVM_NOEXCEPT {
42774278 a_.deallocate(reinterpret_cast(p), n * sizeof(T));
42784279 }
42794280
42804281 template
42814282 friend bool operator==(const short_alloc &x,
4282 const short_alloc &y) noexcept;
4283 const short_alloc &y) LLVM_NOEXCEPT;
42834284
42844285 template friend class short_alloc;
42854286 };
42864287
42874288 template
42884289 inline bool operator==(const short_alloc &x,
4289 const short_alloc &y) noexcept {
4290 const short_alloc &y) LLVM_NOEXCEPT {
42904291 return N == M && &x.a_ == &y.a_;
42914292 }
42924293
42934294 template
42944295 inline bool operator!=(const short_alloc &x,
4295 const short_alloc &y) noexcept {
4296 const short_alloc &y) LLVM_NOEXCEPT {
42964297 return !(x == y);
42974298 }
42984299
43074308 typedef std::ptrdiff_t difference_type;
43084309
43094310 malloc_alloc() = default;
4310 template malloc_alloc(const malloc_alloc &) noexcept {}
4311 template malloc_alloc(const malloc_alloc &) LLVM_NOEXCEPT {}
43114312
43124313 T *allocate(std::size_t n) {
43134314 return static_cast(std::malloc(n * sizeof(T)));
43144315 }
4315 void deallocate(T *p, std::size_t) noexcept { std::free(p); }
4316 void deallocate(T *p, std::size_t) LLVM_NOEXCEPT { std::free(p); }
43164317
43174318 template struct rebind { using other = malloc_alloc; };
43184319 template void construct(U *p, Args &&... args) {
43234324
43244325 template
43254326 inline bool operator==(const malloc_alloc &,
4326 const malloc_alloc &) noexcept {
4327 const malloc_alloc &) LLVM_NOEXCEPT {
43274328 return true;
43284329 }
43294330
43304331 template
43314332 inline bool operator!=(const malloc_alloc &x,
4332 const malloc_alloc &y) noexcept {
4333 const malloc_alloc &y) LLVM_NOEXCEPT {
43334334 return !(x == y);
43344335 }
43354336