Bug Summary

File:root/firefox-clang/mfbt/tests/TestLinkedList.cpp
Warning:line 262, column 3
Method called on moved-from object 'c2'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name TestLinkedList.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/mfbt/tests -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/mfbt/tests -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -I /root/firefox-clang/mfbt/tests -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/mfbt/tests -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/testing -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c++ /root/firefox-clang/mfbt/tests/TestLinkedList.cpp
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#include "mozilla/Assertions.h"
6#include "mozilla/LinkedList.h"
7
8using mozilla::AutoCleanLinkedList;
9using mozilla::LinkedList;
10using mozilla::LinkedListElement;
11
12struct SomeClass : public LinkedListElement<SomeClass> {
13 unsigned int mValue;
14 explicit SomeClass(int aValue = 0) : mValue(aValue) {}
15 SomeClass(SomeClass&&) = default;
16 SomeClass& operator=(SomeClass&&) = default;
17 void incr() { ++mValue; }
18};
19
20template <size_t N>
21static void CheckListValues(LinkedList<SomeClass>& list,
22 unsigned int (&values)[N]) {
23 size_t count = 0;
24 for (SomeClass* x : list) {
25 MOZ_RELEASE_ASSERT(x->mValue == values[count])do { static_assert( mozilla::detail::AssertionConditionType<
decltype(x->mValue == values[count])>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(x->mValue == values[count
]))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("x->mValue == values[count]", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 25); do { } while (false); do { MOZ_CrashSequence(__null, 25
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
26 ++count;
27 }
28 MOZ_RELEASE_ASSERT(count == N)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(count == N)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(count == N))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("count == N", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 28); do { } while (false); do { MOZ_CrashSequence(__null, 28
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
29}
30
31static void TestList() {
32 LinkedList<SomeClass> list;
33
34 SomeClass one(1), two(2), three(3);
35
36 MOZ_RELEASE_ASSERT(list.isEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.isEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.isEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("list.isEmpty()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 36); do
{ } while (false); do { MOZ_CrashSequence(__null, 36); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
37 MOZ_RELEASE_ASSERT(list.length() == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.length() == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.length() == 0))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("list.length() == 0"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 37); do
{ } while (false); do { MOZ_CrashSequence(__null, 37); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
38 MOZ_RELEASE_ASSERT(!list.getFirst())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.getFirst())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.getFirst()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.getFirst()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 38); do
{ } while (false); do { MOZ_CrashSequence(__null, 38); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
39 MOZ_RELEASE_ASSERT(!list.getLast())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.getLast())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.getLast()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.getLast()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 39); do
{ } while (false); do { MOZ_CrashSequence(__null, 39); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
40 MOZ_RELEASE_ASSERT(!list.popFirst())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.popFirst())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.popFirst()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.popFirst()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 40); do
{ } while (false); do { MOZ_CrashSequence(__null, 40); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
41 MOZ_RELEASE_ASSERT(!list.popLast())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.popLast())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.popLast()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.popLast()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 41); do
{ } while (false); do { MOZ_CrashSequence(__null, 41); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
42
43 for (SomeClass* x : list) {
44 MOZ_RELEASE_ASSERT(x)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(x)>::isValid, "invalid assertion condition"); if (
(__builtin_expect(!!(!(!!(x))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("x", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 44
); do { } while (false); do { MOZ_CrashSequence(__null, 44); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
45 MOZ_RELEASE_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 45); do { } while (false); do { MOZ_CrashSequence(__null, 45
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
46 }
47
48 list.insertFront(&one);
49 {
50 unsigned int check[]{1};
51 CheckListValues(list, check);
52 }
53
54 MOZ_RELEASE_ASSERT(one.isInList())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(one.isInList())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(one.isInList()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("one.isInList()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 54); do
{ } while (false); do { MOZ_CrashSequence(__null, 54); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
55 MOZ_RELEASE_ASSERT(!two.isInList())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!two.isInList())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!two.isInList()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!two.isInList()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 55); do
{ } while (false); do { MOZ_CrashSequence(__null, 55); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
56 MOZ_RELEASE_ASSERT(!three.isInList())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!three.isInList())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!three.isInList()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!three.isInList()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 56); do
{ } while (false); do { MOZ_CrashSequence(__null, 56); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
57
58 MOZ_RELEASE_ASSERT(list.contains(&one))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.contains(&one))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.contains(&one)))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("list.contains(&one)"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 58); do
{ } while (false); do { MOZ_CrashSequence(__null, 58); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
59 MOZ_RELEASE_ASSERT(!list.contains(&two))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.contains(&two))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.contains(&two)))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("!list.contains(&two)"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 59); do
{ } while (false); do { MOZ_CrashSequence(__null, 59); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
60 MOZ_RELEASE_ASSERT(!list.contains(&three))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.contains(&three))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.contains(&three)))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!list.contains(&three)"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 60); do
{ } while (false); do { MOZ_CrashSequence(__null, 60); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
61
62 MOZ_RELEASE_ASSERT(!list.isEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.isEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.isEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.isEmpty()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 62); do
{ } while (false); do { MOZ_CrashSequence(__null, 62); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
63 MOZ_RELEASE_ASSERT(list.length() == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.length() == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.length() == 1))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("list.length() == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 63); do
{ } while (false); do { MOZ_CrashSequence(__null, 63); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
64 MOZ_RELEASE_ASSERT(list.getFirst()->mValue == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getFirst()->mValue == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getFirst()->mValue ==
1))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("list.getFirst()->mValue == 1", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 64); do { } while (false); do { MOZ_CrashSequence(__null, 64
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
65 MOZ_RELEASE_ASSERT(list.getLast()->mValue == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getLast()->mValue == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getLast()->mValue ==
1))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("list.getLast()->mValue == 1", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 65); do { } while (false); do { MOZ_CrashSequence(__null, 65
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
66
67 list.insertFront(&two);
68 {
69 unsigned int check[]{2, 1};
70 CheckListValues(list, check);
71 }
72
73 MOZ_RELEASE_ASSERT(list.length() == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.length() == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.length() == 2))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("list.length() == 2"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 73); do
{ } while (false); do { MOZ_CrashSequence(__null, 73); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
74 MOZ_RELEASE_ASSERT(list.getFirst()->mValue == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getFirst()->mValue == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getFirst()->mValue ==
2))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("list.getFirst()->mValue == 2", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 74); do { } while (false); do { MOZ_CrashSequence(__null, 74
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
75 MOZ_RELEASE_ASSERT(list.getLast()->mValue == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getLast()->mValue == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getLast()->mValue ==
1))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("list.getLast()->mValue == 1", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 75); do { } while (false); do { MOZ_CrashSequence(__null, 75
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
76
77 list.insertBack(&three);
78 {
79 unsigned int check[]{2, 1, 3};
80 CheckListValues(list, check);
81 }
82
83 MOZ_RELEASE_ASSERT(list.length() == 3)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.length() == 3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.length() == 3))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("list.length() == 3"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 83); do
{ } while (false); do { MOZ_CrashSequence(__null, 83); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
84 MOZ_RELEASE_ASSERT(list.getFirst()->mValue == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getFirst()->mValue == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getFirst()->mValue ==
2))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("list.getFirst()->mValue == 2", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 84); do { } while (false); do { MOZ_CrashSequence(__null, 84
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
85 MOZ_RELEASE_ASSERT(list.getLast()->mValue == 3)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getLast()->mValue == 3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getLast()->mValue ==
3))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("list.getLast()->mValue == 3", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 85); do { } while (false); do { MOZ_CrashSequence(__null, 85
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
86
87 one.removeFrom(list);
88 {
89 unsigned int check[]{2, 3};
90 CheckListValues(list, check);
91 }
92
93 three.setPrevious(&one);
94 {
95 unsigned int check[]{2, 1, 3};
96 CheckListValues(list, check);
97 }
98
99 three.removeFrom(list);
100 {
101 unsigned int check[]{2, 1};
102 CheckListValues(list, check);
103 }
104
105 two.setPrevious(&three);
106 {
107 unsigned int check[]{3, 2, 1};
108 CheckListValues(list, check);
109 }
110
111 three.removeFrom(list);
112 {
113 unsigned int check[]{2, 1};
114 CheckListValues(list, check);
115 }
116
117 two.setNext(&three);
118 {
119 unsigned int check[]{2, 3, 1};
120 CheckListValues(list, check);
121 }
122
123 one.remove();
124 {
125 unsigned int check[]{2, 3};
126 CheckListValues(list, check);
127 }
128
129 two.remove();
130 {
131 unsigned int check[]{3};
132 CheckListValues(list, check);
133 }
134
135 three.setPrevious(&two);
136 {
137 unsigned int check[]{2, 3};
138 CheckListValues(list, check);
139 }
140
141 three.remove();
142 {
143 unsigned int check[]{2};
144 CheckListValues(list, check);
145 }
146
147 two.remove();
148
149 list.insertBack(&three);
150 {
151 unsigned int check[]{3};
152 CheckListValues(list, check);
153 }
154
155 list.insertFront(&two);
156 {
157 unsigned int check[]{2, 3};
158 CheckListValues(list, check);
159 }
160
161 for (SomeClass* x : list) {
162 x->incr();
163 }
164
165 MOZ_RELEASE_ASSERT(list.length() == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.length() == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.length() == 2))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("list.length() == 2"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 165); do
{ } while (false); do { MOZ_CrashSequence(__null, 165); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
166 MOZ_RELEASE_ASSERT(list.getFirst() == &two)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getFirst() == &two)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getFirst() == &two)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("list.getFirst() == &two"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 166); do
{ } while (false); do { MOZ_CrashSequence(__null, 166); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
167 MOZ_RELEASE_ASSERT(list.getLast() == &three)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getLast() == &three)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getLast() == &three
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"list.getLast() == &three", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 167); do { } while (false); do { MOZ_CrashSequence(__null, 167
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
168 MOZ_RELEASE_ASSERT(list.getFirst()->mValue == 3)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getFirst()->mValue == 3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getFirst()->mValue ==
3))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("list.getFirst()->mValue == 3", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 168); do { } while (false); do { MOZ_CrashSequence(__null, 168
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
169 MOZ_RELEASE_ASSERT(list.getLast()->mValue == 4)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.getLast()->mValue == 4)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.getLast()->mValue ==
4))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("list.getLast()->mValue == 4", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 169); do { } while (false); do { MOZ_CrashSequence(__null, 169
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
170
171 const LinkedList<SomeClass>& constList = list;
172 for (const SomeClass* x : constList) {
173 MOZ_RELEASE_ASSERT(x)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(x)>::isValid, "invalid assertion condition"); if (
(__builtin_expect(!!(!(!!(x))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("x", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 173
); do { } while (false); do { MOZ_CrashSequence(__null, 173);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
174 }
175}
176
177static void TestExtendLists() {
178 AutoCleanLinkedList<SomeClass> list1, list2;
179
180 constexpr unsigned int N = 5;
181 for (unsigned int i = 0; i < N; ++i) {
182 list1.insertBack(new SomeClass(static_cast<int>(i)));
183
184 AutoCleanLinkedList<SomeClass> singleItemList;
185 singleItemList.insertFront(new SomeClass(static_cast<int>(i + N)));
186 list2.extendBack(std::move(singleItemList));
187 }
188 // list1 = { 0, 1, 2, 3, 4 }
189 // list2 = { 5, 6, 7, 8, 9 }
190
191 list1.extendBack(AutoCleanLinkedList<SomeClass>());
192 list1.extendBack(std::move(list2));
193
194 // Make sure the line above has properly emptied |list2|.
195 MOZ_RELEASE_ASSERT(list2.isEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list2.isEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list2.isEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("list2.isEmpty()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 195); do
{ } while (false); do { MOZ_CrashSequence(__null, 195); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
; // NOLINT(bugprone-use-after-move)
196
197 size_t i = 0;
198 for (SomeClass* x : list1) {
199 MOZ_RELEASE_ASSERT(x->mValue == i++)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(x->mValue == i++)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(x->mValue == i++))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("x->mValue == i++"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 199); do
{ } while (false); do { MOZ_CrashSequence(__null, 199); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
200 }
201 MOZ_RELEASE_ASSERT(i == N * 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(i == N * 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(i == N * 2))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("i == N * 2", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 201); do { } while (false); do { MOZ_CrashSequence(__null, 201
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
202}
203
204void TestSplice() {
205 AutoCleanLinkedList<SomeClass> list1, list2;
206 for (unsigned int i = 1; i <= 5; ++i) {
207 list1.insertBack(new SomeClass(static_cast<int>(i)));
208
209 AutoCleanLinkedList<SomeClass> singleItemList;
210 singleItemList.insertFront(new SomeClass(static_cast<int>(i * 10)));
211 list2.extendBack(std::move(singleItemList));
212 }
213 // list1 = { 1, 2, 3, 4, 5 }
214 // list2 = { 10, 20, 30, 40, 50 }
215
216 list1.splice(2, list2, 0, 5);
217
218 MOZ_RELEASE_ASSERT(list2.isEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list2.isEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list2.isEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("list2.isEmpty()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 218); do
{ } while (false); do { MOZ_CrashSequence(__null, 218); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
219 unsigned int kExpected1[]{1, 2, 10, 20, 30, 40, 50, 3, 4, 5};
220 CheckListValues(list1, kExpected1);
221
222 // Since aSourceLen=100 exceeds list1's end, the function transfers
223 // three items [3, 4, 5].
224 list2.splice(0, list1, 7, 100);
225
226 unsigned int kExpected2[]{1, 2, 10, 20, 30, 40, 50};
227 unsigned int kExpected3[]{3, 4, 5};
228 CheckListValues(list1, kExpected2);
229 CheckListValues(list2, kExpected3);
230
231 // Since aDestinationPos=100 exceeds list2's end, the function transfers
232 // items to list2's end.
233 list2.splice(100, list1, 1, 1);
234
235 unsigned int kExpected4[]{1, 10, 20, 30, 40, 50};
236 unsigned int kExpected5[]{3, 4, 5, 2};
237 CheckListValues(list1, kExpected4);
238 CheckListValues(list2, kExpected5);
239}
240
241static void TestMove() {
242 auto MakeSomeClass = [](unsigned int aValue) -> SomeClass {
243 return SomeClass(aValue);
244 };
245
246 LinkedList<SomeClass> list1;
247
248 // Test move constructor for LinkedListElement.
249 SomeClass c1(MakeSomeClass(1));
250 list1.insertBack(&c1);
251
252 // Test move assignment for LinkedListElement from an element not in a
253 // list.
254 SomeClass c2;
255 c2 = MakeSomeClass(2);
256 list1.insertBack(&c2);
257
258 // Test move assignment of LinkedListElement from an element already in a
259 // list.
260 SomeClass c3;
261 c3 = std::move(c2);
2
Object 'c2' is moved
262 MOZ_RELEASE_ASSERT(!c2.isInList())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!c2.isInList())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!c2.isInList()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!c2.isInList()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 262); do
{ } while (false); do { MOZ_CrashSequence(__null, 262); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
3
Method called on moved-from object 'c2'
263 MOZ_RELEASE_ASSERT(c3.isInList())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(c3.isInList())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(c3.isInList()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("c3.isInList()",
"/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 263); do
{ } while (false); do { MOZ_CrashSequence(__null, 263); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
264
265 // Test move constructor for LinkedList.
266 LinkedList<SomeClass> list2(std::move(list1));
267 {
268 unsigned int check[]{1, 2};
269 CheckListValues(list2, check);
270 }
271 MOZ_RELEASE_ASSERT(list1.isEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list1.isEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list1.isEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("list1.isEmpty()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 271); do
{ } while (false); do { MOZ_CrashSequence(__null, 271); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
272
273 // Test move assignment for LinkedList.
274 LinkedList<SomeClass> list3;
275 list3 = std::move(list2);
276 {
277 unsigned int check[]{1, 2};
278 CheckListValues(list3, check);
279 }
280 MOZ_RELEASE_ASSERT(list2.isEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list2.isEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list2.isEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("list2.isEmpty()"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 280); do
{ } while (false); do { MOZ_CrashSequence(__null, 280); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
281
282 list3.clear();
283}
284
285static void TestRemoveAndGet() {
286 LinkedList<SomeClass> list;
287
288 SomeClass one(1), two(2), three(3);
289 list.insertBack(&one);
290 list.insertBack(&two);
291 list.insertBack(&three);
292 {
293 unsigned int check[]{1, 2, 3};
294 CheckListValues(list, check);
295 }
296
297 MOZ_RELEASE_ASSERT(two.removeAndGetNext() == &three)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(two.removeAndGetNext() == &three)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(two.removeAndGetNext() == &
three))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("two.removeAndGetNext() == &three", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 297); do { } while (false); do { MOZ_CrashSequence(__null, 297
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
298 {
299 unsigned int check[]{1, 3};
300 CheckListValues(list, check);
301 }
302
303 MOZ_RELEASE_ASSERT(three.removeAndGetPrevious() == &one)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(three.removeAndGetPrevious() == &one)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(three.removeAndGetPrevious() == &one))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("three.removeAndGetPrevious() == &one"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 303); do
{ } while (false); do { MOZ_CrashSequence(__null, 303); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
304 {
305 unsigned int check[]{1};
306 CheckListValues(list, check);
307 }
308}
309
310struct PrivateClass : private LinkedListElement<PrivateClass> {
311 friend class mozilla::LinkedList<PrivateClass>;
312 friend class mozilla::LinkedListElement<PrivateClass>;
313};
314
315static void TestPrivate() {
316 LinkedList<PrivateClass> list;
317 PrivateClass one, two;
318 list.insertBack(&one);
319 list.insertBack(&two);
320
321 size_t count = 0;
322 for (PrivateClass* p : list) {
323 MOZ_RELEASE_ASSERT(p, "cannot have null elements in list")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(p)>::isValid, "invalid assertion condition"); if (
(__builtin_expect(!!(!(!!(p))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("p" " (" "cannot have null elements in list" ")", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 323); do { } while (false); do { MOZ_CrashSequence(__null, 323
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
324 count++;
325 }
326 MOZ_RELEASE_ASSERT(count == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(count == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(count == 2))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("count == 2", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 326); do { } while (false); do { MOZ_CrashSequence(__null, 326
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
327}
328
329struct CountedClass : public LinkedListElement<RefPtr<CountedClass>> {
330 int mCount;
331 void AddRef() { mCount++; }
332 void Release() { mCount--; }
333
334 CountedClass() : mCount(0) {}
335 ~CountedClass() { MOZ_RELEASE_ASSERT(mCount == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCount == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCount == 0))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("mCount == 0", "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp"
, 335); do { } while (false); do { MOZ_CrashSequence(__null, 335
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
; }
336};
337
338static void TestRefPtrList() {
339 LinkedList<RefPtr<CountedClass>> list;
340 CountedClass* elt1 = new CountedClass;
341 CountedClass* elt2 = new CountedClass;
342
343 list.insertBack(elt1);
344 list.insertBack(elt2);
345
346 MOZ_RELEASE_ASSERT(elt1->mCount == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt1->mCount == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt1->mCount == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt1->mCount == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 346); do
{ } while (false); do { MOZ_CrashSequence(__null, 346); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
347 MOZ_RELEASE_ASSERT(elt2->mCount == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt2->mCount == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt2->mCount == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt2->mCount == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 347); do
{ } while (false); do { MOZ_CrashSequence(__null, 347); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
348
349 for (RefPtr<CountedClass> p : list) {
350 MOZ_RELEASE_ASSERT(p->mCount == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(p->mCount == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(p->mCount == 2))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("p->mCount == 2"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 350); do
{ } while (false); do { MOZ_CrashSequence(__null, 350); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
351 }
352
353 RefPtr<CountedClass> ptr = list.getFirst();
354 while (ptr) {
355 MOZ_RELEASE_ASSERT(ptr->mCount == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(ptr->mCount == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(ptr->mCount == 2))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("ptr->mCount == 2"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 355); do
{ } while (false); do { MOZ_CrashSequence(__null, 355); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
356 RefPtr<CountedClass> next = ptr->getNext();
357 ptr->remove();
358 ptr = std::move(next);
359 }
360 ptr = nullptr;
361
362 MOZ_RELEASE_ASSERT(elt1->mCount == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt1->mCount == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt1->mCount == 0))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt1->mCount == 0"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 362); do
{ } while (false); do { MOZ_CrashSequence(__null, 362); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
363 MOZ_RELEASE_ASSERT(elt2->mCount == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt2->mCount == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt2->mCount == 0))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt2->mCount == 0"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 363); do
{ } while (false); do { MOZ_CrashSequence(__null, 363); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
364
365 list.insertBack(elt1);
366 elt1->setNext(elt2);
367
368 MOZ_RELEASE_ASSERT(elt1->mCount == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt1->mCount == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt1->mCount == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt1->mCount == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 368); do
{ } while (false); do { MOZ_CrashSequence(__null, 368); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
369 MOZ_RELEASE_ASSERT(elt2->mCount == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt2->mCount == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt2->mCount == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt2->mCount == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 369); do
{ } while (false); do { MOZ_CrashSequence(__null, 369); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
370
371 RefPtr<CountedClass> first = list.popFirst();
372
373 MOZ_RELEASE_ASSERT(elt1->mCount == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt1->mCount == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt1->mCount == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt1->mCount == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 373); do
{ } while (false); do { MOZ_CrashSequence(__null, 373); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
374 MOZ_RELEASE_ASSERT(elt2->mCount == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt2->mCount == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt2->mCount == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt2->mCount == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 374); do
{ } while (false); do { MOZ_CrashSequence(__null, 374); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
375
376 RefPtr<CountedClass> second = list.popFirst();
377
378 MOZ_RELEASE_ASSERT(elt1->mCount == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt1->mCount == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt1->mCount == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt1->mCount == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 378); do
{ } while (false); do { MOZ_CrashSequence(__null, 378); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
379 MOZ_RELEASE_ASSERT(elt2->mCount == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt2->mCount == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt2->mCount == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt2->mCount == 1"
, "/root/firefox-clang/mfbt/tests/TestLinkedList.cpp", 379); do
{ } while (false); do { MOZ_CrashSequence(__null, 379); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
380
381 first = second = nullptr;
382
383 delete elt1;
384 delete elt2;
385}
386
387int main() {
388 TestList();
389 TestExtendLists();
390 TestSplice();
391 TestPrivate();
392 TestMove();
1
Calling 'TestMove'
393 TestRemoveAndGet();
394 TestRefPtrList();
395 return 0;
396}