authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-11 17:22:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-19 09:37:31-07:00
log9ddfacd8e62abd80b25619dd852ee811dad5f7b6
tree441be2e6381f6e82b8e87d5f1773f7531f8e9912
parent571a4c86c39d83b28a0c6f413f3fc259b48cf422

libcxxabi: update to LLVM 17

release/17.x branch, commit 8f4dd44097c9ae25dd203d5ac87f3b48f854bba8

13 files changed, 461 insertions(+), 408 deletions(-)

lib/libcxxabi/include/__cxxabi_config.h+1-1
...@@ -32,7 +32,7 @@...@@ -32,7 +32,7 @@
32#endif32#endif
3333
34#if defined(_WIN32)34#if defined(_WIN32)
35 #if defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)35 #if defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCXXABI_BUILDING_LIBRARY))
36 #define _LIBCXXABI_HIDDEN36 #define _LIBCXXABI_HIDDEN
37 #define _LIBCXXABI_DATA_VIS37 #define _LIBCXXABI_DATA_VIS
38 #define _LIBCXXABI_FUNC_VIS38 #define _LIBCXXABI_FUNC_VIS
lib/libcxxabi/src/aix_state_tab_eh.inc+56-29
...@@ -14,10 +14,6 @@...@@ -14,10 +14,6 @@
14#include <stdio.h>14#include <stdio.h>
15#include <sys/debug.h>15#include <sys/debug.h>
1616
17#if !__has_cpp_attribute(clang::optnone)
18#error This file requires clang::optnone attribute support
19#endif
20
21/*17/*
22 The legacy IBM xlC and xlclang++ compilers use the state table for EH18 The legacy IBM xlC and xlclang++ compilers use the state table for EH
23 instead of the range table. Destructors, or addresses of the possible catch19 instead of the range table. Destructors, or addresses of the possible catch
...@@ -563,7 +559,8 @@ __xlcxx_personality_v0(int version, _Unwind_Action actions, uint64_t exceptionCl...@@ -563,7 +559,8 @@ __xlcxx_personality_v0(int version, _Unwind_Action actions, uint64_t exceptionCl
563 uintptr_t *currentSP = reinterpret_cast<uintptr_t*>(_Unwind_GetGR(context, 1));559 uintptr_t *currentSP = reinterpret_cast<uintptr_t*>(_Unwind_GetGR(context, 1));
564 uintptr_t *callersSP = reinterpret_cast<uintptr_t*>(currentSP[0]);560 uintptr_t *callersSP = reinterpret_cast<uintptr_t*>(currentSP[0]);
565 callersSP[3] = reinterpret_cast<uintptr_t>(unwind_exception);561 callersSP[3] = reinterpret_cast<uintptr_t>(unwind_exception);
566 _LIBCXXABI_TRACE_STATETAB("Handshake: set unwind_exception=%p in stack=%p\n", reinterpret_cast<void*>(unwind_exception), reinterpret_cast<void*>(callersSP));562 _LIBCXXABI_TRACE_STATETAB("Handshake: save unwind_exception=%p in stack=%p\n",
563 reinterpret_cast<void*>(unwind_exception), reinterpret_cast<void*>(callersSP));
567 // Jump to the handler.564 // Jump to the handler.
568 _Unwind_SetIP(context, results.landingPad);565 _Unwind_SetIP(context, results.landingPad);
569 return _URC_INSTALL_CONTEXT;566 return _URC_INSTALL_CONTEXT;
...@@ -641,38 +638,68 @@ _LIBCXXABI_FUNC_VIS void __xlc_throw_badexception() {...@@ -641,38 +638,68 @@ _LIBCXXABI_FUNC_VIS void __xlc_throw_badexception() {
641 __cxa_throw(newexception, const_cast<std::type_info*>(&typeid(std::bad_exception)), 0);638 __cxa_throw(newexception, const_cast<std::type_info*>(&typeid(std::bad_exception)), 0);
642}639}
643640
644// force_a_stackframe641// skip_non_cxx_eh_aware_frames
645// This function is called by __xlc_exception_handle() to ensure a stack frame642// This function skips non-C++ EH aware stack frames by unwinding from the
646// is created for __xlc_exception_handle().643// stack frame pointed by 'Sp' and returns the first C++ EH aware stack frame
647__attribute__((noinline, optnone))644// found. 'Pc' is an instruction address inside the function that owns the
648static void force_a_stackframe() {}645// stack frame pointed to by 'Sp'.
646static uintptr_t* skip_non_cxx_eh_aware_frames(uint32_t* Pc, uintptr_t* Sp) {
647 uint32_t* currentPc = Pc;
648 uintptr_t* currentStack = Sp;
649
650 // Loop until a C++ EH aware frame is found or the return address is 0,
651 // which is the return address of the startup function '__start'.
652 while (currentPc != 0) {
653 uint32_t* p = currentPc;
654
655 // Keep looking forward until a word of 0 is found. The traceback
656 // table starts at the following word.
657 while (*p)
658 ++p;
659 tbtable* TBTable = reinterpret_cast<tbtable*>(p + 1);
660
661 // A stack frame with a C++ state table is C++ EH aware.
662 if (TBTable->tb.lang == TB_CPLUSPLUS && TBTable->tb.has_ctl)
663 return currentStack;
664
665 // Move up one stack frame.
666 currentStack = reinterpret_cast<uintptr_t*>(currentStack[0]);
667 // Get the value of the LR (saved, prior to incrementing the SP, by the
668 // prolog of the function just inspected) from the frame.
669 currentPc = reinterpret_cast<uint32_t*>(currentStack[2]);
670 }
671 // This should not happen.
672 _LIBCXXABI_TRACE_STATETAB0("skip_non_cxx_eh_aware_frames() reached the end of stack frames, aborting\n");
673 abort();
674}
649675
650// __xlc_exception_handle676// __xlc_exception_handle
651// This function is for xlclang++. It returns the address of the exception677// This function is for xlclang++. It returns the address of the exception
652// object stored in the reserved field in the stack of the caller of the678// object stored in the reserved field in the stack of the caller of the
653// function that calls __xlc_exception_handle() (within the link area for the679// function that calls __xlc_exception_handle() (within the link area for the
654// call to the latter). The address is stored by the personality routine for680// call to the latter). The address is stored by the personality routine for
655// xlclang++ compiled code. The implementation of __xlc_exception_handle()681// xlclang++ compiled code. If __xlc_exception_handle() is called by
656// assumes a stack frame is created for it. The following ensures this682// non-C++ EH aware functions, their frames are skipped until a C++ EH aware
657// assumption holds true: 1) a call to force_a_stackframe() is made inside683// frame is found.
658// __xlc_exception_handle() to make it non-leaf; and 2) optimizations are684// Note: make sure __xlc_excpetion_handle() is a non-leaf function. Currently
659// disabled for this function with attribute 'optnone'. Note: this function685// it calls skip_non_cxx_eh_aware_frames(), which in turn calls abort().
660// may not work as expected if these are changed.
661__attribute__((optnone))
662_LIBCXXABI_FUNC_VIS uintptr_t __xlc_exception_handle() {686_LIBCXXABI_FUNC_VIS uintptr_t __xlc_exception_handle() {
663 // Make a call to force_a_stackframe() so that the compiler creates a stack
664 // frame for this function.
665 force_a_stackframe();
666
667 // Get the SP of this function, i.e., __xlc_exception_handle().687 // Get the SP of this function, i.e., __xlc_exception_handle().
668 uintptr_t *lastStack;688 uintptr_t* lastStack = reinterpret_cast<uintptr_t*>(__builtin_frame_address(0));
669 asm("mr %0, 1" : "=r"(lastStack));689 // Move one frame up to the frame of the caller of __xlc_exception_handle().
670 // Get the SP of the caller of __xlc_exception_handle().690 lastStack = reinterpret_cast<uintptr_t*>(lastStack[0]);
671 uintptr_t *callerStack = reinterpret_cast<uintptr_t*>(lastStack[0]);691 // Get the return address of this function, i.e., __xlc_exception_handle().
672 // Get the SP of the caller of the caller.692 uint32_t* returnAddress = reinterpret_cast<uint32_t*>(__builtin_return_address(0));
673 uintptr_t *callerStack2 = reinterpret_cast<uintptr_t*>(callerStack[0]);693
674 uintptr_t exceptionObject = callerStack2[3];694 // Skip non-C++ EH aware frames and get the first C++ EH aware frame.
675 _LIBCXXABI_TRACE_STATETAB("Handshake: exceptionObject=%p from stack=%p\n", reinterpret_cast<void*>(exceptionObject), reinterpret_cast<void*>(callerStack2));695 uintptr_t* callerStack = skip_non_cxx_eh_aware_frames(returnAddress, lastStack);
696
697 // Get the SP of the caller of the C++ EH aware caller.
698 callerStack = reinterpret_cast<uintptr_t*>(callerStack[0]);
699 // Retrieve the exception object in the stack slot saved by the personality.
700 uintptr_t exceptionObject = callerStack[3];
701 _LIBCXXABI_TRACE_STATETAB("Handshake: retrieve exceptionObject=%p from stack=%p\n",
702 reinterpret_cast<void*>(exceptionObject), reinterpret_cast<void*>(callerStack));
676 return exceptionObject;703 return exceptionObject;
677}704}
678705
lib/libcxxabi/src/cxa_aux_runtime.cpp+1
...@@ -10,6 +10,7 @@...@@ -10,6 +10,7 @@
10//===----------------------------------------------------------------------===//10//===----------------------------------------------------------------------===//
1111
12#include "cxxabi.h"12#include "cxxabi.h"
13#include <exception>
13#include <new>14#include <new>
14#include <typeinfo>15#include <typeinfo>
1516
lib/libcxxabi/src/cxa_demangle.cpp+4-2
...@@ -10,6 +10,7 @@...@@ -10,6 +10,7 @@
10// file does not yet support:10// file does not yet support:
11// - C++ modules TS11// - C++ modules TS
1212
13#include "demangle/DemangleConfig.h"
13#include "demangle/ItaniumDemangle.h"14#include "demangle/ItaniumDemangle.h"
14#include "__cxxabi_config.h"15#include "__cxxabi_config.h"
15#include <cassert>16#include <cassert>
...@@ -19,6 +20,7 @@...@@ -19,6 +20,7 @@
19#include <cstring>20#include <cstring>
20#include <functional>21#include <functional>
21#include <numeric>22#include <numeric>
23#include <string_view>
22#include <utility>24#include <utility>
2325
24using namespace itanium_demangle;26using namespace itanium_demangle;
...@@ -77,8 +79,8 @@ struct DumpVisitor {...@@ -77,8 +79,8 @@ struct DumpVisitor {
77 }79 }
7880
79 void printStr(const char *S) { fprintf(stderr, "%s", S); }81 void printStr(const char *S) { fprintf(stderr, "%s", S); }
80 void print(StringView SV) {82 void print(std::string_view SV) {
81 fprintf(stderr, "\"%.*s\"", (int)SV.size(), SV.begin());83 fprintf(stderr, "\"%.*s\"", (int)SV.size(), &*SV.begin());
82 }84 }
83 void print(const Node *N) {85 void print(const Node *N) {
84 if (N)86 if (N)
lib/libcxxabi/src/cxa_guard_impl.h+3-3
...@@ -255,7 +255,7 @@ struct InitByteNoThreads {...@@ -255,7 +255,7 @@ struct InitByteNoThreads {
255 if (*init_byte_address == COMPLETE_BIT)255 if (*init_byte_address == COMPLETE_BIT)
256 return true;256 return true;
257 if (*init_byte_address & PENDING_BIT)257 if (*init_byte_address & PENDING_BIT)
258 ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization");258 ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization: do you have a function-local static variable whose initialization depends on that function?");
259 *init_byte_address = PENDING_BIT;259 *init_byte_address = PENDING_BIT;
260 return false;260 return false;
261 }261 }
...@@ -325,7 +325,7 @@ public:...@@ -325,7 +325,7 @@ public:
325 // Check for possible recursive initialization.325 // Check for possible recursive initialization.
326 if (has_thread_id_support && (*init_byte_address & PENDING_BIT)) {326 if (has_thread_id_support && (*init_byte_address & PENDING_BIT)) {
327 if (*thread_id_address == current_thread_id.get())327 if (*thread_id_address == current_thread_id.get())
328 ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization");328 ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization: do you have a function-local static variable whose initialization depends on that function?");
329 }329 }
330330
331 // Wait until the pending bit is not set.331 // Wait until the pending bit is not set.
...@@ -460,7 +460,7 @@ public:...@@ -460,7 +460,7 @@ public:
460460
461 // Check for recursive initialization461 // Check for recursive initialization
462 if (has_thread_id_support && thread_id.load(std::_AO_Relaxed) == current_thread_id.get()) {462 if (has_thread_id_support && thread_id.load(std::_AO_Relaxed) == current_thread_id.get()) {
463 ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization");463 ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization: do you have a function-local static variable whose initialization depends on that function?");
464 }464 }
465465
466 if ((last_val & WAITING_BIT) == 0) {466 if ((last_val & WAITING_BIT) == 0) {
lib/libcxxabi/src/demangle/DemangleConfig.h+8
...@@ -11,6 +11,14 @@...@@ -11,6 +11,14 @@
11#ifndef LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H11#ifndef LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
12#define LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H12#define LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
1313
14// Must be defined before pulling in headers from libc++. Allow downstream
15// build systems to override this value.
16// https://libcxx.llvm.org/UsingLibcxx.html#enabling-the-safe-libc-mode
17#ifndef _LIBCPP_VERBOSE_ABORT
18#define _LIBCPP_VERBOSE_ABORT(...) abort_message(__VA_ARGS__)
19#include "../abort_message.h"
20#endif
21
14#include <ciso646>22#include <ciso646>
1523
16#ifdef _MSC_VER24#ifdef _MSC_VER
lib/libcxxabi/src/demangle/ItaniumDemangle.h+154-134
...@@ -17,8 +17,9 @@...@@ -17,8 +17,9 @@
17#define DEMANGLE_ITANIUMDEMANGLE_H17#define DEMANGLE_ITANIUMDEMANGLE_H
1818
19#include "DemangleConfig.h"19#include "DemangleConfig.h"
20#include "StringView.h"20#include "StringViewExtras.h"
21#include "Utility.h"21#include "Utility.h"
22#include <__cxxabi_config.h>
22#include <algorithm>23#include <algorithm>
23#include <cassert>24#include <cassert>
24#include <cctype>25#include <cctype>
...@@ -27,8 +28,15 @@...@@ -27,8 +28,15 @@
27#include <cstring>28#include <cstring>
28#include <limits>29#include <limits>
29#include <new>30#include <new>
31#include <string_view>
32#include <type_traits>
30#include <utility>33#include <utility>
3134
35#ifdef _LIBCXXABI_COMPILER_CLANG
36#pragma clang diagnostic push
37#pragma clang diagnostic ignored "-Wunused-template"
38#endif
39
32DEMANGLE_NAMESPACE_BEGIN40DEMANGLE_NAMESPACE_BEGIN
3341
34template <class T, size_t N> class PODSmallVector {42template <class T, size_t N> class PODSmallVector {
...@@ -286,7 +294,7 @@ public:...@@ -286,7 +294,7 @@ public:
286 // implementation.294 // implementation.
287 virtual void printRight(OutputBuffer &) const {}295 virtual void printRight(OutputBuffer &) const {}
288296
289 virtual StringView getBaseName() const { return StringView(); }297 virtual std::string_view getBaseName() const { return {}; }
290298
291 // Silence compiler warnings, this dtor will never be called.299 // Silence compiler warnings, this dtor will never be called.
292 virtual ~Node() = default;300 virtual ~Node() = default;
...@@ -345,10 +353,10 @@ struct NodeArrayNode : Node {...@@ -345,10 +353,10 @@ struct NodeArrayNode : Node {
345353
346class DotSuffix final : public Node {354class DotSuffix final : public Node {
347 const Node *Prefix;355 const Node *Prefix;
348 const StringView Suffix;356 const std::string_view Suffix;
349357
350public:358public:
351 DotSuffix(const Node *Prefix_, StringView Suffix_)359 DotSuffix(const Node *Prefix_, std::string_view Suffix_)
352 : Node(KDotSuffix), Prefix(Prefix_), Suffix(Suffix_) {}360 : Node(KDotSuffix), Prefix(Prefix_), Suffix(Suffix_) {}
353361
354 template<typename Fn> void match(Fn F) const { F(Prefix, Suffix); }362 template<typename Fn> void match(Fn F) const { F(Prefix, Suffix); }
...@@ -363,15 +371,15 @@ public:...@@ -363,15 +371,15 @@ public:
363371
364class VendorExtQualType final : public Node {372class VendorExtQualType final : public Node {
365 const Node *Ty;373 const Node *Ty;
366 StringView Ext;374 std::string_view Ext;
367 const Node *TA;375 const Node *TA;
368376
369public:377public:
370 VendorExtQualType(const Node *Ty_, StringView Ext_, const Node *TA_)378 VendorExtQualType(const Node *Ty_, std::string_view Ext_, const Node *TA_)
371 : Node(KVendorExtQualType), Ty(Ty_), Ext(Ext_), TA(TA_) {}379 : Node(KVendorExtQualType), Ty(Ty_), Ext(Ext_), TA(TA_) {}
372380
373 const Node *getTy() const { return Ty; }381 const Node *getTy() const { return Ty; }
374 StringView getExt() const { return Ext; }382 std::string_view getExt() const { return Ext; }
375 const Node *getTA() const { return TA; }383 const Node *getTA() const { return TA; }
376384
377 template <typename Fn> void match(Fn F) const { F(Ty, Ext, TA); }385 template <typename Fn> void match(Fn F) const { F(Ty, Ext, TA); }
...@@ -462,10 +470,10 @@ public:...@@ -462,10 +470,10 @@ public:
462470
463class PostfixQualifiedType final : public Node {471class PostfixQualifiedType final : public Node {
464 const Node *Ty;472 const Node *Ty;
465 const StringView Postfix;473 const std::string_view Postfix;
466474
467public:475public:
468 PostfixQualifiedType(const Node *Ty_, StringView Postfix_)476 PostfixQualifiedType(const Node *Ty_, std::string_view Postfix_)
469 : Node(KPostfixQualifiedType), Ty(Ty_), Postfix(Postfix_) {}477 : Node(KPostfixQualifiedType), Ty(Ty_), Postfix(Postfix_) {}
470478
471 template<typename Fn> void match(Fn F) const { F(Ty, Postfix); }479 template<typename Fn> void match(Fn F) const { F(Ty, Postfix); }
...@@ -477,15 +485,15 @@ public:...@@ -477,15 +485,15 @@ public:
477};485};
478486
479class NameType final : public Node {487class NameType final : public Node {
480 const StringView Name;488 const std::string_view Name;
481489
482public:490public:
483 NameType(StringView Name_) : Node(KNameType), Name(Name_) {}491 NameType(std::string_view Name_) : Node(KNameType), Name(Name_) {}
484492
485 template<typename Fn> void match(Fn F) const { F(Name); }493 template<typename Fn> void match(Fn F) const { F(Name); }
486494
487 StringView getName() const { return Name; }495 std::string_view getName() const { return Name; }
488 StringView getBaseName() const override { return Name; }496 std::string_view getBaseName() const override { return Name; }
489497
490 void printLeft(OutputBuffer &OB) const override { OB += Name; }498 void printLeft(OutputBuffer &OB) const override { OB += Name; }
491};499};
...@@ -511,10 +519,10 @@ public:...@@ -511,10 +519,10 @@ public:
511};519};
512520
513class ElaboratedTypeSpefType : public Node {521class ElaboratedTypeSpefType : public Node {
514 StringView Kind;522 std::string_view Kind;
515 Node *Child;523 Node *Child;
516public:524public:
517 ElaboratedTypeSpefType(StringView Kind_, Node *Child_)525 ElaboratedTypeSpefType(std::string_view Kind_, Node *Child_)
518 : Node(KElaboratedTypeSpefType), Kind(Kind_), Child(Child_) {}526 : Node(KElaboratedTypeSpefType), Kind(Kind_), Child(Child_) {}
519527
520 template<typename Fn> void match(Fn F) const { F(Kind, Child); }528 template<typename Fn> void match(Fn F) const { F(Kind, Child); }
...@@ -528,15 +536,17 @@ public:...@@ -528,15 +536,17 @@ public:
528536
529struct AbiTagAttr : Node {537struct AbiTagAttr : Node {
530 Node *Base;538 Node *Base;
531 StringView Tag;539 std::string_view Tag;
532540
533 AbiTagAttr(Node* Base_, StringView Tag_)541 AbiTagAttr(Node *Base_, std::string_view Tag_)
534 : Node(KAbiTagAttr, Base_->RHSComponentCache,542 : Node(KAbiTagAttr, Base_->RHSComponentCache, Base_->ArrayCache,
535 Base_->ArrayCache, Base_->FunctionCache),543 Base_->FunctionCache),
536 Base(Base_), Tag(Tag_) {}544 Base(Base_), Tag(Tag_) {}
537545
538 template<typename Fn> void match(Fn F) const { F(Base, Tag); }546 template<typename Fn> void match(Fn F) const { F(Base, Tag); }
539547
548 std::string_view getBaseName() const override { return Base->getBaseName(); }
549
540 void printLeft(OutputBuffer &OB) const override {550 void printLeft(OutputBuffer &OB) const override {
541 Base->printLeft(OB);551 Base->printLeft(OB);
542 OB += "[abi:";552 OB += "[abi:";
...@@ -562,12 +572,12 @@ public:...@@ -562,12 +572,12 @@ public:
562572
563class ObjCProtoName : public Node {573class ObjCProtoName : public Node {
564 const Node *Ty;574 const Node *Ty;
565 StringView Protocol;575 std::string_view Protocol;
566576
567 friend class PointerType;577 friend class PointerType;
568578
569public:579public:
570 ObjCProtoName(const Node *Ty_, StringView Protocol_)580 ObjCProtoName(const Node *Ty_, std::string_view Protocol_)
571 : Node(KObjCProtoName), Ty(Ty_), Protocol(Protocol_) {}581 : Node(KObjCProtoName), Ty(Ty_), Protocol(Protocol_) {}
572582
573 template<typename Fn> void match(Fn F) const { F(Ty, Protocol); }583 template<typename Fn> void match(Fn F) const { F(Ty, Protocol); }
...@@ -944,11 +954,11 @@ public:...@@ -944,11 +954,11 @@ public:
944};954};
945955
946class SpecialName final : public Node {956class SpecialName final : public Node {
947 const StringView Special;957 const std::string_view Special;
948 const Node *Child;958 const Node *Child;
949959
950public:960public:
951 SpecialName(StringView Special_, const Node *Child_)961 SpecialName(std::string_view Special_, const Node *Child_)
952 : Node(KSpecialName), Special(Special_), Child(Child_) {}962 : Node(KSpecialName), Special(Special_), Child(Child_) {}
953963
954 template<typename Fn> void match(Fn F) const { F(Special, Child); }964 template<typename Fn> void match(Fn F) const { F(Special, Child); }
...@@ -987,7 +997,7 @@ struct NestedName : Node {...@@ -987,7 +997,7 @@ struct NestedName : Node {
987997
988 template<typename Fn> void match(Fn F) const { F(Qual, Name); }998 template<typename Fn> void match(Fn F) const { F(Qual, Name); }
989999
990 StringView getBaseName() const override { return Name->getBaseName(); }1000 std::string_view getBaseName() const override { return Name->getBaseName(); }
9911001
992 void printLeft(OutputBuffer &OB) const override {1002 void printLeft(OutputBuffer &OB) const override {
993 Qual->print(OB);1003 Qual->print(OB);
...@@ -1027,7 +1037,7 @@ struct ModuleEntity : Node {...@@ -1027,7 +1037,7 @@ struct ModuleEntity : Node {
10271037
1028 template <typename Fn> void match(Fn F) const { F(Module, Name); }1038 template <typename Fn> void match(Fn F) const { F(Module, Name); }
10291039
1030 StringView getBaseName() const override { return Name->getBaseName(); }1040 std::string_view getBaseName() const override { return Name->getBaseName(); }
10311041
1032 void printLeft(OutputBuffer &OB) const override {1042 void printLeft(OutputBuffer &OB) const override {
1033 Name->print(OB);1043 Name->print(OB);
...@@ -1063,7 +1073,7 @@ public:...@@ -1063,7 +1073,7 @@ public:
10631073
1064 template<typename Fn> void match(Fn F) const { F(Qualifier, Name); }1074 template<typename Fn> void match(Fn F) const { F(Qualifier, Name); }
10651075
1066 StringView getBaseName() const override { return Name->getBaseName(); }1076 std::string_view getBaseName() const override { return Name->getBaseName(); }
10671077
1068 void printLeft(OutputBuffer &OB) const override {1078 void printLeft(OutputBuffer &OB) const override {
1069 Qualifier->print(OB);1079 Qualifier->print(OB);
...@@ -1485,7 +1495,7 @@ struct NameWithTemplateArgs : Node {...@@ -1485,7 +1495,7 @@ struct NameWithTemplateArgs : Node {
14851495
1486 template<typename Fn> void match(Fn F) const { F(Name, TemplateArgs); }1496 template<typename Fn> void match(Fn F) const { F(Name, TemplateArgs); }
14871497
1488 StringView getBaseName() const override { return Name->getBaseName(); }1498 std::string_view getBaseName() const override { return Name->getBaseName(); }
14891499
1490 void printLeft(OutputBuffer &OB) const override {1500 void printLeft(OutputBuffer &OB) const override {
1491 Name->print(OB);1501 Name->print(OB);
...@@ -1502,7 +1512,7 @@ public:...@@ -1502,7 +1512,7 @@ public:
15021512
1503 template<typename Fn> void match(Fn F) const { F(Child); }1513 template<typename Fn> void match(Fn F) const { F(Child); }
15041514
1505 StringView getBaseName() const override { return Child->getBaseName(); }1515 std::string_view getBaseName() const override { return Child->getBaseName(); }
15061516
1507 void printLeft(OutputBuffer &OB) const override {1517 void printLeft(OutputBuffer &OB) const override {
1508 OB += "::";1518 OB += "::";
...@@ -1538,20 +1548,20 @@ protected:...@@ -1538,20 +1548,20 @@ protected:
1538 return unsigned(SSK) >= unsigned(SpecialSubKind::string);1548 return unsigned(SSK) >= unsigned(SpecialSubKind::string);
1539 }1549 }
15401550
1541 StringView getBaseName() const override {1551 std::string_view getBaseName() const override {
1542 switch (SSK) {1552 switch (SSK) {
1543 case SpecialSubKind::allocator:1553 case SpecialSubKind::allocator:
1544 return StringView("allocator");1554 return {"allocator"};
1545 case SpecialSubKind::basic_string:1555 case SpecialSubKind::basic_string:
1546 return StringView("basic_string");1556 return {"basic_string"};
1547 case SpecialSubKind::string:1557 case SpecialSubKind::string:
1548 return StringView("basic_string");1558 return {"basic_string"};
1549 case SpecialSubKind::istream:1559 case SpecialSubKind::istream:
1550 return StringView("basic_istream");1560 return {"basic_istream"};
1551 case SpecialSubKind::ostream:1561 case SpecialSubKind::ostream:
1552 return StringView("basic_ostream");1562 return {"basic_ostream"};
1553 case SpecialSubKind::iostream:1563 case SpecialSubKind::iostream:
1554 return StringView("basic_iostream");1564 return {"basic_iostream"};
1555 }1565 }
1556 DEMANGLE_UNREACHABLE;1566 DEMANGLE_UNREACHABLE;
1557 }1567 }
...@@ -1575,12 +1585,12 @@ public:...@@ -1575,12 +1585,12 @@ public:
15751585
1576 template<typename Fn> void match(Fn F) const { F(SSK); }1586 template<typename Fn> void match(Fn F) const { F(SSK); }
15771587
1578 StringView getBaseName() const override {1588 std::string_view getBaseName() const override {
1579 auto SV = ExpandedSpecialSubstitution::getBaseName ();1589 std::string_view SV = ExpandedSpecialSubstitution::getBaseName();
1580 if (isInstantiation()) {1590 if (isInstantiation()) {
1581 // The instantiations are typedefs that drop the "basic_" prefix.1591 // The instantiations are typedefs that drop the "basic_" prefix.
1582 assert(SV.startsWith("basic_"));1592 assert(starts_with(SV, "basic_"));
1583 SV = SV.dropFront(sizeof("basic_") - 1);1593 SV.remove_prefix(sizeof("basic_") - 1);
1584 }1594 }
1585 return SV;1595 return SV;
1586 }1596 }
...@@ -1628,10 +1638,11 @@ public:...@@ -1628,10 +1638,11 @@ public:
1628};1638};
16291639
1630class UnnamedTypeName : public Node {1640class UnnamedTypeName : public Node {
1631 const StringView Count;1641 const std::string_view Count;
16321642
1633public:1643public:
1634 UnnamedTypeName(StringView Count_) : Node(KUnnamedTypeName), Count(Count_) {}1644 UnnamedTypeName(std::string_view Count_)
1645 : Node(KUnnamedTypeName), Count(Count_) {}
16351646
1636 template<typename Fn> void match(Fn F) const { F(Count); }1647 template<typename Fn> void match(Fn F) const { F(Count); }
16371648
...@@ -1645,11 +1656,11 @@ public:...@@ -1645,11 +1656,11 @@ public:
1645class ClosureTypeName : public Node {1656class ClosureTypeName : public Node {
1646 NodeArray TemplateParams;1657 NodeArray TemplateParams;
1647 NodeArray Params;1658 NodeArray Params;
1648 StringView Count;1659 std::string_view Count;
16491660
1650public:1661public:
1651 ClosureTypeName(NodeArray TemplateParams_, NodeArray Params_,1662 ClosureTypeName(NodeArray TemplateParams_, NodeArray Params_,
1652 StringView Count_)1663 std::string_view Count_)
1653 : Node(KClosureTypeName), TemplateParams(TemplateParams_),1664 : Node(KClosureTypeName), TemplateParams(TemplateParams_),
1654 Params(Params_), Count(Count_) {}1665 Params(Params_), Count(Count_) {}
16551666
...@@ -1696,12 +1707,12 @@ public:...@@ -1696,12 +1707,12 @@ public:
16961707
1697class BinaryExpr : public Node {1708class BinaryExpr : public Node {
1698 const Node *LHS;1709 const Node *LHS;
1699 const StringView InfixOperator;1710 const std::string_view InfixOperator;
1700 const Node *RHS;1711 const Node *RHS;
17011712
1702public:1713public:
1703 BinaryExpr(const Node *LHS_, StringView InfixOperator_, const Node *RHS_,1714 BinaryExpr(const Node *LHS_, std::string_view InfixOperator_,
1704 Prec Prec_)1715 const Node *RHS_, Prec Prec_)
1705 : Node(KBinaryExpr, Prec_), LHS(LHS_), InfixOperator(InfixOperator_),1716 : Node(KBinaryExpr, Prec_), LHS(LHS_), InfixOperator(InfixOperator_),
1706 RHS(RHS_) {}1717 RHS(RHS_) {}
17071718
...@@ -1750,10 +1761,10 @@ public:...@@ -1750,10 +1761,10 @@ public:
17501761
1751class PostfixExpr : public Node {1762class PostfixExpr : public Node {
1752 const Node *Child;1763 const Node *Child;
1753 const StringView Operator;1764 const std::string_view Operator;
17541765
1755public:1766public:
1756 PostfixExpr(const Node *Child_, StringView Operator_, Prec Prec_)1767 PostfixExpr(const Node *Child_, std::string_view Operator_, Prec Prec_)
1757 : Node(KPostfixExpr, Prec_), Child(Child_), Operator(Operator_) {}1768 : Node(KPostfixExpr, Prec_), Child(Child_), Operator(Operator_) {}
17581769
1759 template <typename Fn> void match(Fn F) const {1770 template <typename Fn> void match(Fn F) const {
...@@ -1791,11 +1802,12 @@ public:...@@ -1791,11 +1802,12 @@ public:
17911802
1792class MemberExpr : public Node {1803class MemberExpr : public Node {
1793 const Node *LHS;1804 const Node *LHS;
1794 const StringView Kind;1805 const std::string_view Kind;
1795 const Node *RHS;1806 const Node *RHS;
17961807
1797public:1808public:
1798 MemberExpr(const Node *LHS_, StringView Kind_, const Node *RHS_, Prec Prec_)1809 MemberExpr(const Node *LHS_, std::string_view Kind_, const Node *RHS_,
1810 Prec Prec_)
1799 : Node(KMemberExpr, Prec_), LHS(LHS_), Kind(Kind_), RHS(RHS_) {}1811 : Node(KMemberExpr, Prec_), LHS(LHS_), Kind(Kind_), RHS(RHS_) {}
18001812
1801 template <typename Fn> void match(Fn F) const {1813 template <typename Fn> void match(Fn F) const {
...@@ -1812,13 +1824,14 @@ public:...@@ -1812,13 +1824,14 @@ public:
1812class SubobjectExpr : public Node {1824class SubobjectExpr : public Node {
1813 const Node *Type;1825 const Node *Type;
1814 const Node *SubExpr;1826 const Node *SubExpr;
1815 StringView Offset;1827 std::string_view Offset;
1816 NodeArray UnionSelectors;1828 NodeArray UnionSelectors;
1817 bool OnePastTheEnd;1829 bool OnePastTheEnd;
18181830
1819public:1831public:
1820 SubobjectExpr(const Node *Type_, const Node *SubExpr_, StringView Offset_,1832 SubobjectExpr(const Node *Type_, const Node *SubExpr_,
1821 NodeArray UnionSelectors_, bool OnePastTheEnd_)1833 std::string_view Offset_, NodeArray UnionSelectors_,
1834 bool OnePastTheEnd_)
1822 : Node(KSubobjectExpr), Type(Type_), SubExpr(SubExpr_), Offset(Offset_),1835 : Node(KSubobjectExpr), Type(Type_), SubExpr(SubExpr_), Offset(Offset_),
1823 UnionSelectors(UnionSelectors_), OnePastTheEnd(OnePastTheEnd_) {}1836 UnionSelectors(UnionSelectors_), OnePastTheEnd(OnePastTheEnd_) {}
18241837
...@@ -1835,7 +1848,7 @@ public:...@@ -1835,7 +1848,7 @@ public:
1835 OB += "0";1848 OB += "0";
1836 } else if (Offset[0] == 'n') {1849 } else if (Offset[0] == 'n') {
1837 OB += "-";1850 OB += "-";
1838 OB += Offset.dropFront();1851 OB += std::string_view(Offset.data() + 1, Offset.size() - 1);
1839 } else {1852 } else {
1840 OB += Offset;1853 OB += Offset;
1841 }1854 }
...@@ -1844,12 +1857,12 @@ public:...@@ -1844,12 +1857,12 @@ public:
1844};1857};
18451858
1846class EnclosingExpr : public Node {1859class EnclosingExpr : public Node {
1847 const StringView Prefix;1860 const std::string_view Prefix;
1848 const Node *Infix;1861 const Node *Infix;
1849 const StringView Postfix;1862 const std::string_view Postfix;
18501863
1851public:1864public:
1852 EnclosingExpr(StringView Prefix_, const Node *Infix_,1865 EnclosingExpr(std::string_view Prefix_, const Node *Infix_,
1853 Prec Prec_ = Prec::Primary)1866 Prec Prec_ = Prec::Primary)
1854 : Node(KEnclosingExpr, Prec_), Prefix(Prefix_), Infix(Infix_) {}1867 : Node(KEnclosingExpr, Prec_), Prefix(Prefix_), Infix(Infix_) {}
18551868
...@@ -1868,12 +1881,13 @@ public:...@@ -1868,12 +1881,13 @@ public:
18681881
1869class CastExpr : public Node {1882class CastExpr : public Node {
1870 // cast_kind<to>(from)1883 // cast_kind<to>(from)
1871 const StringView CastKind;1884 const std::string_view CastKind;
1872 const Node *To;1885 const Node *To;
1873 const Node *From;1886 const Node *From;
18741887
1875public:1888public:
1876 CastExpr(StringView CastKind_, const Node *To_, const Node *From_, Prec Prec_)1889 CastExpr(std::string_view CastKind_, const Node *To_, const Node *From_,
1890 Prec Prec_)
1877 : Node(KCastExpr, Prec_), CastKind(CastKind_), To(To_), From(From_) {}1891 : Node(KCastExpr, Prec_), CastKind(CastKind_), To(To_), From(From_) {}
18781892
1879 template <typename Fn> void match(Fn F) const {1893 template <typename Fn> void match(Fn F) const {
...@@ -1996,11 +2010,11 @@ public:...@@ -1996,11 +2010,11 @@ public:
1996};2010};
19972011
1998class PrefixExpr : public Node {2012class PrefixExpr : public Node {
1999 StringView Prefix;2013 std::string_view Prefix;
2000 Node *Child;2014 Node *Child;
20012015
2002public:2016public:
2003 PrefixExpr(StringView Prefix_, Node *Child_, Prec Prec_)2017 PrefixExpr(std::string_view Prefix_, Node *Child_, Prec Prec_)
2004 : Node(KPrefixExpr, Prec_), Prefix(Prefix_), Child(Child_) {}2018 : Node(KPrefixExpr, Prec_), Prefix(Prefix_), Child(Child_) {}
20052019
2006 template <typename Fn> void match(Fn F) const {2020 template <typename Fn> void match(Fn F) const {
...@@ -2014,10 +2028,11 @@ public:...@@ -2014,10 +2028,11 @@ public:
2014};2028};
20152029
2016class FunctionParam : public Node {2030class FunctionParam : public Node {
2017 StringView Number;2031 std::string_view Number;
20182032
2019public:2033public:
2020 FunctionParam(StringView Number_) : Node(KFunctionParam), Number(Number_) {}2034 FunctionParam(std::string_view Number_)
2035 : Node(KFunctionParam), Number(Number_) {}
20212036
2022 template<typename Fn> void match(Fn F) const { F(Number); }2037 template<typename Fn> void match(Fn F) const { F(Number); }
20232038
...@@ -2052,11 +2067,11 @@ public:...@@ -2052,11 +2067,11 @@ public:
2052class PointerToMemberConversionExpr : public Node {2067class PointerToMemberConversionExpr : public Node {
2053 const Node *Type;2068 const Node *Type;
2054 const Node *SubExpr;2069 const Node *SubExpr;
2055 StringView Offset;2070 std::string_view Offset;
20562071
2057public:2072public:
2058 PointerToMemberConversionExpr(const Node *Type_, const Node *SubExpr_,2073 PointerToMemberConversionExpr(const Node *Type_, const Node *SubExpr_,
2059 StringView Offset_, Prec Prec_)2074 std::string_view Offset_, Prec Prec_)
2060 : Node(KPointerToMemberConversionExpr, Prec_), Type(Type_),2075 : Node(KPointerToMemberConversionExpr, Prec_), Type(Type_),
2061 SubExpr(SubExpr_), Offset(Offset_) {}2076 SubExpr(SubExpr_), Offset(Offset_) {}
20622077
...@@ -2141,11 +2156,11 @@ public:...@@ -2141,11 +2156,11 @@ public:
21412156
2142class FoldExpr : public Node {2157class FoldExpr : public Node {
2143 const Node *Pack, *Init;2158 const Node *Pack, *Init;
2144 StringView OperatorName;2159 std::string_view OperatorName;
2145 bool IsLeftFold;2160 bool IsLeftFold;
21462161
2147public:2162public:
2148 FoldExpr(bool IsLeftFold_, StringView OperatorName_, const Node *Pack_,2163 FoldExpr(bool IsLeftFold_, std::string_view OperatorName_, const Node *Pack_,
2149 const Node *Init_)2164 const Node *Init_)
2150 : Node(KFoldExpr), Pack(Pack_), Init(Init_), OperatorName(OperatorName_),2165 : Node(KFoldExpr), Pack(Pack_), Init(Init_), OperatorName(OperatorName_),
2151 IsLeftFold(IsLeftFold_) {}2166 IsLeftFold(IsLeftFold_) {}
...@@ -2209,7 +2224,7 @@ public:...@@ -2209,7 +2224,7 @@ public:
2209 template<typename Fn> void match(Fn F) const { F(Value); }2224 template<typename Fn> void match(Fn F) const { F(Value); }
22102225
2211 void printLeft(OutputBuffer &OB) const override {2226 void printLeft(OutputBuffer &OB) const override {
2212 OB += Value ? StringView("true") : StringView("false");2227 OB += Value ? std::string_view("true") : std::string_view("false");
2213 }2228 }
2214};2229};
22152230
...@@ -2247,10 +2262,10 @@ public:...@@ -2247,10 +2262,10 @@ public:
2247class EnumLiteral : public Node {2262class EnumLiteral : public Node {
2248 // ty(integer)2263 // ty(integer)
2249 const Node *Ty;2264 const Node *Ty;
2250 StringView Integer;2265 std::string_view Integer;
22512266
2252public:2267public:
2253 EnumLiteral(const Node *Ty_, StringView Integer_)2268 EnumLiteral(const Node *Ty_, std::string_view Integer_)
2254 : Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {}2269 : Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {}
22552270
2256 template<typename Fn> void match(Fn F) const { F(Ty, Integer); }2271 template<typename Fn> void match(Fn F) const { F(Ty, Integer); }
...@@ -2261,18 +2276,18 @@ public:...@@ -2261,18 +2276,18 @@ public:
2261 OB.printClose();2276 OB.printClose();
22622277
2263 if (Integer[0] == 'n')2278 if (Integer[0] == 'n')
2264 OB << "-" << Integer.dropFront(1);2279 OB << '-' << std::string_view(Integer.data() + 1, Integer.size() - 1);
2265 else2280 else
2266 OB << Integer;2281 OB << Integer;
2267 }2282 }
2268};2283};
22692284
2270class IntegerLiteral : public Node {2285class IntegerLiteral : public Node {
2271 StringView Type;2286 std::string_view Type;
2272 StringView Value;2287 std::string_view Value;
22732288
2274public:2289public:
2275 IntegerLiteral(StringView Type_, StringView Value_)2290 IntegerLiteral(std::string_view Type_, std::string_view Value_)
2276 : Node(KIntegerLiteral), Type(Type_), Value(Value_) {}2291 : Node(KIntegerLiteral), Type(Type_), Value(Value_) {}
22772292
2278 template<typename Fn> void match(Fn F) const { F(Type, Value); }2293 template<typename Fn> void match(Fn F) const { F(Type, Value); }
...@@ -2284,10 +2299,9 @@ public:...@@ -2284,10 +2299,9 @@ public:
2284 OB.printClose();2299 OB.printClose();
2285 }2300 }
22862301
2287 if (Value[0] == 'n') {2302 if (Value[0] == 'n')
2288 OB += '-';2303 OB << '-' << std::string_view(Value.data() + 1, Value.size() - 1);
2289 OB += Value.dropFront(1);2304 else
2290 } else
2291 OB += Value;2305 OB += Value;
22922306
2293 if (Type.size() <= 3)2307 if (Type.size() <= 3)
...@@ -2310,29 +2324,26 @@ constexpr Node::Kind getFloatLiteralKind(long double *) {...@@ -2310,29 +2324,26 @@ constexpr Node::Kind getFloatLiteralKind(long double *) {
2310}2324}
23112325
2312template <class Float> class FloatLiteralImpl : public Node {2326template <class Float> class FloatLiteralImpl : public Node {
2313 const StringView Contents;2327 const std::string_view Contents;
23142328
2315 static constexpr Kind KindForClass =2329 static constexpr Kind KindForClass =
2316 float_literal_impl::getFloatLiteralKind((Float *)nullptr);2330 float_literal_impl::getFloatLiteralKind((Float *)nullptr);
23172331
2318public:2332public:
2319 FloatLiteralImpl(StringView Contents_)2333 FloatLiteralImpl(std::string_view Contents_)
2320 : Node(KindForClass), Contents(Contents_) {}2334 : Node(KindForClass), Contents(Contents_) {}
23212335
2322 template<typename Fn> void match(Fn F) const { F(Contents); }2336 template<typename Fn> void match(Fn F) const { F(Contents); }
23232337
2324 void printLeft(OutputBuffer &OB) const override {2338 void printLeft(OutputBuffer &OB) const override {
2325 const char *first = Contents.begin();
2326 const char *last = Contents.end() + 1;
2327
2328 const size_t N = FloatData<Float>::mangled_size;2339 const size_t N = FloatData<Float>::mangled_size;
2329 if (static_cast<std::size_t>(last - first) > N) {2340 if (Contents.size() >= N) {
2330 last = first + N;
2331 union {2341 union {
2332 Float value;2342 Float value;
2333 char buf[sizeof(Float)];2343 char buf[sizeof(Float)];
2334 };2344 };
2335 const char *t = first;2345 const char *t = Contents.data();
2346 const char *last = t + N;
2336 char *e = buf;2347 char *e = buf;
2337 for (; t != last; ++t, ++e) {2348 for (; t != last; ++t, ++e) {
2338 unsigned d1 = isdigit(*t) ? static_cast<unsigned>(*t - '0')2349 unsigned d1 = isdigit(*t) ? static_cast<unsigned>(*t - '0')
...@@ -2347,7 +2358,7 @@ public:...@@ -2347,7 +2358,7 @@ public:
2347#endif2358#endif
2348 char num[FloatData<Float>::max_demangled_size] = {0};2359 char num[FloatData<Float>::max_demangled_size] = {0};
2349 int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);2360 int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
2350 OB += StringView(num, num + n);2361 OB += std::string_view(num, n);
2351 }2362 }
2352 }2363 }
2353};2364};
...@@ -2474,8 +2485,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {...@@ -2474,8 +2485,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
2474 return res;2485 return res;
2475 }2486 }
24762487
2477 bool consumeIf(StringView S) {2488 bool consumeIf(std::string_view S) {
2478 if (StringView(First, Last).startsWith(S)) {2489 if (starts_with(std::string_view(First, Last - First), S)) {
2479 First += S.size();2490 First += S.size();
2480 return true;2491 return true;
2481 }2492 }
...@@ -2500,10 +2511,10 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {...@@ -2500,10 +2511,10 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
25002511
2501 size_t numLeft() const { return static_cast<size_t>(Last - First); }2512 size_t numLeft() const { return static_cast<size_t>(Last - First); }
25022513
2503 StringView parseNumber(bool AllowNegative = false);2514 std::string_view parseNumber(bool AllowNegative = false);
2504 Qualifiers parseCVQualifiers();2515 Qualifiers parseCVQualifiers();
2505 bool parsePositiveInteger(size_t *Out);2516 bool parsePositiveInteger(size_t *Out);
2506 StringView parseBareSourceName();2517 std::string_view parseBareSourceName();
25072518
2508 bool parseSeqId(size_t *Out);2519 bool parseSeqId(size_t *Out);
2509 Node *parseSubstitution();2520 Node *parseSubstitution();
...@@ -2514,9 +2525,9 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {...@@ -2514,9 +2525,9 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
25142525
2515 /// Parse the <expr> production.2526 /// Parse the <expr> production.
2516 Node *parseExpr();2527 Node *parseExpr();
2517 Node *parsePrefixExpr(StringView Kind, Node::Prec Prec);2528 Node *parsePrefixExpr(std::string_view Kind, Node::Prec Prec);
2518 Node *parseBinaryExpr(StringView Kind, Node::Prec Prec);2529 Node *parseBinaryExpr(std::string_view Kind, Node::Prec Prec);
2519 Node *parseIntegerLiteral(StringView Lit);2530 Node *parseIntegerLiteral(std::string_view Lit);
2520 Node *parseExprPrimary();2531 Node *parseExprPrimary();
2521 template <class Float> Node *parseFloatingLiteral();2532 template <class Float> Node *parseFloatingLiteral();
2522 Node *parseFunctionParam();2533 Node *parseFunctionParam();
...@@ -2624,17 +2635,18 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {...@@ -2624,17 +2635,18 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
2624 bool operator!=(const char *Peek) const { return !this->operator==(Peek); }2635 bool operator!=(const char *Peek) const { return !this->operator==(Peek); }
26252636
2626 public:2637 public:
2627 StringView getSymbol() const {2638 std::string_view getSymbol() const {
2628 StringView Res = Name;2639 std::string_view Res = Name;
2629 if (Kind < Unnameable) {2640 if (Kind < Unnameable) {
2630 assert(Res.startsWith("operator") &&2641 assert(starts_with(Res, "operator") &&
2631 "operator name does not start with 'operator'");2642 "operator name does not start with 'operator'");
2632 Res = Res.dropFront(sizeof("operator") - 1);2643 Res.remove_prefix(sizeof("operator") - 1);
2633 Res.consumeFront(' ');2644 if (starts_with(Res, ' '))
2645 Res.remove_prefix(1);
2634 }2646 }
2635 return Res;2647 return Res;
2636 }2648 }
2637 StringView getName() const { return Name; }2649 std::string_view getName() const { return Name; }
2638 OIKind getKind() const { return Kind; }2650 OIKind getKind() const { return Kind; }
2639 bool getFlag() const { return Flag; }2651 bool getFlag() const { return Flag; }
2640 Node::Prec getPrecedence() const { return Prec; }2652 Node::Prec getPrecedence() const { return Prec; }
...@@ -2854,7 +2866,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {...@@ -2854,7 +2866,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {
2854 TemplateParams.clear();2866 TemplateParams.clear();
28552867
2856 if (consumeIf("Ut")) {2868 if (consumeIf("Ut")) {
2857 StringView Count = parseNumber();2869 std::string_view Count = parseNumber();
2858 if (!consumeIf('_'))2870 if (!consumeIf('_'))
2859 return nullptr;2871 return nullptr;
2860 return make<UnnamedTypeName>(Count);2872 return make<UnnamedTypeName>(Count);
...@@ -2866,7 +2878,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {...@@ -2866,7 +2878,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {
28662878
2867 size_t ParamsBegin = Names.size();2879 size_t ParamsBegin = Names.size();
2868 while (look() == 'T' &&2880 while (look() == 'T' &&
2869 StringView("yptn").find(look(1)) != StringView::npos) {2881 std::string_view("yptn").find(look(1)) != std::string_view::npos) {
2870 Node *T = parseTemplateParamDecl();2882 Node *T = parseTemplateParamDecl();
2871 if (!T)2883 if (!T)
2872 return nullptr;2884 return nullptr;
...@@ -2909,7 +2921,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {...@@ -2909,7 +2921,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {
2909 }2921 }
2910 NodeArray Params = popTrailingNodeArray(ParamsBegin);2922 NodeArray Params = popTrailingNodeArray(ParamsBegin);
29112923
2912 StringView Count = parseNumber();2924 std::string_view Count = parseNumber();
2913 if (!consumeIf('_'))2925 if (!consumeIf('_'))
2914 return nullptr;2926 return nullptr;
2915 return make<ClosureTypeName>(TempParams, Params, Count);2927 return make<ClosureTypeName>(TempParams, Params, Count);
...@@ -2931,9 +2943,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSourceName(NameState *) {...@@ -2931,9 +2943,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSourceName(NameState *) {
2931 return nullptr;2943 return nullptr;
2932 if (numLeft() < Length || Length == 0)2944 if (numLeft() < Length || Length == 0)
2933 return nullptr;2945 return nullptr;
2934 StringView Name(First, First + Length);2946 std::string_view Name(First, Length);
2935 First += Length;2947 First += Length;
2936 if (Name.startsWith("_GLOBAL__N"))2948 if (starts_with(Name, "_GLOBAL__N"))
2937 return make<NameType>("(anonymous namespace)");2949 return make<NameType>("(anonymous namespace)");
2938 return make<NameType>(Name);2950 return make<NameType>(Name);
2939}2951}
...@@ -3447,7 +3459,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseUnresolvedName(bool Global) {...@@ -3447,7 +3459,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseUnresolvedName(bool Global) {
3447template <typename Derived, typename Alloc>3459template <typename Derived, typename Alloc>
3448Node *AbstractManglingParser<Derived, Alloc>::parseAbiTags(Node *N) {3460Node *AbstractManglingParser<Derived, Alloc>::parseAbiTags(Node *N) {
3449 while (consumeIf('B')) {3461 while (consumeIf('B')) {
3450 StringView SN = parseBareSourceName();3462 std::string_view SN = parseBareSourceName();
3451 if (SN.empty())3463 if (SN.empty())
3452 return nullptr;3464 return nullptr;
3453 N = make<AbiTagAttr>(N, SN);3465 N = make<AbiTagAttr>(N, SN);
...@@ -3459,16 +3471,16 @@ Node *AbstractManglingParser<Derived, Alloc>::parseAbiTags(Node *N) {...@@ -3459,16 +3471,16 @@ Node *AbstractManglingParser<Derived, Alloc>::parseAbiTags(Node *N) {
34593471
3460// <number> ::= [n] <non-negative decimal integer>3472// <number> ::= [n] <non-negative decimal integer>
3461template <typename Alloc, typename Derived>3473template <typename Alloc, typename Derived>
3462StringView3474std::string_view
3463AbstractManglingParser<Alloc, Derived>::parseNumber(bool AllowNegative) {3475AbstractManglingParser<Alloc, Derived>::parseNumber(bool AllowNegative) {
3464 const char *Tmp = First;3476 const char *Tmp = First;
3465 if (AllowNegative)3477 if (AllowNegative)
3466 consumeIf('n');3478 consumeIf('n');
3467 if (numLeft() == 0 || !std::isdigit(*First))3479 if (numLeft() == 0 || !std::isdigit(*First))
3468 return StringView();3480 return std::string_view();
3469 while (numLeft() != 0 && std::isdigit(*First))3481 while (numLeft() != 0 && std::isdigit(*First))
3470 ++First;3482 ++First;
3471 return StringView(Tmp, First);3483 return std::string_view(Tmp, First - Tmp);
3472}3484}
34733485
3474// <positive length number> ::= [0-9]*3486// <positive length number> ::= [0-9]*
...@@ -3485,11 +3497,11 @@ bool AbstractManglingParser<Alloc, Derived>::parsePositiveInteger(size_t *Out) {...@@ -3485,11 +3497,11 @@ bool AbstractManglingParser<Alloc, Derived>::parsePositiveInteger(size_t *Out) {
3485}3497}
34863498
3487template <typename Alloc, typename Derived>3499template <typename Alloc, typename Derived>
3488StringView AbstractManglingParser<Alloc, Derived>::parseBareSourceName() {3500std::string_view AbstractManglingParser<Alloc, Derived>::parseBareSourceName() {
3489 size_t Int = 0;3501 size_t Int = 0;
3490 if (parsePositiveInteger(&Int) || numLeft() < Int)3502 if (parsePositiveInteger(&Int) || numLeft() < Int)
3491 return StringView();3503 return {};
3492 StringView R(First, First + Int);3504 std::string_view R(First, Int);
3493 First += Int;3505 First += Int;
3494 return R;3506 return R;
3495}3507}
...@@ -3673,7 +3685,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parsePointerToMemberType() {...@@ -3673,7 +3685,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parsePointerToMemberType() {
3673// ::= Te <name> # dependent elaborated type specifier using 'enum'3685// ::= Te <name> # dependent elaborated type specifier using 'enum'
3674template <typename Derived, typename Alloc>3686template <typename Derived, typename Alloc>
3675Node *AbstractManglingParser<Derived, Alloc>::parseClassEnumType() {3687Node *AbstractManglingParser<Derived, Alloc>::parseClassEnumType() {
3676 StringView ElabSpef;3688 std::string_view ElabSpef;
3677 if (consumeIf("Ts"))3689 if (consumeIf("Ts"))
3678 ElabSpef = "struct";3690 ElabSpef = "struct";
3679 else if (consumeIf("Tu"))3691 else if (consumeIf("Tu"))
...@@ -3697,17 +3709,18 @@ Node *AbstractManglingParser<Derived, Alloc>::parseClassEnumType() {...@@ -3697,17 +3709,18 @@ Node *AbstractManglingParser<Derived, Alloc>::parseClassEnumType() {
3697template <typename Derived, typename Alloc>3709template <typename Derived, typename Alloc>
3698Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {3710Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {
3699 if (consumeIf('U')) {3711 if (consumeIf('U')) {
3700 StringView Qual = parseBareSourceName();3712 std::string_view Qual = parseBareSourceName();
3701 if (Qual.empty())3713 if (Qual.empty())
3702 return nullptr;3714 return nullptr;
37033715
3704 // extension ::= U <objc-name> <objc-type> # objc-type<identifier>3716 // extension ::= U <objc-name> <objc-type> # objc-type<identifier>
3705 if (Qual.startsWith("objcproto")) {3717 if (starts_with(Qual, "objcproto")) {
3706 StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto"));3718 constexpr size_t Len = sizeof("objcproto") - 1;
3707 StringView Proto;3719 std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len);
3720 std::string_view Proto;
3708 {3721 {
3709 ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.begin()),3722 ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.data()),
3710 SaveLast(Last, ProtoSourceName.end());3723 SaveLast(Last, &*ProtoSourceName.rbegin() + 1);
3711 Proto = parseBareSourceName();3724 Proto = parseBareSourceName();
3712 }3725 }
3713 if (Proto.empty())3726 if (Proto.empty())
...@@ -3875,7 +3888,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {...@@ -3875,7 +3888,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
3875 // <builtin-type> ::= u <source-name> # vendor extended type3888 // <builtin-type> ::= u <source-name> # vendor extended type
3876 case 'u': {3889 case 'u': {
3877 ++First;3890 ++First;
3878 StringView Res = parseBareSourceName();3891 std::string_view Res = parseBareSourceName();
3879 if (Res.empty())3892 if (Res.empty())
3880 return nullptr;3893 return nullptr;
3881 // Typically, <builtin-type>s are not considered substitution candidates,3894 // Typically, <builtin-type>s are not considered substitution candidates,
...@@ -4123,8 +4136,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {...@@ -4123,8 +4136,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
4123}4136}
41244137
4125template <typename Derived, typename Alloc>4138template <typename Derived, typename Alloc>
4126Node *AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(StringView Kind,4139Node *
4127 Node::Prec Prec) {4140AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(std::string_view Kind,
4141 Node::Prec Prec) {
4128 Node *E = getDerived().parseExpr();4142 Node *E = getDerived().parseExpr();
4129 if (E == nullptr)4143 if (E == nullptr)
4130 return nullptr;4144 return nullptr;
...@@ -4132,8 +4146,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(StringView Kind,...@@ -4132,8 +4146,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(StringView Kind,
4132}4146}
41334147
4134template <typename Derived, typename Alloc>4148template <typename Derived, typename Alloc>
4135Node *AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(StringView Kind,4149Node *
4136 Node::Prec Prec) {4150AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(std::string_view Kind,
4151 Node::Prec Prec) {
4137 Node *LHS = getDerived().parseExpr();4152 Node *LHS = getDerived().parseExpr();
4138 if (LHS == nullptr)4153 if (LHS == nullptr)
4139 return nullptr;4154 return nullptr;
...@@ -4144,9 +4159,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(StringView Kind,...@@ -4144,9 +4159,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(StringView Kind,
4144}4159}
41454160
4146template <typename Derived, typename Alloc>4161template <typename Derived, typename Alloc>
4147Node *4162Node *AbstractManglingParser<Derived, Alloc>::parseIntegerLiteral(
4148AbstractManglingParser<Derived, Alloc>::parseIntegerLiteral(StringView Lit) {4163 std::string_view Lit) {
4149 StringView Tmp = parseNumber(true);4164 std::string_view Tmp = parseNumber(true);
4150 if (!Tmp.empty() && consumeIf('E'))4165 if (!Tmp.empty() && consumeIf('E'))
4151 return make<IntegerLiteral>(Lit, Tmp);4166 return make<IntegerLiteral>(Lit, Tmp);
4152 return nullptr;4167 return nullptr;
...@@ -4176,7 +4191,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() {...@@ -4176,7 +4191,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() {
4176 return make<NameType>("this");4191 return make<NameType>("this");
4177 if (consumeIf("fp")) {4192 if (consumeIf("fp")) {
4178 parseCVQualifiers();4193 parseCVQualifiers();
4179 StringView Num = parseNumber();4194 std::string_view Num = parseNumber();
4180 if (!consumeIf('_'))4195 if (!consumeIf('_'))
4181 return nullptr;4196 return nullptr;
4182 return make<FunctionParam>(Num);4197 return make<FunctionParam>(Num);
...@@ -4187,7 +4202,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() {...@@ -4187,7 +4202,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() {
4187 if (!consumeIf('p'))4202 if (!consumeIf('p'))
4188 return nullptr;4203 return nullptr;
4189 parseCVQualifiers();4204 parseCVQualifiers();
4190 StringView Num = parseNumber();4205 std::string_view Num = parseNumber();
4191 if (!consumeIf('_'))4206 if (!consumeIf('_'))
4192 return nullptr;4207 return nullptr;
4193 return make<FunctionParam>(Num);4208 return make<FunctionParam>(Num);
...@@ -4341,7 +4356,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {...@@ -4341,7 +4356,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {
4341 Node *T = getDerived().parseType();4356 Node *T = getDerived().parseType();
4342 if (T == nullptr)4357 if (T == nullptr)
4343 return nullptr;4358 return nullptr;
4344 StringView N = parseNumber(/*AllowNegative=*/true);4359 std::string_view N = parseNumber(/*AllowNegative=*/true);
4345 if (N.empty())4360 if (N.empty())
4346 return nullptr;4361 return nullptr;
4347 if (!consumeIf('E'))4362 if (!consumeIf('E'))
...@@ -4464,7 +4479,7 @@ AbstractManglingParser<Derived, Alloc>::parsePointerToMemberConversionExpr(...@@ -4464,7 +4479,7 @@ AbstractManglingParser<Derived, Alloc>::parsePointerToMemberConversionExpr(
4464 Node *Expr = getDerived().parseExpr();4479 Node *Expr = getDerived().parseExpr();
4465 if (!Expr)4480 if (!Expr)
4466 return nullptr;4481 return nullptr;
4467 StringView Offset = getDerived().parseNumber(true);4482 std::string_view Offset = getDerived().parseNumber(true);
4468 if (!consumeIf('E'))4483 if (!consumeIf('E'))
4469 return nullptr;4484 return nullptr;
4470 return make<PointerToMemberConversionExpr>(Ty, Expr, Offset, Prec);4485 return make<PointerToMemberConversionExpr>(Ty, Expr, Offset, Prec);
...@@ -4482,7 +4497,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSubobjectExpr() {...@@ -4482,7 +4497,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSubobjectExpr() {
4482 Node *Expr = getDerived().parseExpr();4497 Node *Expr = getDerived().parseExpr();
4483 if (!Expr)4498 if (!Expr)
4484 return nullptr;4499 return nullptr;
4485 StringView Offset = getDerived().parseNumber(true);4500 std::string_view Offset = getDerived().parseNumber(true);
4486 size_t SelectorsBegin = Names.size();4501 size_t SelectorsBegin = Names.size();
4487 while (consumeIf('_')) {4502 while (consumeIf('_')) {
4488 Node *Selector = make<NameType>(parseNumber());4503 Node *Selector = make<NameType>(parseNumber());
...@@ -5141,7 +5156,7 @@ Node *AbstractManglingParser<Alloc, Derived>::parseFloatingLiteral() {...@@ -5141,7 +5156,7 @@ Node *AbstractManglingParser<Alloc, Derived>::parseFloatingLiteral() {
5141 const size_t N = FloatData<Float>::mangled_size;5156 const size_t N = FloatData<Float>::mangled_size;
5142 if (numLeft() <= N)5157 if (numLeft() <= N)
5143 return nullptr;5158 return nullptr;
5144 StringView Data(First, First + N);5159 std::string_view Data(First, N);
5145 for (char C : Data)5160 for (char C : Data)
5146 if (!std::isxdigit(C))5161 if (!std::isxdigit(C))
5147 return nullptr;5162 return nullptr;
...@@ -5461,7 +5476,8 @@ Node *AbstractManglingParser<Derived, Alloc>::parse() {...@@ -5461,7 +5476,8 @@ Node *AbstractManglingParser<Derived, Alloc>::parse() {
5461 if (Encoding == nullptr)5476 if (Encoding == nullptr)
5462 return nullptr;5477 return nullptr;
5463 if (look() == '.') {5478 if (look() == '.') {
5464 Encoding = make<DotSuffix>(Encoding, StringView(First, Last));5479 Encoding =
5480 make<DotSuffix>(Encoding, std::string_view(First, Last - First));
5465 First = Last;5481 First = Last;
5466 }5482 }
5467 if (numLeft() != 0)5483 if (numLeft() != 0)
...@@ -5497,4 +5513,8 @@ struct ManglingParser : AbstractManglingParser<ManglingParser<Alloc>, Alloc> {...@@ -5497,4 +5513,8 @@ struct ManglingParser : AbstractManglingParser<ManglingParser<Alloc>, Alloc> {
54975513
5498DEMANGLE_NAMESPACE_END5514DEMANGLE_NAMESPACE_END
54995515
5516#ifdef _LIBCXXABI_COMPILER_CLANG
5517#pragma clang diagnostic pop
5518#endif
5519
5500#endif // DEMANGLE_ITANIUMDEMANGLE_H5520#endif // DEMANGLE_ITANIUMDEMANGLE_H
lib/libcxxabi/src/demangle/StringView.h deleted-122
...@@ -1,122 +0,0 @@
1//===--- StringView.h -------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// FIXME: Use std::string_view instead when we support C++17.
10// There are two copies of this file in the source tree. The one under
11// libcxxabi is the original and the one under llvm is the copy. Use
12// cp-to-llvm.sh to update the copy. See README.txt for more details.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef DEMANGLE_STRINGVIEW_H
17#define DEMANGLE_STRINGVIEW_H
18
19#include "DemangleConfig.h"
20#include <cassert>
21#include <cstring>
22
23DEMANGLE_NAMESPACE_BEGIN
24
25class StringView {
26 const char *First;
27 const char *Last;
28
29public:
30 static const size_t npos = ~size_t(0);
31
32 template <size_t N>
33 StringView(const char (&Str)[N]) : First(Str), Last(Str + N - 1) {}
34 StringView(const char *First_, const char *Last_)
35 : First(First_), Last(Last_) {}
36 StringView(const char *First_, size_t Len)
37 : First(First_), Last(First_ + Len) {}
38 StringView(const char *Str) : First(Str), Last(Str + std::strlen(Str)) {}
39 StringView() : First(nullptr), Last(nullptr) {}
40
41 StringView substr(size_t Pos, size_t Len = npos) const {
42 assert(Pos <= size());
43 if (Len > size() - Pos)
44 Len = size() - Pos;
45 return StringView(begin() + Pos, Len);
46 }
47
48 size_t find(char C, size_t From = 0) const {
49 // Avoid calling memchr with nullptr.
50 if (From < size()) {
51 // Just forward to memchr, which is faster than a hand-rolled loop.
52 if (const void *P = ::memchr(First + From, C, size() - From))
53 return size_t(static_cast<const char *>(P) - First);
54 }
55 return npos;
56 }
57
58 StringView dropFront(size_t N = 1) const {
59 if (N >= size())
60 N = size();
61 return StringView(First + N, Last);
62 }
63
64 StringView dropBack(size_t N = 1) const {
65 if (N >= size())
66 N = size();
67 return StringView(First, Last - N);
68 }
69
70 char front() const {
71 assert(!empty());
72 return *begin();
73 }
74
75 char back() const {
76 assert(!empty());
77 return *(end() - 1);
78 }
79
80 char popFront() {
81 assert(!empty());
82 return *First++;
83 }
84
85 bool consumeFront(char C) {
86 if (!startsWith(C))
87 return false;
88 *this = dropFront(1);
89 return true;
90 }
91
92 bool consumeFront(StringView S) {
93 if (!startsWith(S))
94 return false;
95 *this = dropFront(S.size());
96 return true;
97 }
98
99 bool startsWith(char C) const { return !empty() && *begin() == C; }
100
101 bool startsWith(StringView Str) const {
102 if (Str.size() > size())
103 return false;
104 return std::strncmp(Str.begin(), begin(), Str.size()) == 0;
105 }
106
107 const char &operator[](size_t Idx) const { return *(begin() + Idx); }
108
109 const char *begin() const { return First; }
110 const char *end() const { return Last; }
111 size_t size() const { return static_cast<size_t>(Last - First); }
112 bool empty() const { return First == Last; }
113};
114
115inline bool operator==(const StringView &LHS, const StringView &RHS) {
116 return LHS.size() == RHS.size() &&
117 std::strncmp(LHS.begin(), RHS.begin(), LHS.size()) == 0;
118}
119
120DEMANGLE_NAMESPACE_END
121
122#endif
lib/libcxxabi/src/demangle/StringViewExtras.h created+38
...@@ -0,0 +1,38 @@
1//===--- StringViewExtras.h -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// There are two copies of this file in the source tree. The one under
10// libcxxabi is the original and the one under llvm is the copy. Use
11// cp-to-llvm.sh to update the copy. See README.txt for more details.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef DEMANGLE_STRINGVIEW_H
16#define DEMANGLE_STRINGVIEW_H
17
18#include "DemangleConfig.h"
19
20#include <string_view>
21
22DEMANGLE_NAMESPACE_BEGIN
23
24inline bool starts_with(std::string_view self, char C) noexcept {
25 return !self.empty() && *self.begin() == C;
26}
27
28inline bool starts_with(std::string_view haystack,
29 std::string_view needle) noexcept {
30 if (needle.size() > haystack.size())
31 return false;
32 haystack.remove_suffix(haystack.size() - needle.size());
33 return haystack == needle;
34}
35
36DEMANGLE_NAMESPACE_END
37
38#endif
lib/libcxxabi/src/demangle/Utility.h+14-8
...@@ -16,13 +16,16 @@...@@ -16,13 +16,16 @@
16#ifndef DEMANGLE_UTILITY_H16#ifndef DEMANGLE_UTILITY_H
17#define DEMANGLE_UTILITY_H17#define DEMANGLE_UTILITY_H
1818
19#include "StringView.h"19#include "DemangleConfig.h"
20
20#include <array>21#include <array>
22#include <cassert>
21#include <cstdint>23#include <cstdint>
22#include <cstdlib>24#include <cstdlib>
23#include <cstring>25#include <cstring>
24#include <exception>26#include <exception>
25#include <limits>27#include <limits>
28#include <string_view>
2629
27DEMANGLE_NAMESPACE_BEGIN30DEMANGLE_NAMESPACE_BEGIN
2831
...@@ -64,7 +67,8 @@ class OutputBuffer {...@@ -64,7 +67,8 @@ class OutputBuffer {
64 if (isNeg)67 if (isNeg)
65 *--TempPtr = '-';68 *--TempPtr = '-';
6669
67 return operator+=(StringView(TempPtr, Temp.data() + Temp.size()));70 return operator+=(
71 std::string_view(TempPtr, Temp.data() + Temp.size() - TempPtr));
68 }72 }
6973
70public:74public:
...@@ -77,7 +81,9 @@ public:...@@ -77,7 +81,9 @@ public:
77 OutputBuffer(const OutputBuffer &) = delete;81 OutputBuffer(const OutputBuffer &) = delete;
78 OutputBuffer &operator=(const OutputBuffer &) = delete;82 OutputBuffer &operator=(const OutputBuffer &) = delete;
7983
80 operator StringView() const { return StringView(Buffer, CurrentPosition); }84 operator std::string_view() const {
85 return std::string_view(Buffer, CurrentPosition);
86 }
8187
82 /// If a ParameterPackExpansion (or similar type) is encountered, the offset88 /// If a ParameterPackExpansion (or similar type) is encountered, the offset
83 /// into the pack that we're currently printing.89 /// into the pack that we're currently printing.
...@@ -99,10 +105,10 @@ public:...@@ -99,10 +105,10 @@ public:
99 *this += Close;105 *this += Close;
100 }106 }
101107
102 OutputBuffer &operator+=(StringView R) {108 OutputBuffer &operator+=(std::string_view R) {
103 if (size_t Size = R.size()) {109 if (size_t Size = R.size()) {
104 grow(Size);110 grow(Size);
105 std::memcpy(Buffer + CurrentPosition, R.begin(), Size);111 std::memcpy(Buffer + CurrentPosition, &*R.begin(), Size);
106 CurrentPosition += Size;112 CurrentPosition += Size;
107 }113 }
108 return *this;114 return *this;
...@@ -114,18 +120,18 @@ public:...@@ -114,18 +120,18 @@ public:
114 return *this;120 return *this;
115 }121 }
116122
117 OutputBuffer &prepend(StringView R) {123 OutputBuffer &prepend(std::string_view R) {
118 size_t Size = R.size();124 size_t Size = R.size();
119125
120 grow(Size);126 grow(Size);
121 std::memmove(Buffer + Size, Buffer, CurrentPosition);127 std::memmove(Buffer + Size, Buffer, CurrentPosition);
122 std::memcpy(Buffer, R.begin(), Size);128 std::memcpy(Buffer, &*R.begin(), Size);
123 CurrentPosition += Size;129 CurrentPosition += Size;
124130
125 return *this;131 return *this;
126 }132 }
127133
128 OutputBuffer &operator<<(StringView R) { return (*this += R); }134 OutputBuffer &operator<<(std::string_view R) { return (*this += R); }
129135
130 OutputBuffer &operator<<(char C) { return (*this += C); }136 OutputBuffer &operator<<(char C) { return (*this += C); }
131137
lib/libcxxabi/src/fallback_malloc.cpp+1-1
...@@ -15,10 +15,10 @@...@@ -15,10 +15,10 @@
15#endif15#endif
16#endif16#endif
1717
18#include <__memory/aligned_alloc.h>
18#include <assert.h>19#include <assert.h>
19#include <stdlib.h> // for malloc, calloc, free20#include <stdlib.h> // for malloc, calloc, free
20#include <string.h> // for memset21#include <string.h> // for memset
21#include <new> // for std::__libcpp_aligned_{alloc,free}
2222
23// A small, simple heap manager based (loosely) on23// A small, simple heap manager based (loosely) on
24// the startup heap manager from FreeBSD, optimized for space.24// the startup heap manager from FreeBSD, optimized for space.
lib/libcxxabi/src/private_typeinfo.cpp+124-62
...@@ -41,6 +41,7 @@...@@ -41,6 +41,7 @@
41// Defining _LIBCXXABI_FORGIVING_DYNAMIC_CAST does not help since can_catch() calls41// Defining _LIBCXXABI_FORGIVING_DYNAMIC_CAST does not help since can_catch() calls
42// is_equal() with use_strcmp=false so the string names are not compared.42// is_equal() with use_strcmp=false so the string names are not compared.
4343
44#include <cstdint>
44#include <string.h>45#include <string.h>
4546
46#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST47#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
...@@ -656,77 +657,138 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,...@@ -656,77 +657,138 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,
656 // Find out if we can use a giant short cut in the search657 // Find out if we can use a giant short cut in the search
657 if (is_equal(dynamic_type, dst_type, false))658 if (is_equal(dynamic_type, dst_type, false))
658 {659 {
659 // Using giant short cut. Add that information to info.660 // We're downcasting from src_type to the complete object's dynamic
660 info.number_of_dst_type = 1;661 // type. This is a really hot path that can be further optimized
661 // Do the search662 // with the `src2dst_offset` hint.
662 dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, false);663 // In such a case, dynamic_ptr already gives the casting result if the
663#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST664 // casting ever succeeds. All we have to do now is to check
664 // The following if should always be false because we should definitely665 // static_ptr points to a public base sub-object of dynamic_ptr.
665 // find (static_ptr, static_type), either on a public or private path666
666 if (info.path_dst_ptr_to_static_ptr == unknown)667 if (src2dst_offset >= 0)
667 {668 {
668 // We get here only if there is some kind of visibility problem669 // The static type is a unique public non-virtual base type of
669 // in client code.670 // dst_type at offset `src2dst_offset` from the origin of dst.
670 static_assert(std::atomic<size_t>::is_always_lock_free, "");671 // Note that there might be other non-public static_type bases. The
671 static std::atomic<size_t> error_count(0);672 // hint only guarantees that the public base is non-virtual and
672 size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed);673 // unique. So we have to check whether static_ptr points to that
673 if ((error_count_snapshot & (error_count_snapshot-1)) == 0)674 // unique public base sub-object.
674 syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's "675 if (offset_to_derived == -src2dst_offset)
675 "should have public visibility. At least one of them is hidden. %s"676 dst_ptr = dynamic_ptr;
676 ", %s.\n", static_type->name(), dynamic_type->name());677 }
677 // Redo the search comparing type_info's using strcmp678 else if (src2dst_offset == -2)
678 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};679 {
679 info.number_of_dst_type = 1;680 // static_type is not a public base of dst_type.
680 dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, true);681 dst_ptr = nullptr;
681 }682 }
683 else
684 {
685 // If src2dst_offset == -3, then:
686 // src_type is a multiple public base type but never a virtual
687 // base type. We can't conclude that static_ptr points to those
688 // public base sub-objects because there might be other non-
689 // public static_type bases. The search is inevitable.
690
691 // Fallback to the slow path to check that static_type is a public
692 // base type of dynamic_type.
693 // Using giant short cut. Add that information to info.
694 info.number_of_dst_type = 1;
695 // Do the search
696 dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, false);
697#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
698 // The following if should always be false because we should
699 // definitely find (static_ptr, static_type), either on a public
700 // or private path
701 if (info.path_dst_ptr_to_static_ptr == unknown)
702 {
703 // We get here only if there is some kind of visibility problem
704 // in client code.
705 static_assert(std::atomic<size_t>::is_always_lock_free, "");
706 static std::atomic<size_t> error_count(0);
707 size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed);
708 if ((error_count_snapshot & (error_count_snapshot-1)) == 0)
709 syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's "
710 "should have public visibility. At least one of them is hidden. %s"
711 ", %s.\n", static_type->name(), dynamic_type->name());
712 // Redo the search comparing type_info's using strcmp
713 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
714 info.number_of_dst_type = 1;
715 dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, true);
716 }
682#endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST717#endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST
683 // Query the search.718 // Query the search.
684 if (info.path_dst_ptr_to_static_ptr == public_path)719 if (info.path_dst_ptr_to_static_ptr == public_path)
685 dst_ptr = dynamic_ptr;720 dst_ptr = dynamic_ptr;
721 }
686 }722 }
687 else723 else
688 {724 {
689 // Not using giant short cut. Do the search725 if (src2dst_offset >= 0)
690 dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, false);
691 #ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
692 // The following if should always be false because we should definitely
693 // find (static_ptr, static_type), either on a public or private path
694 if (info.path_dst_ptr_to_static_ptr == unknown &&
695 info.path_dynamic_ptr_to_static_ptr == unknown)
696 {726 {
697 static_assert(std::atomic<size_t>::is_always_lock_free, "");727 // Optimize toward downcasting: dst_type has one unique public
698 static std::atomic<size_t> error_count(0);728 // static_type bases. Let's first try to do a downcast before
699 size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed);729 // falling back to the slow path. The downcast succeeds if there
700 if ((error_count_snapshot & (error_count_snapshot-1)) == 0)730 // is at least one path regardless of visibility from
701 syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's "731 // dynamic_type to dst_type.
702 "has hidden visibility or is defined in more than one translation "732 const void* dst_ptr_to_static = reinterpret_cast<const char*>(static_ptr) - src2dst_offset;
703 "unit. They should all have public visibility. "733 if (reinterpret_cast<std::intptr_t>(dst_ptr_to_static) >= reinterpret_cast<std::intptr_t>(dynamic_ptr))
704 "%s, %s, %s.\n", static_type->name(), dynamic_type->name(),734 {
705 dst_type->name());735 // Try to search a path from dynamic_type to dst_type.
706 // Redo the search comparing type_info's using strcmp736 __dynamic_cast_info dynamic_to_dst_info = {dynamic_type, dst_ptr_to_static, dst_type, src2dst_offset};
707 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};737 dynamic_to_dst_info.number_of_dst_type = 1;
708 dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, true);738 dynamic_type->search_above_dst(&dynamic_to_dst_info, dynamic_ptr, dynamic_ptr, public_path, false);
739 if (dynamic_to_dst_info.path_dst_ptr_to_static_ptr != unknown) {
740 // We have found at least one path from dynamic_ptr to
741 // dst_ptr. The downcast can succeed.
742 dst_ptr = dst_ptr_to_static;
743 }
744 }
709 }745 }
710#endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST746
711 // Query the search.747 if (!dst_ptr)
712 switch (info.number_to_static_ptr)
713 {748 {
714 case 0:749 // Not using giant short cut. Do the search
715 if (info.number_to_dst_ptr == 1 &&750 dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, false);
716 info.path_dynamic_ptr_to_static_ptr == public_path &&751#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
717 info.path_dynamic_ptr_to_dst_ptr == public_path)752 // The following if should always be false because we should
718 dst_ptr = info.dst_ptr_not_leading_to_static_ptr;753 // definitely find (static_ptr, static_type), either on a public
719 break;754 // or private path
720 case 1:755 if (info.path_dst_ptr_to_static_ptr == unknown &&
721 if (info.path_dst_ptr_to_static_ptr == public_path ||756 info.path_dynamic_ptr_to_static_ptr == unknown)
722 (757 {
723 info.number_to_dst_ptr == 0 &&758 static_assert(std::atomic<size_t>::is_always_lock_free, "");
724 info.path_dynamic_ptr_to_static_ptr == public_path &&759 static std::atomic<size_t> error_count(0);
725 info.path_dynamic_ptr_to_dst_ptr == public_path760 size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed);
726 )761 if ((error_count_snapshot & (error_count_snapshot-1)) == 0)
727 )762 syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's "
728 dst_ptr = info.dst_ptr_leading_to_static_ptr;763 "has hidden visibility or is defined in more than one translation "
729 break;764 "unit. They should all have public visibility. "
765 "%s, %s, %s.\n", static_type->name(), dynamic_type->name(),
766 dst_type->name());
767 // Redo the search comparing type_info's using strcmp
768 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
769 dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, true);
770 }
771#endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST
772 // Query the search.
773 switch (info.number_to_static_ptr)
774 {
775 case 0:
776 if (info.number_to_dst_ptr == 1 &&
777 info.path_dynamic_ptr_to_static_ptr == public_path &&
778 info.path_dynamic_ptr_to_dst_ptr == public_path)
779 dst_ptr = info.dst_ptr_not_leading_to_static_ptr;
780 break;
781 case 1:
782 if (info.path_dst_ptr_to_static_ptr == public_path ||
783 (
784 info.number_to_dst_ptr == 0 &&
785 info.path_dynamic_ptr_to_static_ptr == public_path &&
786 info.path_dynamic_ptr_to_dst_ptr == public_path
787 )
788 )
789 dst_ptr = info.dst_ptr_leading_to_static_ptr;
790 break;
791 }
730 }792 }
731 }793 }
732 return const_cast<void*>(dst_ptr);794 return const_cast<void*>(dst_ptr);
lib/libcxxabi/src/stdlib_new_delete.cpp+57-46
...@@ -4,30 +4,40 @@...@@ -4,30 +4,40 @@
4// See https://llvm.org/LICENSE.txt for license information.4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//6//
7//
8// This file implements the new and delete operators.
9//===----------------------------------------------------------------------===//7//===----------------------------------------------------------------------===//
108
11#include "__cxxabi_config.h"9#include "__cxxabi_config.h"
12#include <new>10#include <__memory/aligned_alloc.h>
13#include <cstdlib>11#include <cstdlib>
12#include <new>
13
14// Perform a few sanity checks on libc++ and libc++abi macros to ensure that
15// the code below can be an exact copy of the code in libcxx/src/new.cpp.
16#if !defined(_THROW_BAD_ALLOC)
17# error The _THROW_BAD_ALLOC macro should be already defined by libc++
18#endif
19
20#ifndef _LIBCPP_WEAK
21# error The _LIBCPP_WEAK macro should be already defined by libc++
22#endif
1423
15#if !defined(_THROW_BAD_ALLOC) || !defined(_LIBCXXABI_WEAK)24#if defined(_LIBCXXABI_NO_EXCEPTIONS) != defined(_LIBCPP_HAS_NO_EXCEPTIONS)
16#error The _THROW_BAD_ALLOC and _LIBCXXABI_WEAK libc++ macros must \25# error libc++ and libc++abi seem to disagree on whether exceptions are enabled
17 already be defined by libc++.
18#endif26#endif
27
28// ------------------ BEGIN COPY ------------------
19// Implement all new and delete operators as weak definitions29// Implement all new and delete operators as weak definitions
20// in this shared library, so that they can be overridden by programs30// in this shared library, so that they can be overridden by programs
21// that define non-weak copies of the functions.31// that define non-weak copies of the functions.
2232
23_LIBCXXABI_WEAK33_LIBCPP_WEAK
24void *34void *
25operator new(std::size_t size) _THROW_BAD_ALLOC35operator new(std::size_t size) _THROW_BAD_ALLOC
26{36{
27 if (size == 0)37 if (size == 0)
28 size = 1;38 size = 1;
29 void* p;39 void* p;
30 while ((p = ::malloc(size)) == nullptr)40 while ((p = std::malloc(size)) == nullptr)
31 {41 {
32 // If malloc fails and there is a new_handler,42 // If malloc fails and there is a new_handler,
33 // call it to try free up memory.43 // call it to try free up memory.
...@@ -35,7 +45,7 @@ operator new(std::size_t size) _THROW_BAD_ALLOC...@@ -35,7 +45,7 @@ operator new(std::size_t size) _THROW_BAD_ALLOC
35 if (nh)45 if (nh)
36 nh();46 nh();
37 else47 else
38#ifndef _LIBCXXABI_NO_EXCEPTIONS48#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
39 throw std::bad_alloc();49 throw std::bad_alloc();
40#else50#else
41 break;51 break;
...@@ -44,87 +54,87 @@ operator new(std::size_t size) _THROW_BAD_ALLOC...@@ -44,87 +54,87 @@ operator new(std::size_t size) _THROW_BAD_ALLOC
44 return p;54 return p;
45}55}
4656
47_LIBCXXABI_WEAK57_LIBCPP_WEAK
48void*58void*
49operator new(size_t size, const std::nothrow_t&) noexcept59operator new(size_t size, const std::nothrow_t&) noexcept
50{60{
51 void* p = nullptr;61 void* p = nullptr;
52#ifndef _LIBCXXABI_NO_EXCEPTIONS62#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
53 try63 try
54 {64 {
55#endif // _LIBCXXABI_NO_EXCEPTIONS65#endif // _LIBCPP_HAS_NO_EXCEPTIONS
56 p = ::operator new(size);66 p = ::operator new(size);
57#ifndef _LIBCXXABI_NO_EXCEPTIONS67#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
58 }68 }
59 catch (...)69 catch (...)
60 {70 {
61 }71 }
62#endif // _LIBCXXABI_NO_EXCEPTIONS72#endif // _LIBCPP_HAS_NO_EXCEPTIONS
63 return p;73 return p;
64}74}
6575
66_LIBCXXABI_WEAK76_LIBCPP_WEAK
67void*77void*
68operator new[](size_t size) _THROW_BAD_ALLOC78operator new[](size_t size) _THROW_BAD_ALLOC
69{79{
70 return ::operator new(size);80 return ::operator new(size);
71}81}
7282
73_LIBCXXABI_WEAK83_LIBCPP_WEAK
74void*84void*
75operator new[](size_t size, const std::nothrow_t&) noexcept85operator new[](size_t size, const std::nothrow_t&) noexcept
76{86{
77 void* p = nullptr;87 void* p = nullptr;
78#ifndef _LIBCXXABI_NO_EXCEPTIONS88#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
79 try89 try
80 {90 {
81#endif // _LIBCXXABI_NO_EXCEPTIONS91#endif // _LIBCPP_HAS_NO_EXCEPTIONS
82 p = ::operator new[](size);92 p = ::operator new[](size);
83#ifndef _LIBCXXABI_NO_EXCEPTIONS93#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
84 }94 }
85 catch (...)95 catch (...)
86 {96 {
87 }97 }
88#endif // _LIBCXXABI_NO_EXCEPTIONS98#endif // _LIBCPP_HAS_NO_EXCEPTIONS
89 return p;99 return p;
90}100}
91101
92_LIBCXXABI_WEAK102_LIBCPP_WEAK
93void103void
94operator delete(void* ptr) noexcept104operator delete(void* ptr) noexcept
95{105{
96 ::free(ptr);106 std::free(ptr);
97}107}
98108
99_LIBCXXABI_WEAK109_LIBCPP_WEAK
100void110void
101operator delete(void* ptr, const std::nothrow_t&) noexcept111operator delete(void* ptr, const std::nothrow_t&) noexcept
102{112{
103 ::operator delete(ptr);113 ::operator delete(ptr);
104}114}
105115
106_LIBCXXABI_WEAK116_LIBCPP_WEAK
107void117void
108operator delete(void* ptr, size_t) noexcept118operator delete(void* ptr, size_t) noexcept
109{119{
110 ::operator delete(ptr);120 ::operator delete(ptr);
111}121}
112122
113_LIBCXXABI_WEAK123_LIBCPP_WEAK
114void124void
115operator delete[] (void* ptr) noexcept125operator delete[] (void* ptr) noexcept
116{126{
117 ::operator delete(ptr);127 ::operator delete(ptr);
118}128}
119129
120_LIBCXXABI_WEAK130_LIBCPP_WEAK
121void131void
122operator delete[] (void* ptr, const std::nothrow_t&) noexcept132operator delete[] (void* ptr, const std::nothrow_t&) noexcept
123{133{
124 ::operator delete[](ptr);134 ::operator delete[](ptr);
125}135}
126136
127_LIBCXXABI_WEAK137_LIBCPP_WEAK
128void138void
129operator delete[] (void* ptr, size_t) noexcept139operator delete[] (void* ptr, size_t) noexcept
130{140{
...@@ -133,7 +143,7 @@ operator delete[] (void* ptr, size_t) noexcept...@@ -133,7 +143,7 @@ operator delete[] (void* ptr, size_t) noexcept
133143
134#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)144#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
135145
136_LIBCXXABI_WEAK146_LIBCPP_WEAK
137void *147void *
138operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC148operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
139{149{
...@@ -155,7 +165,7 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC...@@ -155,7 +165,7 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
155 if (nh)165 if (nh)
156 nh();166 nh();
157 else {167 else {
158#ifndef _LIBCXXABI_NO_EXCEPTIONS168#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
159 throw std::bad_alloc();169 throw std::bad_alloc();
160#else170#else
161 break;171 break;
...@@ -165,87 +175,87 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC...@@ -165,87 +175,87 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
165 return p;175 return p;
166}176}
167177
168_LIBCXXABI_WEAK178_LIBCPP_WEAK
169void*179void*
170operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept180operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept
171{181{
172 void* p = nullptr;182 void* p = nullptr;
173#ifndef _LIBCXXABI_NO_EXCEPTIONS183#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
174 try184 try
175 {185 {
176#endif // _LIBCXXABI_NO_EXCEPTIONS186#endif // _LIBCPP_HAS_NO_EXCEPTIONS
177 p = ::operator new(size, alignment);187 p = ::operator new(size, alignment);
178#ifndef _LIBCXXABI_NO_EXCEPTIONS188#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
179 }189 }
180 catch (...)190 catch (...)
181 {191 {
182 }192 }
183#endif // _LIBCXXABI_NO_EXCEPTIONS193#endif // _LIBCPP_HAS_NO_EXCEPTIONS
184 return p;194 return p;
185}195}
186196
187_LIBCXXABI_WEAK197_LIBCPP_WEAK
188void*198void*
189operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC199operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
190{200{
191 return ::operator new(size, alignment);201 return ::operator new(size, alignment);
192}202}
193203
194_LIBCXXABI_WEAK204_LIBCPP_WEAK
195void*205void*
196operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept206operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept
197{207{
198 void* p = nullptr;208 void* p = nullptr;
199#ifndef _LIBCXXABI_NO_EXCEPTIONS209#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
200 try210 try
201 {211 {
202#endif // _LIBCXXABI_NO_EXCEPTIONS212#endif // _LIBCPP_HAS_NO_EXCEPTIONS
203 p = ::operator new[](size, alignment);213 p = ::operator new[](size, alignment);
204#ifndef _LIBCXXABI_NO_EXCEPTIONS214#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
205 }215 }
206 catch (...)216 catch (...)
207 {217 {
208 }218 }
209#endif // _LIBCXXABI_NO_EXCEPTIONS219#endif // _LIBCPP_HAS_NO_EXCEPTIONS
210 return p;220 return p;
211}221}
212222
213_LIBCXXABI_WEAK223_LIBCPP_WEAK
214void224void
215operator delete(void* ptr, std::align_val_t) noexcept225operator delete(void* ptr, std::align_val_t) noexcept
216{226{
217 std::__libcpp_aligned_free(ptr);227 std::__libcpp_aligned_free(ptr);
218}228}
219229
220_LIBCXXABI_WEAK230_LIBCPP_WEAK
221void231void
222operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept232operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept
223{233{
224 ::operator delete(ptr, alignment);234 ::operator delete(ptr, alignment);
225}235}
226236
227_LIBCXXABI_WEAK237_LIBCPP_WEAK
228void238void
229operator delete(void* ptr, size_t, std::align_val_t alignment) noexcept239operator delete(void* ptr, size_t, std::align_val_t alignment) noexcept
230{240{
231 ::operator delete(ptr, alignment);241 ::operator delete(ptr, alignment);
232}242}
233243
234_LIBCXXABI_WEAK244_LIBCPP_WEAK
235void245void
236operator delete[] (void* ptr, std::align_val_t alignment) noexcept246operator delete[] (void* ptr, std::align_val_t alignment) noexcept
237{247{
238 ::operator delete(ptr, alignment);248 ::operator delete(ptr, alignment);
239}249}
240250
241_LIBCXXABI_WEAK251_LIBCPP_WEAK
242void252void
243operator delete[] (void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept253operator delete[] (void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept
244{254{
245 ::operator delete[](ptr, alignment);255 ::operator delete[](ptr, alignment);
246}256}
247257
248_LIBCXXABI_WEAK258_LIBCPP_WEAK
249void259void
250operator delete[] (void* ptr, size_t, std::align_val_t alignment) noexcept260operator delete[] (void* ptr, size_t, std::align_val_t alignment) noexcept
251{261{
...@@ -253,3 +263,4 @@ operator delete[] (void* ptr, size_t, std::align_val_t alignment) noexcept...@@ -253,3 +263,4 @@ operator delete[] (void* ptr, size_t, std::align_val_t alignment) noexcept
253}263}
254264
255#endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION265#endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
266// ------------------ END COPY ------------------