Skip to content

Commit 465b7dd

Browse files
Clean up tests and fix some 'noexcepts'
1 parent 9a32997 commit 465b7dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+768
-1380
lines changed

libcxx/include/__stacktrace/basic_stacktrace.h

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,8 @@
1010
#ifndef _LIBCPP___BASIC_STACKTRACE_H
1111
#define _LIBCPP___BASIC_STACKTRACE_H
1212

13-
#include <__config>
14-
15-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16-
# pragma GCC system_header
17-
#endif
18-
19-
_LIBCPP_PUSH_MACROS
20-
#include <__undef_macros>
21-
2213
#include <__assert>
14+
#include <__config>
2315
#include <__cstddef/size_t.h>
2416
#include <__functional/function.h>
2517
#include <__functional/hash.h>
@@ -29,24 +21,28 @@ _LIBCPP_PUSH_MACROS
2921
#include <__memory/allocator_traits.h>
3022
#include <__memory_resource/polymorphic_allocator.h>
3123
#include <__new/allocate.h>
24+
#include <__stacktrace/stacktrace_entry.h>
3225
#include <__type_traits/is_nothrow_constructible.h>
3326
#include <__vector/vector.h>
3427
#include <cstddef>
3528
#include <iostream>
3629
#include <string>
3730
#include <utility>
38-
3931
#if _LIBCPP_HAS_LOCALIZATION
4032
# include <__fwd/ostream.h>
4133
#endif // _LIBCPP_HAS_LOCALIZATION
42-
4334
#if !defined(_WIN32)
4435
# include <unwind.h>
4536
#endif
4637

47-
#if _LIBCPP_STD_VER >= 23 && _LIBCPP_AVAILABILITY_HAS_STACKTRACE
38+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
39+
# pragma GCC system_header
40+
#endif
41+
42+
_LIBCPP_PUSH_MACROS
43+
#include <__undef_macros>
4844

49-
# include <__stacktrace/stacktrace_entry.h>
45+
#if _LIBCPP_STD_VER >= 23 && _LIBCPP_AVAILABILITY_HAS_STACKTRACE
5046

5147
_LIBCPP_BEGIN_NAMESPACE_STD
5248

