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 @@
3232#endif
3333
3434#if defined(_WIN32)
35 #if defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
35 #if defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCXXABI_BUILDING_LIBRARY))
3636 #define _LIBCXXABI_HIDDEN
3737 #define _LIBCXXABI_DATA_VIS
3838 #define _LIBCXXABI_FUNC_VIS
lib/libcxxabi/src/aix_state_tab_eh.inc+56-29
......@@ -14,10 +14,6 @@
1414#include <stdio.h>
1515#include <sys/debug.h>
1616
17#if !__has_cpp_attribute(clang::optnone)
18#error This file requires clang::optnone attribute support
19#endif
20
2117/*
2218 The legacy IBM xlC and xlclang++ compilers use the state table for EH
2319 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
563559 uintptr_t *currentSP = reinterpret_cast<uintptr_t*>(_Unwind_GetGR(context, 1));
564560 uintptr_t *callersSP = reinterpret_cast<uintptr_t*>(currentSP[0]);
565561 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));
567564 // Jump to the handler.
568565 _Unwind_SetIP(context, results.landingPad);
569566 return _URC_INSTALL_CONTEXT;
......@@ -641,38 +638,68 @@ _LIBCXXABI_FUNC_VIS void __xlc_throw_badexception() {
641638 __cxa_throw(newexception, const_cast<std::type_info*>(&typeid(std::bad_exception)), 0);
642639}
643640
644// force_a_stackframe
645// This function is called by __xlc_exception_handle() to ensure a stack frame
646// is created for __xlc_exception_handle().
647__attribute__((noinline, optnone))
648static void force_a_stackframe() {}
641// skip_non_cxx_eh_aware_frames
642// This function skips non-C++ EH aware stack frames by unwinding from the
643// stack frame pointed by 'Sp' and returns the first C++ EH aware stack frame
644// found. 'Pc' is an instruction address inside the function that owns the
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
650676// __xlc_exception_handle
651677// This function is for xlclang++. It returns the address of the exception
652678// object stored in the reserved field in the stack of the caller of the
653679// function that calls __xlc_exception_handle() (within the link area for the
654680// call to the latter). The address is stored by the personality routine for
655// xlclang++ compiled code. The implementation of __xlc_exception_handle()
656// assumes a stack frame is created for it. The following ensures this
657// assumption holds true: 1) a call to force_a_stackframe() is made inside
658// __xlc_exception_handle() to make it non-leaf; and 2) optimizations are
659// disabled for this function with attribute 'optnone'. Note: this function
660// may not work as expected if these are changed.
661__attribute__((optnone))
681// xlclang++ compiled code. If __xlc_exception_handle() is called by
682// non-C++ EH aware functions, their frames are skipped until a C++ EH aware
683// frame is found.
684// Note: make sure __xlc_excpetion_handle() is a non-leaf function. Currently
685// it calls skip_non_cxx_eh_aware_frames(), which in turn calls abort().
662686_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
667687 // Get the SP of this function, i.e., __xlc_exception_handle().
668 uintptr_t *lastStack;
669 asm("mr %0, 1" : "=r"(lastStack));
670 // Get the SP of the caller of __xlc_exception_handle().
671 uintptr_t *callerStack = reinterpret_cast<uintptr_t*>(lastStack[0]);
672 // Get the SP of the caller of the caller.
673 uintptr_t *callerStack2 = reinterpret_cast<uintptr_t*>(callerStack[0]);
674 uintptr_t exceptionObject = callerStack2[3];
675 _LIBCXXABI_TRACE_STATETAB("Handshake: exceptionObject=%p from stack=%p\n", reinterpret_cast<void*>(exceptionObject), reinterpret_cast<void*>(callerStack2));
688 uintptr_t* lastStack = reinterpret_cast<uintptr_t*>(__builtin_frame_address(0));
689 // Move one frame up to the frame of the caller of __xlc_exception_handle().
690 lastStack = reinterpret_cast<uintptr_t*>(lastStack[0]);
691 // Get the return address of this function, i.e., __xlc_exception_handle().
692 uint32_t* returnAddress = reinterpret_cast<uint32_t*>(__builtin_return_address(0));
693
694 // Skip non-C++ EH aware frames and get the first C++ EH aware frame.
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));
676703 return exceptionObject;
677704}
678705
lib/libcxxabi/src/cxa_aux_runtime.cpp+1
......@@ -10,6 +10,7 @@
1010//===----------------------------------------------------------------------===//
1111
1212#include "cxxabi.h"
13#include <exception>
1314#include <new>
1415#include <typeinfo>
1516
lib/libcxxabi/src/cxa_demangle.cpp+4-2
......@@ -10,6 +10,7 @@
1010// file does not yet support:
1111// - C++ modules TS
1212
13#include "demangle/DemangleConfig.h"
1314#include "demangle/ItaniumDemangle.h"
1415#include "__cxxabi_config.h"
1516#include <cassert>
......@@ -19,6 +20,7 @@
1920#include <cstring>
2021#include <functional>
2122#include <numeric>
23#include <string_view>
2224#include <utility>
2325
2426using namespace itanium_demangle;
......@@ -77,8 +79,8 @@ struct DumpVisitor {
7779 }
7880
7981 void printStr(const char *S) { fprintf(stderr, "%s", S); }
80 void print(StringView SV) {
81 fprintf(stderr, "\"%.*s\"", (int)SV.size(), SV.begin());
82 void print(std::string_view SV) {
83 fprintf(stderr, "\"%.*s\"", (int)SV.size(), &*SV.begin());
8284 }
8385 void print(const Node *N) {
8486 if (N)
lib/libcxxabi/src/cxa_guard_impl.h+3-3
......@@ -255,7 +255,7 @@ struct InitByteNoThreads {
255255 if (*init_byte_address == COMPLETE_BIT)
256256 return true;
257257 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?");
259259 *init_byte_address = PENDING_BIT;
260260 return false;
261261 }
......@@ -325,7 +325,7 @@ public:
325325 // Check for possible recursive initialization.
326326 if (has_thread_id_support && (*init_byte_address & PENDING_BIT)) {
327327 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?");
329329 }
330330
331331 // Wait until the pending bit is not set.
......@@ -460,7 +460,7 @@ public:
460460
461461 // Check for recursive initialization
462462 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?");
464464 }
465465
466466 if ((last_val & WAITING_BIT) == 0) {
lib/libcxxabi/src/demangle/DemangleConfig.h+8
......@@ -11,6 +11,14 @@
1111#ifndef LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H
1212#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
1422#include <ciso646>
1523
1624#ifdef _MSC_VER
lib/libcxxabi/src/demangle/ItaniumDemangle.h+154-134
......@@ -17,8 +17,9 @@
1717#define DEMANGLE_ITANIUMDEMANGLE_H
1818
1919#include "DemangleConfig.h"
20#include "StringView.h"
20#include "StringViewExtras.h"
2121#include "Utility.h"
22#include <__cxxabi_config.h>
2223#include <algorithm>
2324#include <cassert>
2425#include <cctype>
......@@ -27,8 +28,15 @@
2728#include <cstring>
2829#include <limits>
2930#include <new>
31#include <string_view>
32#include <type_traits>
3033#include <utility>
3134
35#ifdef _LIBCXXABI_COMPILER_CLANG
36#pragma clang diagnostic push
37#pragma clang diagnostic ignored "-Wunused-template"
38#endif
39
3240DEMANGLE_NAMESPACE_BEGIN
3341
3442template <class T, size_t N> class PODSmallVector {
......@@ -286,7 +294,7 @@ public:
286294 // implementation.
287295 virtual void printRight(OutputBuffer &) const {}
288296
289 virtual StringView getBaseName() const { return StringView(); }
297 virtual std::string_view getBaseName() const { return {}; }
290298
291299 // Silence compiler warnings, this dtor will never be called.
292300 virtual ~Node() = default;
......@@ -345,10 +353,10 @@ struct NodeArrayNode : Node {
345353
346354class DotSuffix final : public Node {
347355 const Node *Prefix;
348 const StringView Suffix;
356 const std::string_view Suffix;
349357
350358public:
351 DotSuffix(const Node *Prefix_, StringView Suffix_)
359 DotSuffix(const Node *Prefix_, std::string_view Suffix_)
352360 : Node(KDotSuffix), Prefix(Prefix_), Suffix(Suffix_) {}
353361
354362 template<typename Fn> void match(Fn F) const { F(Prefix, Suffix); }
......@@ -363,15 +371,15 @@ public:
363371
364372class VendorExtQualType final : public Node {
365373 const Node *Ty;
366 StringView Ext;
374 std::string_view Ext;
367375 const Node *TA;
368376
369377public:
370 VendorExtQualType(const Node *Ty_, StringView Ext_, const Node *TA_)
378 VendorExtQualType(const Node *Ty_, std::string_view Ext_, const Node *TA_)
371379 : Node(KVendorExtQualType), Ty(Ty_), Ext(Ext_), TA(TA_) {}
372380
373381 const Node *getTy() const { return Ty; }
374 StringView getExt() const { return Ext; }
382 std::string_view getExt() const { return Ext; }
375383 const Node *getTA() const { return TA; }
376384
377385 template <typename Fn> void match(Fn F) const { F(Ty, Ext, TA); }
......@@ -462,10 +470,10 @@ public:
462470
463471class PostfixQualifiedType final : public Node {
464472 const Node *Ty;
465 const StringView Postfix;
473 const std::string_view Postfix;
466474
467475public:
468 PostfixQualifiedType(const Node *Ty_, StringView Postfix_)
476 PostfixQualifiedType(const Node *Ty_, std::string_view Postfix_)
469477 : Node(KPostfixQualifiedType), Ty(Ty_), Postfix(Postfix_) {}
470478
471479 template<typename Fn> void match(Fn F) const { F(Ty, Postfix); }
......@@ -477,15 +485,15 @@ public:
477485};
478486
479487class NameType final : public Node {
480 const StringView Name;
488 const std::string_view Name;
481489
482490public:
483 NameType(StringView Name_) : Node(KNameType), Name(Name_) {}
491 NameType(std::string_view Name_) : Node(KNameType), Name(Name_) {}
484492
485493 template<typename Fn> void match(Fn F) const { F(Name); }
486494
487 StringView getName() const { return Name; }
488 StringView getBaseName() const override { return Name; }
495 std::string_view getName() const { return Name; }
496 std::string_view getBaseName() const override { return Name; }
489497
490498 void printLeft(OutputBuffer &OB) const override { OB += Name; }
491499};
......@@ -511,10 +519,10 @@ public:
511519};
512520
513521class ElaboratedTypeSpefType : public Node {
514 StringView Kind;
522 std::string_view Kind;
515523 Node *Child;
516524public:
517 ElaboratedTypeSpefType(StringView Kind_, Node *Child_)
525 ElaboratedTypeSpefType(std::string_view Kind_, Node *Child_)
518526 : Node(KElaboratedTypeSpefType), Kind(Kind_), Child(Child_) {}
519527
520528 template<typename Fn> void match(Fn F) const { F(Kind, Child); }
......@@ -528,15 +536,17 @@ public:
528536
529537struct AbiTagAttr : Node {
530538 Node *Base;
531 StringView Tag;
539 std::string_view Tag;
532540
533 AbiTagAttr(Node* Base_, StringView Tag_)
534 : Node(KAbiTagAttr, Base_->RHSComponentCache,
535 Base_->ArrayCache, Base_->FunctionCache),
541 AbiTagAttr(Node *Base_, std::string_view Tag_)
542 : Node(KAbiTagAttr, Base_->RHSComponentCache, Base_->ArrayCache,
543 Base_->FunctionCache),
536544 Base(Base_), Tag(Tag_) {}
537545
538546 template<typename Fn> void match(Fn F) const { F(Base, Tag); }
539547
548 std::string_view getBaseName() const override { return Base->getBaseName(); }
549
540550 void printLeft(OutputBuffer &OB) const override {
541551 Base->printLeft(OB);
542552 OB += "[abi:";
......@@ -562,12 +572,12 @@ public:
562572
563573class ObjCProtoName : public Node {
564574 const Node *Ty;
565 StringView Protocol;
575 std::string_view Protocol;
566576
567577 friend class PointerType;
568578
569579public:
570 ObjCProtoName(const Node *Ty_, StringView Protocol_)
580 ObjCProtoName(const Node *Ty_, std::string_view Protocol_)
571581 : Node(KObjCProtoName), Ty(Ty_), Protocol(Protocol_) {}
572582
573583 template<typename Fn> void match(Fn F) const { F(Ty, Protocol); }
......@@ -944,11 +954,11 @@ public:
944954};
945955
946956class SpecialName final : public Node {
947 const StringView Special;
957 const std::string_view Special;
948958 const Node *Child;
949959
950960public:
951 SpecialName(StringView Special_, const Node *Child_)
961 SpecialName(std::string_view Special_, const Node *Child_)
952962 : Node(KSpecialName), Special(Special_), Child(Child_) {}
953963
954964 template<typename Fn> void match(Fn F) const { F(Special, Child); }
......@@ -987,7 +997,7 @@ struct NestedName : Node {
987997
988998 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
9921002 void printLeft(OutputBuffer &OB) const override {
9931003 Qual->print(OB);
......@@ -1027,7 +1037,7 @@ struct ModuleEntity : Node {
10271037
10281038 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
10321042 void printLeft(OutputBuffer &OB) const override {
10331043 Name->print(OB);
......@@ -1063,7 +1073,7 @@ public:
10631073
10641074 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
10681078 void printLeft(OutputBuffer &OB) const override {
10691079 Qualifier->print(OB);
......@@ -1485,7 +1495,7 @@ struct NameWithTemplateArgs : Node {
14851495
14861496 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
14901500 void printLeft(OutputBuffer &OB) const override {
14911501 Name->print(OB);
......@@ -1502,7 +1512,7 @@ public:
15021512
15031513 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
15071517 void printLeft(OutputBuffer &OB) const override {
15081518 OB += "::";
......@@ -1538,20 +1548,20 @@ protected:
15381548 return unsigned(SSK) >= unsigned(SpecialSubKind::string);
15391549 }
15401550
1541 StringView getBaseName() const override {
1551 std::string_view getBaseName() const override {
15421552 switch (SSK) {
15431553 case SpecialSubKind::allocator:
1544 return StringView("allocator");
1554 return {"allocator"};
15451555 case SpecialSubKind::basic_string:
1546 return StringView("basic_string");
1556 return {"basic_string"};
15471557 case SpecialSubKind::string:
1548 return StringView("basic_string");
1558 return {"basic_string"};
15491559 case SpecialSubKind::istream:
1550 return StringView("basic_istream");
1560 return {"basic_istream"};
15511561 case SpecialSubKind::ostream:
1552 return StringView("basic_ostream");
1562 return {"basic_ostream"};
15531563 case SpecialSubKind::iostream:
1554 return StringView("basic_iostream");
1564 return {"basic_iostream"};
15551565 }
15561566 DEMANGLE_UNREACHABLE;
15571567 }
......@@ -1575,12 +1585,12 @@ public:
15751585
15761586 template<typename Fn> void match(Fn F) const { F(SSK); }
15771587
1578 StringView getBaseName() const override {
1579 auto SV = ExpandedSpecialSubstitution::getBaseName ();
1588 std::string_view getBaseName() const override {
1589 std::string_view SV = ExpandedSpecialSubstitution::getBaseName();
15801590 if (isInstantiation()) {
15811591 // The instantiations are typedefs that drop the "basic_" prefix.
1582 assert(SV.startsWith("basic_"));
1583 SV = SV.dropFront(sizeof("basic_") - 1);
1592 assert(starts_with(SV, "basic_"));
1593 SV.remove_prefix(sizeof("basic_") - 1);
15841594 }
15851595 return SV;
15861596 }
......@@ -1628,10 +1638,11 @@ public:
16281638};
16291639
16301640class UnnamedTypeName : public Node {
1631 const StringView Count;
1641 const std::string_view Count;
16321642
16331643public:
1634 UnnamedTypeName(StringView Count_) : Node(KUnnamedTypeName), Count(Count_) {}
1644 UnnamedTypeName(std::string_view Count_)
1645 : Node(KUnnamedTypeName), Count(Count_) {}
16351646
16361647 template<typename Fn> void match(Fn F) const { F(Count); }
16371648
......@@ -1645,11 +1656,11 @@ public:
16451656class ClosureTypeName : public Node {
16461657 NodeArray TemplateParams;
16471658 NodeArray Params;
1648 StringView Count;
1659 std::string_view Count;
16491660
16501661public:
16511662 ClosureTypeName(NodeArray TemplateParams_, NodeArray Params_,
1652 StringView Count_)
1663 std::string_view Count_)
16531664 : Node(KClosureTypeName), TemplateParams(TemplateParams_),
16541665 Params(Params_), Count(Count_) {}
16551666
......@@ -1696,12 +1707,12 @@ public:
16961707
16971708class BinaryExpr : public Node {
16981709 const Node *LHS;
1699 const StringView InfixOperator;
1710 const std::string_view InfixOperator;
17001711 const Node *RHS;
17011712
17021713public:
1703 BinaryExpr(const Node *LHS_, StringView InfixOperator_, const Node *RHS_,
1704 Prec Prec_)
1714 BinaryExpr(const Node *LHS_, std::string_view InfixOperator_,
1715 const Node *RHS_, Prec Prec_)
17051716 : Node(KBinaryExpr, Prec_), LHS(LHS_), InfixOperator(InfixOperator_),
17061717 RHS(RHS_) {}
17071718
......@@ -1750,10 +1761,10 @@ public:
17501761
17511762class PostfixExpr : public Node {
17521763 const Node *Child;
1753 const StringView Operator;
1764 const std::string_view Operator;
17541765
17551766public:
1756 PostfixExpr(const Node *Child_, StringView Operator_, Prec Prec_)
1767 PostfixExpr(const Node *Child_, std::string_view Operator_, Prec Prec_)
17571768 : Node(KPostfixExpr, Prec_), Child(Child_), Operator(Operator_) {}
17581769
17591770 template <typename Fn> void match(Fn F) const {
......@@ -1791,11 +1802,12 @@ public:
17911802
17921803class MemberExpr : public Node {
17931804 const Node *LHS;
1794 const StringView Kind;
1805 const std::string_view Kind;
17951806 const Node *RHS;
17961807
17971808public:
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_)
17991811 : Node(KMemberExpr, Prec_), LHS(LHS_), Kind(Kind_), RHS(RHS_) {}
18001812
18011813 template <typename Fn> void match(Fn F) const {
......@@ -1812,13 +1824,14 @@ public:
18121824class SubobjectExpr : public Node {
18131825 const Node *Type;
18141826 const Node *SubExpr;
1815 StringView Offset;
1827 std::string_view Offset;
18161828 NodeArray UnionSelectors;
18171829 bool OnePastTheEnd;
18181830
18191831public:
1820 SubobjectExpr(const Node *Type_, const Node *SubExpr_, StringView Offset_,
1821 NodeArray UnionSelectors_, bool OnePastTheEnd_)
1832 SubobjectExpr(const Node *Type_, const Node *SubExpr_,
1833 std::string_view Offset_, NodeArray UnionSelectors_,
1834 bool OnePastTheEnd_)
18221835 : Node(KSubobjectExpr), Type(Type_), SubExpr(SubExpr_), Offset(Offset_),
18231836 UnionSelectors(UnionSelectors_), OnePastTheEnd(OnePastTheEnd_) {}
18241837
......@@ -1835,7 +1848,7 @@ public:
18351848 OB += "0";
18361849 } else if (Offset[0] == 'n') {
18371850 OB += "-";
1838 OB += Offset.dropFront();
1851 OB += std::string_view(Offset.data() + 1, Offset.size() - 1);
18391852 } else {
18401853 OB += Offset;
18411854 }
......@@ -1844,12 +1857,12 @@ public:
18441857};
18451858
18461859class EnclosingExpr : public Node {
1847 const StringView Prefix;
1860 const std::string_view Prefix;
18481861 const Node *Infix;
1849 const StringView Postfix;
1862 const std::string_view Postfix;
18501863
18511864public:
1852 EnclosingExpr(StringView Prefix_, const Node *Infix_,
1865 EnclosingExpr(std::string_view Prefix_, const Node *Infix_,
18531866 Prec Prec_ = Prec::Primary)
18541867 : Node(KEnclosingExpr, Prec_), Prefix(Prefix_), Infix(Infix_) {}
18551868
......@@ -1868,12 +1881,13 @@ public:
18681881
18691882class CastExpr : public Node {
18701883 // cast_kind<to>(from)
1871 const StringView CastKind;
1884 const std::string_view CastKind;
18721885 const Node *To;
18731886 const Node *From;
18741887
18751888public:
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_)
18771891 : Node(KCastExpr, Prec_), CastKind(CastKind_), To(To_), From(From_) {}
18781892
18791893 template <typename Fn> void match(Fn F) const {
......@@ -1996,11 +2010,11 @@ public:
19962010};
19972011
19982012class PrefixExpr : public Node {
1999 StringView Prefix;
2013 std::string_view Prefix;
20002014 Node *Child;
20012015
20022016public:
2003 PrefixExpr(StringView Prefix_, Node *Child_, Prec Prec_)
2017 PrefixExpr(std::string_view Prefix_, Node *Child_, Prec Prec_)
20042018 : Node(KPrefixExpr, Prec_), Prefix(Prefix_), Child(Child_) {}
20052019
20062020 template <typename Fn> void match(Fn F) const {
......@@ -2014,10 +2028,11 @@ public:
20142028};
20152029
20162030class FunctionParam : public Node {
2017 StringView Number;
2031 std::string_view Number;
20182032
20192033public:
2020 FunctionParam(StringView Number_) : Node(KFunctionParam), Number(Number_) {}
2034 FunctionParam(std::string_view Number_)
2035 : Node(KFunctionParam), Number(Number_) {}
20212036
20222037 template<typename Fn> void match(Fn F) const { F(Number); }
20232038
......@@ -2052,11 +2067,11 @@ public:
20522067class PointerToMemberConversionExpr : public Node {
20532068 const Node *Type;
20542069 const Node *SubExpr;
2055 StringView Offset;
2070 std::string_view Offset;
20562071
20572072public:
20582073 PointerToMemberConversionExpr(const Node *Type_, const Node *SubExpr_,
2059 StringView Offset_, Prec Prec_)
2074 std::string_view Offset_, Prec Prec_)
20602075 : Node(KPointerToMemberConversionExpr, Prec_), Type(Type_),
20612076 SubExpr(SubExpr_), Offset(Offset_) {}
20622077
......@@ -2141,11 +2156,11 @@ public:
21412156
21422157class FoldExpr : public Node {
21432158 const Node *Pack, *Init;
2144 StringView OperatorName;
2159 std::string_view OperatorName;
21452160 bool IsLeftFold;
21462161
21472162public:
2148 FoldExpr(bool IsLeftFold_, StringView OperatorName_, const Node *Pack_,
2163 FoldExpr(bool IsLeftFold_, std::string_view OperatorName_, const Node *Pack_,
21492164 const Node *Init_)
21502165 : Node(KFoldExpr), Pack(Pack_), Init(Init_), OperatorName(OperatorName_),
21512166 IsLeftFold(IsLeftFold_) {}
......@@ -2209,7 +2224,7 @@ public:
22092224 template<typename Fn> void match(Fn F) const { F(Value); }
22102225
22112226 void printLeft(OutputBuffer &OB) const override {
2212 OB += Value ? StringView("true") : StringView("false");
2227 OB += Value ? std::string_view("true") : std::string_view("false");
22132228 }
22142229};
22152230
......@@ -2247,10 +2262,10 @@ public:
22472262class EnumLiteral : public Node {
22482263 // ty(integer)
22492264 const Node *Ty;
2250 StringView Integer;
2265 std::string_view Integer;
22512266
22522267public:
2253 EnumLiteral(const Node *Ty_, StringView Integer_)
2268 EnumLiteral(const Node *Ty_, std::string_view Integer_)
22542269 : Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {}
22552270
22562271 template<typename Fn> void match(Fn F) const { F(Ty, Integer); }
......@@ -2261,18 +2276,18 @@ public:
22612276 OB.printClose();
22622277
22632278 if (Integer[0] == 'n')
2264 OB << "-" << Integer.dropFront(1);
2279 OB << '-' << std::string_view(Integer.data() + 1, Integer.size() - 1);
22652280 else
22662281 OB << Integer;
22672282 }
22682283};
22692284
22702285class IntegerLiteral : public Node {
2271 StringView Type;
2272 StringView Value;
2286 std::string_view Type;
2287 std::string_view Value;
22732288
22742289public:
2275 IntegerLiteral(StringView Type_, StringView Value_)
2290 IntegerLiteral(std::string_view Type_, std::string_view Value_)
22762291 : Node(KIntegerLiteral), Type(Type_), Value(Value_) {}
22772292
22782293 template<typename Fn> void match(Fn F) const { F(Type, Value); }
......@@ -2284,10 +2299,9 @@ public:
22842299 OB.printClose();
22852300 }
22862301
2287 if (Value[0] == 'n') {
2288 OB += '-';
2289 OB += Value.dropFront(1);
2290 } else
2302 if (Value[0] == 'n')
2303 OB << '-' << std::string_view(Value.data() + 1, Value.size() - 1);
2304 else
22912305 OB += Value;
22922306
22932307 if (Type.size() <= 3)
......@@ -2310,29 +2324,26 @@ constexpr Node::Kind getFloatLiteralKind(long double *) {
23102324}
23112325
23122326template <class Float> class FloatLiteralImpl : public Node {
2313 const StringView Contents;
2327 const std::string_view Contents;
23142328
23152329 static constexpr Kind KindForClass =
23162330 float_literal_impl::getFloatLiteralKind((Float *)nullptr);
23172331
23182332public:
2319 FloatLiteralImpl(StringView Contents_)
2333 FloatLiteralImpl(std::string_view Contents_)
23202334 : Node(KindForClass), Contents(Contents_) {}
23212335
23222336 template<typename Fn> void match(Fn F) const { F(Contents); }
23232337
23242338 void printLeft(OutputBuffer &OB) const override {
2325 const char *first = Contents.begin();
2326 const char *last = Contents.end() + 1;
2327
23282339 const size_t N = FloatData<Float>::mangled_size;
2329 if (static_cast<std::size_t>(last - first) > N) {
2330 last = first + N;
2340 if (Contents.size() >= N) {
23312341 union {
23322342 Float value;
23332343 char buf[sizeof(Float)];
23342344 };
2335 const char *t = first;
2345 const char *t = Contents.data();
2346 const char *last = t + N;
23362347 char *e = buf;
23372348 for (; t != last; ++t, ++e) {
23382349 unsigned d1 = isdigit(*t) ? static_cast<unsigned>(*t - '0')
......@@ -2347,7 +2358,7 @@ public:
23472358#endif
23482359 char num[FloatData<Float>::max_demangled_size] = {0};
23492360 int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
2350 OB += StringView(num, num + n);
2361 OB += std::string_view(num, n);
23512362 }
23522363 }
23532364};
......@@ -2474,8 +2485,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
24742485 return res;
24752486 }
24762487
2477 bool consumeIf(StringView S) {
2478 if (StringView(First, Last).startsWith(S)) {
2488 bool consumeIf(std::string_view S) {
2489 if (starts_with(std::string_view(First, Last - First), S)) {
24792490 First += S.size();
24802491 return true;
24812492 }
......@@ -2500,10 +2511,10 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
25002511
25012512 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);
25042515 Qualifiers parseCVQualifiers();
25052516 bool parsePositiveInteger(size_t *Out);
2506 StringView parseBareSourceName();
2517 std::string_view parseBareSourceName();
25072518
25082519 bool parseSeqId(size_t *Out);
25092520 Node *parseSubstitution();
......@@ -2514,9 +2525,9 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
25142525
25152526 /// Parse the <expr> production.
25162527 Node *parseExpr();
2517 Node *parsePrefixExpr(StringView Kind, Node::Prec Prec);
2518 Node *parseBinaryExpr(StringView Kind, Node::Prec Prec);
2519 Node *parseIntegerLiteral(StringView Lit);
2528 Node *parsePrefixExpr(std::string_view Kind, Node::Prec Prec);
2529 Node *parseBinaryExpr(std::string_view Kind, Node::Prec Prec);
2530 Node *parseIntegerLiteral(std::string_view Lit);
25202531 Node *parseExprPrimary();
25212532 template <class Float> Node *parseFloatingLiteral();
25222533 Node *parseFunctionParam();
......@@ -2624,17 +2635,18 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
26242635 bool operator!=(const char *Peek) const { return !this->operator==(Peek); }
26252636
26262637 public:
2627 StringView getSymbol() const {
2628 StringView Res = Name;
2638 std::string_view getSymbol() const {
2639 std::string_view Res = Name;
26292640 if (Kind < Unnameable) {
2630 assert(Res.startsWith("operator") &&
2641 assert(starts_with(Res, "operator") &&
26312642 "operator name does not start with 'operator'");
2632 Res = Res.dropFront(sizeof("operator") - 1);
2633 Res.consumeFront(' ');
2643 Res.remove_prefix(sizeof("operator") - 1);
2644 if (starts_with(Res, ' '))
2645 Res.remove_prefix(1);
26342646 }
26352647 return Res;
26362648 }
2637 StringView getName() const { return Name; }
2649 std::string_view getName() const { return Name; }
26382650 OIKind getKind() const { return Kind; }
26392651 bool getFlag() const { return Flag; }
26402652 Node::Prec getPrecedence() const { return Prec; }
......@@ -2854,7 +2866,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {
28542866 TemplateParams.clear();
28552867
28562868 if (consumeIf("Ut")) {
2857 StringView Count = parseNumber();
2869 std::string_view Count = parseNumber();
28582870 if (!consumeIf('_'))
28592871 return nullptr;
28602872 return make<UnnamedTypeName>(Count);
......@@ -2866,7 +2878,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {
28662878
28672879 size_t ParamsBegin = Names.size();
28682880 while (look() == 'T' &&
2869 StringView("yptn").find(look(1)) != StringView::npos) {
2881 std::string_view("yptn").find(look(1)) != std::string_view::npos) {
28702882 Node *T = parseTemplateParamDecl();
28712883 if (!T)
28722884 return nullptr;
......@@ -2909,7 +2921,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {
29092921 }
29102922 NodeArray Params = popTrailingNodeArray(ParamsBegin);
29112923
2912 StringView Count = parseNumber();
2924 std::string_view Count = parseNumber();
29132925 if (!consumeIf('_'))
29142926 return nullptr;
29152927 return make<ClosureTypeName>(TempParams, Params, Count);
......@@ -2931,9 +2943,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSourceName(NameState *) {
29312943 return nullptr;
29322944 if (numLeft() < Length || Length == 0)
29332945 return nullptr;
2934 StringView Name(First, First + Length);
2946 std::string_view Name(First, Length);
29352947 First += Length;
2936 if (Name.startsWith("_GLOBAL__N"))
2948 if (starts_with(Name, "_GLOBAL__N"))
29372949 return make<NameType>("(anonymous namespace)");
29382950 return make<NameType>(Name);
29392951}
......@@ -3447,7 +3459,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseUnresolvedName(bool Global) {
34473459template <typename Derived, typename Alloc>
34483460Node *AbstractManglingParser<Derived, Alloc>::parseAbiTags(Node *N) {
34493461 while (consumeIf('B')) {
3450 StringView SN = parseBareSourceName();
3462 std::string_view SN = parseBareSourceName();
34513463 if (SN.empty())
34523464 return nullptr;
34533465 N = make<AbiTagAttr>(N, SN);
......@@ -3459,16 +3471,16 @@ Node *AbstractManglingParser<Derived, Alloc>::parseAbiTags(Node *N) {
34593471
34603472// <number> ::= [n] <non-negative decimal integer>
34613473template <typename Alloc, typename Derived>
3462StringView
3474std::string_view
34633475AbstractManglingParser<Alloc, Derived>::parseNumber(bool AllowNegative) {
34643476 const char *Tmp = First;
34653477 if (AllowNegative)
34663478 consumeIf('n');
34673479 if (numLeft() == 0 || !std::isdigit(*First))
3468 return StringView();
3480 return std::string_view();
34693481 while (numLeft() != 0 && std::isdigit(*First))
34703482 ++First;
3471 return StringView(Tmp, First);
3483 return std::string_view(Tmp, First - Tmp);
34723484}
34733485
34743486// <positive length number> ::= [0-9]*
......@@ -3485,11 +3497,11 @@ bool AbstractManglingParser<Alloc, Derived>::parsePositiveInteger(size_t *Out) {
34853497}
34863498
34873499template <typename Alloc, typename Derived>
3488StringView AbstractManglingParser<Alloc, Derived>::parseBareSourceName() {
3500std::string_view AbstractManglingParser<Alloc, Derived>::parseBareSourceName() {
34893501 size_t Int = 0;
34903502 if (parsePositiveInteger(&Int) || numLeft() < Int)
3491 return StringView();
3492 StringView R(First, First + Int);
3503 return {};
3504 std::string_view R(First, Int);
34933505 First += Int;
34943506 return R;
34953507}
......@@ -3673,7 +3685,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parsePointerToMemberType() {
36733685// ::= Te <name> # dependent elaborated type specifier using 'enum'
36743686template <typename Derived, typename Alloc>
36753687Node *AbstractManglingParser<Derived, Alloc>::parseClassEnumType() {
3676 StringView ElabSpef;
3688 std::string_view ElabSpef;
36773689 if (consumeIf("Ts"))
36783690 ElabSpef = "struct";
36793691 else if (consumeIf("Tu"))
......@@ -3697,17 +3709,18 @@ Node *AbstractManglingParser<Derived, Alloc>::parseClassEnumType() {
36973709template <typename Derived, typename Alloc>
36983710Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {
36993711 if (consumeIf('U')) {
3700 StringView Qual = parseBareSourceName();
3712 std::string_view Qual = parseBareSourceName();
37013713 if (Qual.empty())
37023714 return nullptr;
37033715
37043716 // extension ::= U <objc-name> <objc-type> # objc-type<identifier>
3705 if (Qual.startsWith("objcproto")) {
3706 StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto"));
3707 StringView Proto;
3717 if (starts_with(Qual, "objcproto")) {
3718 constexpr size_t Len = sizeof("objcproto") - 1;
3719 std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len);
3720 std::string_view Proto;
37083721 {
3709 ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.begin()),
3710 SaveLast(Last, ProtoSourceName.end());
3722 ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.data()),
3723 SaveLast(Last, &*ProtoSourceName.rbegin() + 1);
37113724 Proto = parseBareSourceName();
37123725 }
37133726 if (Proto.empty())
......@@ -3875,7 +3888,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
38753888 // <builtin-type> ::= u <source-name> # vendor extended type
38763889 case 'u': {
38773890 ++First;
3878 StringView Res = parseBareSourceName();
3891 std::string_view Res = parseBareSourceName();
38793892 if (Res.empty())
38803893 return nullptr;
38813894 // Typically, <builtin-type>s are not considered substitution candidates,
......@@ -4123,8 +4136,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
41234136}
41244137
41254138template <typename Derived, typename Alloc>
4126Node *AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(StringView Kind,
4127 Node::Prec Prec) {
4139Node *
4140AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(std::string_view Kind,
4141 Node::Prec Prec) {
41284142 Node *E = getDerived().parseExpr();
41294143 if (E == nullptr)
41304144 return nullptr;
......@@ -4132,8 +4146,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(StringView Kind,
41324146}
41334147
41344148template <typename Derived, typename Alloc>
4135Node *AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(StringView Kind,
4136 Node::Prec Prec) {
4149Node *
4150AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(std::string_view Kind,
4151 Node::Prec Prec) {
41374152 Node *LHS = getDerived().parseExpr();
41384153 if (LHS == nullptr)
41394154 return nullptr;
......@@ -4144,9 +4159,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(StringView Kind,
41444159}
41454160
41464161template <typename Derived, typename Alloc>
4147Node *
4148AbstractManglingParser<Derived, Alloc>::parseIntegerLiteral(StringView Lit) {
4149 StringView Tmp = parseNumber(true);
4162Node *AbstractManglingParser<Derived, Alloc>::parseIntegerLiteral(
4163 std::string_view Lit) {
4164 std::string_view Tmp = parseNumber(true);
41504165 if (!Tmp.empty() && consumeIf('E'))
41514166 return make<IntegerLiteral>(Lit, Tmp);
41524167 return nullptr;
......@@ -4176,7 +4191,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() {
41764191 return make<NameType>("this");
41774192 if (consumeIf("fp")) {
41784193 parseCVQualifiers();
4179 StringView Num = parseNumber();
4194 std::string_view Num = parseNumber();
41804195 if (!consumeIf('_'))
41814196 return nullptr;
41824197 return make<FunctionParam>(Num);
......@@ -4187,7 +4202,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() {
41874202 if (!consumeIf('p'))
41884203 return nullptr;
41894204 parseCVQualifiers();
4190 StringView Num = parseNumber();
4205 std::string_view Num = parseNumber();
41914206 if (!consumeIf('_'))
41924207 return nullptr;
41934208 return make<FunctionParam>(Num);
......@@ -4341,7 +4356,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {
43414356 Node *T = getDerived().parseType();
43424357 if (T == nullptr)
43434358 return nullptr;
4344 StringView N = parseNumber(/*AllowNegative=*/true);
4359 std::string_view N = parseNumber(/*AllowNegative=*/true);
43454360 if (N.empty())
43464361 return nullptr;
43474362 if (!consumeIf('E'))
......@@ -4464,7 +4479,7 @@ AbstractManglingParser<Derived, Alloc>::parsePointerToMemberConversionExpr(
44644479 Node *Expr = getDerived().parseExpr();
44654480 if (!Expr)
44664481 return nullptr;
4467 StringView Offset = getDerived().parseNumber(true);
4482 std::string_view Offset = getDerived().parseNumber(true);
44684483 if (!consumeIf('E'))
44694484 return nullptr;
44704485 return make<PointerToMemberConversionExpr>(Ty, Expr, Offset, Prec);
......@@ -4482,7 +4497,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSubobjectExpr() {
44824497 Node *Expr = getDerived().parseExpr();
44834498 if (!Expr)
44844499 return nullptr;
4485 StringView Offset = getDerived().parseNumber(true);
4500 std::string_view Offset = getDerived().parseNumber(true);
44864501 size_t SelectorsBegin = Names.size();
44874502 while (consumeIf('_')) {
44884503 Node *Selector = make<NameType>(parseNumber());
......@@ -5141,7 +5156,7 @@ Node *AbstractManglingParser<Alloc, Derived>::parseFloatingLiteral() {
51415156 const size_t N = FloatData<Float>::mangled_size;
51425157 if (numLeft() <= N)
51435158 return nullptr;
5144 StringView Data(First, First + N);
5159 std::string_view Data(First, N);
51455160 for (char C : Data)
51465161 if (!std::isxdigit(C))
51475162 return nullptr;
......@@ -5461,7 +5476,8 @@ Node *AbstractManglingParser<Derived, Alloc>::parse() {
54615476 if (Encoding == nullptr)
54625477 return nullptr;
54635478 if (look() == '.') {
5464 Encoding = make<DotSuffix>(Encoding, StringView(First, Last));
5479 Encoding =
5480 make<DotSuffix>(Encoding, std::string_view(First, Last - First));
54655481 First = Last;
54665482 }
54675483 if (numLeft() != 0)
......@@ -5497,4 +5513,8 @@ struct ManglingParser : AbstractManglingParser<ManglingParser<Alloc>, Alloc> {
54975513
54985514DEMANGLE_NAMESPACE_END
54995515
5516#ifdef _LIBCXXABI_COMPILER_CLANG
5517#pragma clang diagnostic pop
5518#endif
5519
55005520#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 @@
1616#ifndef DEMANGLE_UTILITY_H
1717#define DEMANGLE_UTILITY_H
1818
19#include "StringView.h"
19#include "DemangleConfig.h"
20
2021#include <array>
22#include <cassert>
2123#include <cstdint>
2224#include <cstdlib>
2325#include <cstring>
2426#include <exception>
2527#include <limits>
28#include <string_view>
2629
2730DEMANGLE_NAMESPACE_BEGIN
2831
......@@ -64,7 +67,8 @@ class OutputBuffer {
6467 if (isNeg)
6568 *--TempPtr = '-';
6669
67 return operator+=(StringView(TempPtr, Temp.data() + Temp.size()));
70 return operator+=(
71 std::string_view(TempPtr, Temp.data() + Temp.size() - TempPtr));
6872 }
6973
7074public:
......@@ -77,7 +81,9 @@ public:
7781 OutputBuffer(const OutputBuffer &) = delete;
7882 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
8288 /// If a ParameterPackExpansion (or similar type) is encountered, the offset
8389 /// into the pack that we're currently printing.
......@@ -99,10 +105,10 @@ public:
99105 *this += Close;
100106 }
101107
102 OutputBuffer &operator+=(StringView R) {
108 OutputBuffer &operator+=(std::string_view R) {
103109 if (size_t Size = R.size()) {
104110 grow(Size);
105 std::memcpy(Buffer + CurrentPosition, R.begin(), Size);
111 std::memcpy(Buffer + CurrentPosition, &*R.begin(), Size);
106112 CurrentPosition += Size;
107113 }
108114 return *this;
......@@ -114,18 +120,18 @@ public:
114120 return *this;
115121 }
116122
117 OutputBuffer &prepend(StringView R) {
123 OutputBuffer &prepend(std::string_view R) {
118124 size_t Size = R.size();
119125
120126 grow(Size);
121127 std::memmove(Buffer + Size, Buffer, CurrentPosition);
122 std::memcpy(Buffer, R.begin(), Size);
128 std::memcpy(Buffer, &*R.begin(), Size);
123129 CurrentPosition += Size;
124130
125131 return *this;
126132 }
127133
128 OutputBuffer &operator<<(StringView R) { return (*this += R); }
134 OutputBuffer &operator<<(std::string_view R) { return (*this += R); }
129135
130136 OutputBuffer &operator<<(char C) { return (*this += C); }
131137
lib/libcxxabi/src/fallback_malloc.cpp+1-1
......@@ -15,10 +15,10 @@
1515#endif
1616#endif
1717
18#include <__memory/aligned_alloc.h>
1819#include <assert.h>
1920#include <stdlib.h> // for malloc, calloc, free
2021#include <string.h> // for memset
21#include <new> // for std::__libcpp_aligned_{alloc,free}
2222
2323// A small, simple heap manager based (loosely) on
2424// the startup heap manager from FreeBSD, optimized for space.
lib/libcxxabi/src/private_typeinfo.cpp+124-62
......@@ -41,6 +41,7 @@
4141// Defining _LIBCXXABI_FORGIVING_DYNAMIC_CAST does not help since can_catch() calls
4242// is_equal() with use_strcmp=false so the string names are not compared.
4343
44#include <cstdint>
4445#include <string.h>
4546
4647#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
......@@ -656,77 +657,138 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,
656657 // Find out if we can use a giant short cut in the search
657658 if (is_equal(dynamic_type, dst_type, false))
658659 {
659 // Using giant short cut. Add that information to info.
660 info.number_of_dst_type = 1;
661 // Do the search
662 dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, false);
663#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
664 // The following if should always be false because we should definitely
665 // find (static_ptr, static_type), either on a public or private path
666 if (info.path_dst_ptr_to_static_ptr == unknown)
660 // We're downcasting from src_type to the complete object's dynamic
661 // type. This is a really hot path that can be further optimized
662 // with the `src2dst_offset` hint.
663 // In such a case, dynamic_ptr already gives the casting result if the
664 // casting ever succeeds. All we have to do now is to check
665 // static_ptr points to a public base sub-object of dynamic_ptr.
666
667 if (src2dst_offset >= 0)
667668 {
668 // We get here only if there is some kind of visibility problem
669 // in client code.
670 static_assert(std::atomic<size_t>::is_always_lock_free, "");
671 static std::atomic<size_t> error_count(0);
672 size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed);
673 if ((error_count_snapshot & (error_count_snapshot-1)) == 0)
674 syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's "
675 "should have public visibility. At least one of them is hidden. %s"
676 ", %s.\n", static_type->name(), dynamic_type->name());
677 // Redo the search comparing type_info's using strcmp
678 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
679 info.number_of_dst_type = 1;
680 dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, true);
669 // The static type is a unique public non-virtual base type of
670 // dst_type at offset `src2dst_offset` from the origin of dst.
671 // Note that there might be other non-public static_type bases. The
672 // hint only guarantees that the public base is non-virtual and
673 // unique. So we have to check whether static_ptr points to that
674 // unique public base sub-object.
675 if (offset_to_derived == -src2dst_offset)
676 dst_ptr = dynamic_ptr;
677 }
678 else if (src2dst_offset == -2)
679 {
680 // static_type is not a public base of dst_type.
681 dst_ptr = nullptr;
681682 }
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 }
682717#endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST
683 // Query the search.
684 if (info.path_dst_ptr_to_static_ptr == public_path)
685 dst_ptr = dynamic_ptr;
718 // Query the search.
719 if (info.path_dst_ptr_to_static_ptr == public_path)
720 dst_ptr = dynamic_ptr;
721 }
686722 }
687723 else
688724 {
689 // Not using giant short cut. Do the search
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)
725 if (src2dst_offset >= 0)
696726 {
697 static_assert(std::atomic<size_t>::is_always_lock_free, "");
698 static std::atomic<size_t> error_count(0);
699 size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed);
700 if ((error_count_snapshot & (error_count_snapshot-1)) == 0)
701 syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's "
702 "has hidden visibility or is defined in more than one translation "
703 "unit. They should all have public visibility. "
704 "%s, %s, %s.\n", static_type->name(), dynamic_type->name(),
705 dst_type->name());
706 // Redo the search comparing type_info's using strcmp
707 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
708 dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, true);
727 // Optimize toward downcasting: dst_type has one unique public
728 // static_type bases. Let's first try to do a downcast before
729 // falling back to the slow path. The downcast succeeds if there
730 // is at least one path regardless of visibility from
731 // dynamic_type to dst_type.
732 const void* dst_ptr_to_static = reinterpret_cast<const char*>(static_ptr) - src2dst_offset;
733 if (reinterpret_cast<std::intptr_t>(dst_ptr_to_static) >= reinterpret_cast<std::intptr_t>(dynamic_ptr))
734 {
735 // Try to search a path from dynamic_type to dst_type.
736 __dynamic_cast_info dynamic_to_dst_info = {dynamic_type, dst_ptr_to_static, dst_type, src2dst_offset};
737 dynamic_to_dst_info.number_of_dst_type = 1;
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 }
709745 }
710#endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST
711 // Query the search.
712 switch (info.number_to_static_ptr)
746
747 if (!dst_ptr)
713748 {
714 case 0:
715 if (info.number_to_dst_ptr == 1 &&
716 info.path_dynamic_ptr_to_static_ptr == public_path &&
717 info.path_dynamic_ptr_to_dst_ptr == public_path)
718 dst_ptr = info.dst_ptr_not_leading_to_static_ptr;
719 break;
720 case 1:
721 if (info.path_dst_ptr_to_static_ptr == public_path ||
722 (
723 info.number_to_dst_ptr == 0 &&
724 info.path_dynamic_ptr_to_static_ptr == public_path &&
725 info.path_dynamic_ptr_to_dst_ptr == public_path
726 )
727 )
728 dst_ptr = info.dst_ptr_leading_to_static_ptr;
729 break;
749 // Not using giant short cut. Do the search
750 dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, false);
751#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
752 // The following if should always be false because we should
753 // definitely find (static_ptr, static_type), either on a public
754 // or private path
755 if (info.path_dst_ptr_to_static_ptr == unknown &&
756 info.path_dynamic_ptr_to_static_ptr == unknown)
757 {
758 static_assert(std::atomic<size_t>::is_always_lock_free, "");
759 static std::atomic<size_t> error_count(0);
760 size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed);
761 if ((error_count_snapshot & (error_count_snapshot-1)) == 0)
762 syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's "
763 "has hidden visibility or is defined in more than one translation "
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 }
730792 }
731793 }
732794 return const_cast<void*>(dst_ptr);
lib/libcxxabi/src/stdlib_new_delete.cpp+57-46
......@@ -4,30 +4,40 @@
44// See https://llvm.org/LICENSE.txt for license information.
55// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66//
7//
8// This file implements the new and delete operators.
97//===----------------------------------------------------------------------===//
108
119#include "__cxxabi_config.h"
12#include <new>
10#include <__memory/aligned_alloc.h>
1311#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)
16#error The _THROW_BAD_ALLOC and _LIBCXXABI_WEAK libc++ macros must \
17 already be defined by libc++.
24#if defined(_LIBCXXABI_NO_EXCEPTIONS) != defined(_LIBCPP_HAS_NO_EXCEPTIONS)
25# error libc++ and libc++abi seem to disagree on whether exceptions are enabled
1826#endif
27
28// ------------------ BEGIN COPY ------------------
1929// Implement all new and delete operators as weak definitions
2030// in this shared library, so that they can be overridden by programs
2131// that define non-weak copies of the functions.
2232
23_LIBCXXABI_WEAK
33_LIBCPP_WEAK
2434void *
2535operator new(std::size_t size) _THROW_BAD_ALLOC
2636{
2737 if (size == 0)
2838 size = 1;
2939 void* p;
30 while ((p = ::malloc(size)) == nullptr)
40 while ((p = std::malloc(size)) == nullptr)
3141 {
3242 // If malloc fails and there is a new_handler,
3343 // call it to try free up memory.
......@@ -35,7 +45,7 @@ operator new(std::size_t size) _THROW_BAD_ALLOC
3545 if (nh)
3646 nh();
3747 else
38#ifndef _LIBCXXABI_NO_EXCEPTIONS
48#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
3949 throw std::bad_alloc();
4050#else
4151 break;
......@@ -44,87 +54,87 @@ operator new(std::size_t size) _THROW_BAD_ALLOC
4454 return p;
4555}
4656
47_LIBCXXABI_WEAK
57_LIBCPP_WEAK
4858void*
4959operator new(size_t size, const std::nothrow_t&) noexcept
5060{
5161 void* p = nullptr;
52#ifndef _LIBCXXABI_NO_EXCEPTIONS
62#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
5363 try
5464 {
55#endif // _LIBCXXABI_NO_EXCEPTIONS
65#endif // _LIBCPP_HAS_NO_EXCEPTIONS
5666 p = ::operator new(size);
57#ifndef _LIBCXXABI_NO_EXCEPTIONS
67#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
5868 }
5969 catch (...)
6070 {
6171 }
62#endif // _LIBCXXABI_NO_EXCEPTIONS
72#endif // _LIBCPP_HAS_NO_EXCEPTIONS
6373 return p;
6474}
6575
66_LIBCXXABI_WEAK
76_LIBCPP_WEAK
6777void*
6878operator new[](size_t size) _THROW_BAD_ALLOC
6979{
7080 return ::operator new(size);
7181}
7282
73_LIBCXXABI_WEAK
83_LIBCPP_WEAK
7484void*
7585operator new[](size_t size, const std::nothrow_t&) noexcept
7686{
7787 void* p = nullptr;
78#ifndef _LIBCXXABI_NO_EXCEPTIONS
88#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
7989 try
8090 {
81#endif // _LIBCXXABI_NO_EXCEPTIONS
91#endif // _LIBCPP_HAS_NO_EXCEPTIONS
8292 p = ::operator new[](size);
83#ifndef _LIBCXXABI_NO_EXCEPTIONS
93#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
8494 }
8595 catch (...)
8696 {
8797 }
88#endif // _LIBCXXABI_NO_EXCEPTIONS
98#endif // _LIBCPP_HAS_NO_EXCEPTIONS
8999 return p;
90100}
91101
92_LIBCXXABI_WEAK
102_LIBCPP_WEAK
93103void
94104operator delete(void* ptr) noexcept
95105{
96 ::free(ptr);
106 std::free(ptr);
97107}
98108
99_LIBCXXABI_WEAK
109_LIBCPP_WEAK
100110void
101111operator delete(void* ptr, const std::nothrow_t&) noexcept
102112{
103113 ::operator delete(ptr);
104114}
105115
106_LIBCXXABI_WEAK
116_LIBCPP_WEAK
107117void
108118operator delete(void* ptr, size_t) noexcept
109119{
110120 ::operator delete(ptr);
111121}
112122
113_LIBCXXABI_WEAK
123_LIBCPP_WEAK
114124void
115125operator delete[] (void* ptr) noexcept
116126{
117127 ::operator delete(ptr);
118128}
119129
120_LIBCXXABI_WEAK
130_LIBCPP_WEAK
121131void
122132operator delete[] (void* ptr, const std::nothrow_t&) noexcept
123133{
124134 ::operator delete[](ptr);
125135}
126136
127_LIBCXXABI_WEAK
137_LIBCPP_WEAK
128138void
129139operator delete[] (void* ptr, size_t) noexcept
130140{
......@@ -133,7 +143,7 @@ operator delete[] (void* ptr, size_t) noexcept
133143
134144#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
135145
136_LIBCXXABI_WEAK
146_LIBCPP_WEAK
137147void *
138148operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
139149{
......@@ -155,7 +165,7 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
155165 if (nh)
156166 nh();
157167 else {
158#ifndef _LIBCXXABI_NO_EXCEPTIONS
168#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
159169 throw std::bad_alloc();
160170#else
161171 break;
......@@ -165,87 +175,87 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
165175 return p;
166176}
167177
168_LIBCXXABI_WEAK
178_LIBCPP_WEAK
169179void*
170180operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept
171181{
172182 void* p = nullptr;
173#ifndef _LIBCXXABI_NO_EXCEPTIONS
183#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
174184 try
175185 {
176#endif // _LIBCXXABI_NO_EXCEPTIONS
186#endif // _LIBCPP_HAS_NO_EXCEPTIONS
177187 p = ::operator new(size, alignment);
178#ifndef _LIBCXXABI_NO_EXCEPTIONS
188#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
179189 }
180190 catch (...)
181191 {
182192 }
183#endif // _LIBCXXABI_NO_EXCEPTIONS
193#endif // _LIBCPP_HAS_NO_EXCEPTIONS
184194 return p;
185195}
186196
187_LIBCXXABI_WEAK
197_LIBCPP_WEAK
188198void*
189199operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
190200{
191201 return ::operator new(size, alignment);
192202}
193203
194_LIBCXXABI_WEAK
204_LIBCPP_WEAK
195205void*
196206operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept
197207{
198208 void* p = nullptr;
199#ifndef _LIBCXXABI_NO_EXCEPTIONS
209#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
200210 try
201211 {
202#endif // _LIBCXXABI_NO_EXCEPTIONS
212#endif // _LIBCPP_HAS_NO_EXCEPTIONS
203213 p = ::operator new[](size, alignment);
204#ifndef _LIBCXXABI_NO_EXCEPTIONS
214#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
205215 }
206216 catch (...)
207217 {
208218 }
209#endif // _LIBCXXABI_NO_EXCEPTIONS
219#endif // _LIBCPP_HAS_NO_EXCEPTIONS
210220 return p;
211221}
212222
213_LIBCXXABI_WEAK
223_LIBCPP_WEAK
214224void
215225operator delete(void* ptr, std::align_val_t) noexcept
216226{
217227 std::__libcpp_aligned_free(ptr);
218228}
219229
220_LIBCXXABI_WEAK
230_LIBCPP_WEAK
221231void
222232operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept
223233{
224234 ::operator delete(ptr, alignment);
225235}
226236
227_LIBCXXABI_WEAK
237_LIBCPP_WEAK
228238void
229239operator delete(void* ptr, size_t, std::align_val_t alignment) noexcept
230240{
231241 ::operator delete(ptr, alignment);
232242}
233243
234_LIBCXXABI_WEAK
244_LIBCPP_WEAK
235245void
236246operator delete[] (void* ptr, std::align_val_t alignment) noexcept
237247{
238248 ::operator delete(ptr, alignment);
239249}
240250
241_LIBCXXABI_WEAK
251_LIBCPP_WEAK
242252void
243253operator delete[] (void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept
244254{
245255 ::operator delete[](ptr, alignment);
246256}
247257
248_LIBCXXABI_WEAK
258_LIBCPP_WEAK
249259void
250260operator delete[] (void* ptr, size_t, std::align_val_t alignment) noexcept
251261{
......@@ -253,3 +263,4 @@ operator delete[] (void* ptr, size_t, std::align_val_t alignment) noexcept
253263}
254264
255265#endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
266// ------------------ END COPY ------------------