@@ -103,12 +99,9 @@ class basic_stacktrace : private __stacktrace::_Trace {
10399
friend struct __stacktrace::_Trace;
104100

105101
vector<stacktrace_entry, _Allocator> __entries_;
106-
_LIBCPP_HIDE_FROM_ABI _EntryIters entry_iters() {
107-
auto* __data = __entries_.data();
108-
auto __size = __entries_.size();
109-
std::cerr << "@@@ data:" << __data << " size:" << __size << '\n';
110-
return {__data, __size};
111-
}
102+
103+
_LIBCPP_HIDE_FROM_ABI _EntryIters entry_iters() { return {__entries_.data(), __entries_.size()}; }
104+
112105
_LIBCPP_HIDE_FROM_ABI __stacktrace::_Entry& entry_append() {
113106
return (__stacktrace::_Entry&)__entries_.emplace_back();
114107
}
@@ -170,10 +163,10 @@ class basic_stacktrace : private __stacktrace::_Trace {
170163
_LIBCPP_HIDE_FROM_ABI basic_stacktrace() noexcept(is_nothrow_default_constructible_v<allocator_type>)
171164
: basic_stacktrace(allocator_type()) {}
172165

173-
_LIBCPP_HIDE_FROM_ABI explicit basic_stacktrace(const allocator_type& __alloc)
166+
_LIBCPP_HIDE_FROM_ABI explicit basic_stacktrace(const allocator_type& __alloc) noexcept
174167
: _Trace(entry_iters_fn(), entry_append_fn()), __entries_(__alloc) {}
175168

176-
_LIBCPP_HIDE_FROM_ABI basic_stacktrace(const basic_stacktrace& __other) noexcept
169+
_LIBCPP_HIDE_FROM_ABI basic_stacktrace(const basic_stacktrace& __other)
177170
: _Trace(entry_iters_fn(), entry_append_fn()) {
178171
__entries_ = __other.__entries_;
179172
}
@@ -354,6 +347,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE inline void _Trace::populate_addrs(s
354347
# endif // _WIN32
355348

356349
_Trace& _Trace::base(auto& __trace) { return *static_cast<_Trace*>(std::addressof(__trace)); }
350+
357351
_Trace const& _Trace::base(auto const& __trace) { return *static_cast<_Trace const*>(std::addressof(__trace)); }
358352

359353
} // namespace __stacktrace

libcxx/include/__stacktrace/stacktrace_entry.h

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,26 @@
1010
#ifndef _LIBCPP___STACKTRACE_ENTRY_H
1111
#define _LIBCPP___STACKTRACE_ENTRY_H
1212

13-
#include <__config>
14-
#include <cstring>
15-
16-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17-
# pragma GCC system_header
18-
#endif
19-
20-
_LIBCPP_PUSH_MACROS
21-
#include <__undef_macros>
22-
2313
#include <__assert>
14+
#include <__config>
2415
#include <__functional/function.h>
2516
#include <__fwd/format.h>
2617
#include <cstddef>
2718
#include <cstdint>
19+
#include <cstring>
2820
#include <string>
2921
#include <string_view>
30-
3122
#if _LIBCPP_HAS_LOCALIZATION
3223
# include <__fwd/ostream.h>
3324
#endif // _LIBCPP_HAS_LOCALIZATION
3425

26+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27+
# pragma GCC system_header
28+
#endif
29+
30+
_LIBCPP_PUSH_MACROS
31+
#include <__undef_macros>
32+
3533
#if _LIBCPP_STD_VER >= 23 && _LIBCPP_AVAILABILITY_HAS_STACKTRACE
3634

3735
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -52,23 +50,14 @@ struct _StringWrapper {
5250
// 4. just use std::string, which is just plain wrong
5351
// 5. ...?
5452

55-
char __chars_[1024]{0};
53+
std::string __str_;
5654

57-
_LIBCPP_HIDE_FROM_ABI std::string_view view() const { return __chars_; }
55+
_LIBCPP_HIDE_FROM_ABI std::string_view view() const { return __str_; }
5856

5957
_LIBCPP_HIDE_FROM_ABI _StringWrapper& assign(std::string_view __view) {
60-
size_t __size = std::min(__view.size(), sizeof(__chars_) - 1);
61-
memcpy(__chars_, __view.data(), __size);
62-
__chars_[__size] = 0;
58+
__str_ = __view;
6359
return *this;
6460
}
65-
66-
_LIBCPP_HIDE_FROM_ABI ~_StringWrapper() = default;
67-
_LIBCPP_HIDE_FROM_ABI _StringWrapper() = default;
68-
_LIBCPP_HIDE_FROM_ABI _StringWrapper(_StringWrapper const&) = default;
69-
_LIBCPP_HIDE_FROM_ABI _StringWrapper(_StringWrapper&&) = default;
70-
_LIBCPP_HIDE_FROM_ABI _StringWrapper& operator=(_StringWrapper const&) = default;
71-
_LIBCPP_HIDE_FROM_ABI _StringWrapper& operator=(_StringWrapper&&) = default;
7261
};
7362

7463
struct _Entry {
@@ -176,6 +165,7 @@ struct hash<stacktrace_entry> {
176165
namespace __stacktrace {
177166

178167
_LIBCPP_HIDE_FROM_ABI inline _Entry& _Entry::base(stacktrace_entry& __entry) { return __entry.__base_; }
168+
179169
_LIBCPP_HIDE_FROM_ABI inline _Entry const& _Entry::base(stacktrace_entry const& __entry) { return __entry.__base_; }
180170

181171
} // namespace __stacktrace

libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
{'is_defined': False, 'name': '_ZTVSt13runtime_error', 'size': 0, 'type': 'OBJECT'}
3636
{'is_defined': False, 'name': '_ZTVSt14overflow_error', 'size': 0, 'type': 'OBJECT'}
3737
{'is_defined': False, 'name': '_ZTVSt16invalid_argument', 'size': 0, 'type': 'OBJECT'}
38+
{'is_defined': False, 'name': '_ZTVSt9exception', 'size': 0, 'type': 'OBJECT'}
3839
{'is_defined': False, 'name': '_ZdaPv', 'type': 'FUNC'}
3940
{'is_defined': False, 'name': '_ZdaPvSt11align_val_t', 'type': 'FUNC'}
4041
{'is_defined': False, 'name': '_ZdlPv', 'type': 'FUNC'}
@@ -104,8 +105,10 @@
104105
{'is_defined': True, 'name': '_ZNKSt3__110moneypunctIwLb1EE16do_negative_signEv', 'type': 'FUNC'}
105106
{'is_defined': True, 'name': '_ZNKSt3__110moneypunctIwLb1EE16do_positive_signEv', 'type': 'FUNC'}
106107
{'is_defined': True, 'name': '_ZNKSt3__110moneypunctIwLb1EE16do_thousands_sepEv', 'type': 'FUNC'}
108+
{'is_defined': True, 'name': '_ZNKSt3__112__stacktrace6_Entry4hashEv', 'type': 'FUNC'}
107109
{'is_defined': True, 'name': '_ZNKSt3__112__stacktrace6_Entry8write_toERNS_13basic_ostreamIcNS_11char_traitsIcEEEE', 'type': 'FUNC'}
108110
{'is_defined': True, 'name': '_ZNKSt3__112__stacktrace6_Entry9to_stringEv', 'type': 'FUNC'}
111+
{'is_defined': True, 'name': '_ZNKSt3__112__stacktrace6_Trace4hashEv', 'type': 'FUNC'}
109112
{'is_defined': True, 'name': '_ZNKSt3__112__stacktrace6_Trace8write_toERNS_13basic_ostreamIcNS_11char_traitsIcEEEE', 'type': 'FUNC'}
110113
{'is_defined': True, 'name': '_ZNKSt3__112__stacktrace6_Trace9to_stringEv', 'type': 'FUNC'}
111114
{'is_defined': True, 'name': '_ZNKSt3__112bad_weak_ptr4whatEv', 'type': 'FUNC'}
@@ -1967,6 +1970,8 @@
19671970
{'is_defined': True, 'name': '_ZTVNSt3__120__codecvt_utf8_utf16IDiEE', 'size': 96, 'type': 'OBJECT'}
19681971
{'is_defined': True, 'name': '_ZTVNSt3__120__codecvt_utf8_utf16IDsEE', 'size': 96, 'type': 'OBJECT'}
19691972
{'is_defined': True, 'name': '_ZTVNSt3__120__codecvt_utf8_utf16IwEE', 'size': 96, 'type': 'OBJECT'}
1973+
{'is_defined': True, 'name': '_ZTVNSt3__120__time_get_c_storageIcEE', 'size': 72, 'type': 'OBJECT'}
1974+
{'is_defined': True, 'name': '_ZTVNSt3__120__time_get_c_storageIwEE', 'size': 72, 'type': 'OBJECT'}
19701975
{'is_defined': True, 'name': '_ZTVNSt3__13pmr15memory_resourceE', 'size': 56, 'type': 'OBJECT'}
19711976
{'is_defined': True, 'name': '_ZTVNSt3__13pmr25monotonic_buffer_resourceE', 'size': 56, 'type': 'OBJECT'}
19721977
{'is_defined': True, 'name': '_ZTVNSt3__13pmr26synchronized_pool_resourceE', 'size': 56, 'type': 'OBJECT'}

libcxx/modules/std/stacktrace.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
//===----------------------------------------------------------------------===//
99

1010
export namespace std {
11-
#if _LIBCPP_STD_VER >= 23
11+
#if _LIBCPP_STD_VER >= 23 && _LIBCPP_AVAILABILITY_HAS_STACKTRACE
1212

13-
// [stacktrace.entry], class stacktrace_­entry
13+
// [stacktrace.entry], class stacktrace_entry
1414
using std::stacktrace_entry;
1515

16-
// [stacktrace.basic], class template basic_­stacktrace
16+
// [stacktrace.basic], class template basic_stacktrace
1717
using std::basic_stacktrace;
1818

19-
// basic_­stacktrace typedef-names
19+
// basic_stacktrace typedef-names
2020
using std::stacktrace;
2121

2222
// [stacktrace.basic.nonmem], non-member functions
@@ -39,5 +39,5 @@ export namespace std {
3939
// P2693R1, "Formatting thread::id and stacktrace")
4040
// using std::formatter;
4141

42-
#endif // _LIBCPP_STD_VER >= 23
42+
#endif // _LIBCPP_STD_VER >= 23 && _LIBCPP_AVAILABILITY_HAS_STACKTRACE
4343
} // namespace std

libcxx/test/libcxx/transitive_includes/cxx23.csv

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,19 +926,36 @@ stack limits
926926
stack stdexcept
927927
stack tuple
928928
stack version
929+
stacktrace array
930+
stacktrace bitset
929931
stacktrace cctype
932+
stacktrace cerrno
930933
stacktrace climits
934+
stacktrace clocale
935+
stacktrace cmath
931936
stacktrace compare
932937
stacktrace cstddef
933938
stacktrace cstdint
934939
stacktrace cstdio
940+
stacktrace cstdlib
935941
stacktrace cstring
942+
stacktrace ctime
936943
stacktrace cwchar
937944
stacktrace cwctype
945+
stacktrace format
938946
stacktrace initializer_list
947+
stacktrace ios
939948
stacktrace iosfwd
949+
stacktrace iostream
950+
stacktrace istream
940951
stacktrace limits
952+
stacktrace locale
953+
stacktrace optional
954+
stacktrace ostream
955+
stacktrace print
956+
stacktrace ratio
941957
stacktrace stdexcept
958+
stacktrace streambuf
942959
stacktrace string
943960
stacktrace string_view
944961
stacktrace tuple

libcxx/test/libcxx/transitive_includes/cxx26.csv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,19 +908,35 @@ stack limits
908908
stack stdexcept
909909
stack tuple
910910
stack version
911+
stacktrace array
912+
stacktrace bitset
911913
stacktrace cctype
914+
stacktrace cerrno
912915
stacktrace climits
916+
stacktrace clocale
917+
stacktrace cmath
913918
stacktrace compare
914919
stacktrace cstddef
915920
stacktrace cstdint
916921
stacktrace cstdio
922+
stacktrace cstdlib
917923
stacktrace cstring
924+
stacktrace ctime
918925
stacktrace cwchar
919926
stacktrace cwctype
927+
stacktrace format
920928
stacktrace initializer_list
929+
stacktrace ios
921930
stacktrace iosfwd
931+
stacktrace iostream
932+
stacktrace istream
922933
stacktrace limits
934+
stacktrace optional
935+
stacktrace ostream
936+
stacktrace print
937+
stacktrace ratio
923938
stacktrace stdexcept
939+
stacktrace streambuf
924940
stacktrace string
925941
stacktrace string_view
926942
stacktrace tuple

libcxx/test/std/diagnostics/stacktrace/basic.cmp/equality.pass.cpp

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,41 @@
77
//===----------------------------------------------------------------------===//
88

99
// REQUIRES: std-at-least-c++23
10-
// XFAIL: availability-stacktrace-missing
10+
// UNSUPPORTED: availability-stacktrace-missing
1111

1212
// (19.6.4.4) Comparisons [stacktrace.basic.cmp]
13-
// template<class Allocator2>
14-
// friend bool operator==(const basic_stacktrace& x,
15-
// const basic_stacktrace<Allocator2>& y) noexcept;
13+
//
14+
// template<class Allocator2>
15+
// friend bool operator==(const basic_stacktrace& x,
16+
// const basic_stacktrace<Allocator2>& y) noexcept;
1617

1718
#include <cassert>
1819
#include <stacktrace>
1920

20-
#include "test_macros.h"
21-
22-
// Disable TCO for calls into, and out from, the annotated function.
23-
#define STACKTRACE_AVOID_OPT TEST_NO_TAIL_CALLS_IN TEST_NO_TAIL_CALLS_OUT TEST_NOINLINE
24-
25-
// Some non-inlinable functions to help contrive different stacktraces:
26-
// main calls the "middle" funcs, and those both call "top".
27-
// We'll consider main the "bottom" func, even though there are other functions
28-
// like `_start` which call main; those are trimmed via `max_depth` argument.
29-
30-
STACKTRACE_AVOID_OPT std::stacktrace top(size_t skip, size_t depth) { return std::stacktrace::current(skip, depth); }
31-
STACKTRACE_AVOID_OPT std::stacktrace middle1(size_t skip, size_t depth) { return top(skip, depth); }
32-
STACKTRACE_AVOID_OPT std::stacktrace middle2(size_t skip, size_t depth) { return top(skip, depth); }
33-
34-
STACKTRACE_AVOID_OPT int main(int, char**) {
35-
// Collect a few different stacktraces and test `operator==` and `operator!=`.
36-
37-
std::stacktrace st0; // default-initializable empty stacktrace
38-
static_assert(noexcept(st0 == st0)); // verify noexcept-ness
39-
static_assert(noexcept(st0 != st0)); // verify noexcept-ness
40-
assert(st0 == st0); // trivial: self-equality
41-
42-
std::stacktrace st1a = top(0, 2); // st1a = [top, main]
43-
assert(st1a == st1a); // trivial: self-equality
44-
assert(st1a != st0); //
45-
std::stacktrace st2a = middle1(0, 3); // st2a = [top, middle1, main]
46-
assert(st2a == st2a); //
47-
assert(st1a != st2a); //
48-
std::stacktrace st2b = middle2(0, 3); // st2b = [top, middle2, main]
49-
assert(st2b == st2b); //
50-
assert(st2a != st2b); //
51-
52-
// Verify two equivalent stacktrace instances are equal, even if not "same".
53-
// For both, we'll take only two entries, which should be equivalent.
54-
std::stacktrace st3a = middle1(0, 2); // st3a = [top, middle1]
55-
std::stacktrace st3b = middle1(0, 2); // st3b = [top, middle1]
56-
assert(st3a == st3b);
21+
// Call chain is: main -> c -> b -> a -> stacktrace::current;
22+
// we're only checking a, b, c in the returned stacktrace, so use max_depth of 3.
23+
_LIBCPP_NOINLINE std::stacktrace a(size_t skip = 0) { return std::stacktrace::current(skip, 3); }
24+
_LIBCPP_NOINLINE std::stacktrace b(size_t skip = 0) { return a(skip); }
25+
_LIBCPP_NOINLINE std::stacktrace c(size_t skip = 0) { return b(skip); }
26+
27+
int main(int, char**) {
28+
std::stacktrace st0;
29+
static_assert(noexcept(st0 == st0));
30+
static_assert(noexcept(st0 != st0));
31+
assert(st0 == st0);
32+
33+
std::stacktrace st1 = a();
34+
assert(st1 != st0);
35+
36+
std::stacktrace st2 = b();
37+
assert(st2 != st1);
38+
assert(st2 != st0);
39+
40+
std::stacktrace st3 = c();
41+
assert(st3 != st0);
42+
assert(st3 != st1);
43+
assert(st3 != st2);
44+
assert(c() == st3);
5745

5846
return 0;
5947
}

0 commit comments

Comments
 (0)