Bug Summary

File:root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp
Warning:line 24, column 5
The right operand of '==' is a garbage value due to array index out of bounds

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 TestDoublyLinkedList.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/TestDoublyLinkedList.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/DoublyLinkedList.h"
7
8using mozilla::DoublyLinkedList;
9using mozilla::DoublyLinkedListElement;
10
11struct SomeClass : public DoublyLinkedListElement<SomeClass> {
12 unsigned int mValue;
13 explicit SomeClass(int aValue) : mValue(aValue) {}
14 void incr() { ++mValue; }
15 bool operator==(const SomeClass& other) const {
16 return mValue == other.mValue;
17 }
18};
19
20template <typename ListType, size_t N>
21static void CheckListValues(ListType& list, unsigned int (&values)[N]) {
22 size_t count = 0;
23 for (auto& x : list) {
3
Assuming the condition is false
8
Assuming the condition is false
24 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/TestDoublyLinkedList.cpp", 24
); do { } while (false); do { MOZ_CrashSequence(__null, 24); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
4
Assuming the condition is true
5
Taking false branch
6
Loop condition is false. Exiting loop
9
The right operand of '==' is a garbage value due to array index out of bounds
25 ++count;
7
The value 1 is assigned to 'count'
26 }
27 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/TestDoublyLinkedList.cpp"
, 27); do { } while (false); do { MOZ_CrashSequence(__null, 27
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
28}
29
30static void TestDoublyLinkedList() {
31 DoublyLinkedList<SomeClass> list;
32
33 SomeClass one(1), two(2), three(3);
34
35 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/TestDoublyLinkedList.cpp", 35
); do { } while (false); do { MOZ_CrashSequence(__null, 35); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
36 MOZ_RELEASE_ASSERT(!list.isSingle())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.isSingle())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.isSingle()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.isSingle()"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 36
); do { } while (false); do { MOZ_CrashSequence(__null, 36); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
37 MOZ_RELEASE_ASSERT(!list.begin())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.begin())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.begin()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!list.begin()",
"/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 37
); do { } while (false); do { MOZ_CrashSequence(__null, 37); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
38 MOZ_RELEASE_ASSERT(!list.end())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.end())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.end()))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!list.end()", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 38); do { } while (false); do { MOZ_CrashSequence(__null, 38
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
39
40 for (SomeClass& x : list) {
41 MOZ_RELEASE_ASSERT(x.mValue)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(x.mValue)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(x.mValue))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("x.mValue", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 41); do { } while (false); do { MOZ_CrashSequence(__null, 41
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
42 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/TestDoublyLinkedList.cpp"
, 42); do { } while (false); do { MOZ_CrashSequence(__null, 42
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
43 }
44
45 list.pushFront(&one);
46 {
47 unsigned int check[]{1};
48 CheckListValues(list, check);
49 }
50
51 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/TestDoublyLinkedList.cpp", 51
); do { } while (false); do { MOZ_CrashSequence(__null, 51); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
52 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/TestDoublyLinkedList.cpp", 52
); do { } while (false); do { MOZ_CrashSequence(__null, 52); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
53 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/TestDoublyLinkedList.cpp", 53
); do { } while (false); do { MOZ_CrashSequence(__null, 53); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
54
55 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/TestDoublyLinkedList.cpp", 55
); do { } while (false); do { MOZ_CrashSequence(__null, 55); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
56 MOZ_RELEASE_ASSERT(list.isSingle())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.isSingle())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.isSingle()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("list.isSingle()"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 56
); do { } while (false); do { MOZ_CrashSequence(__null, 56); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
57 MOZ_RELEASE_ASSERT(list.begin()->mValue == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.begin()->mValue == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.begin()->mValue == 1
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"list.begin()->mValue == 1", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 57); do { } while (false); do { MOZ_CrashSequence(__null, 57
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
58 MOZ_RELEASE_ASSERT(!list.end())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.end())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.end()))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!list.end()", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 58); do { } while (false); do { MOZ_CrashSequence(__null, 58
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
59
60 list.pushFront(&two);
61 {
62 unsigned int check[]{2, 1};
63 CheckListValues(list, check);
64 }
65
66 MOZ_RELEASE_ASSERT(!list.isSingle())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.isSingle())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.isSingle()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.isSingle()"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 66
); do { } while (false); do { MOZ_CrashSequence(__null, 66); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
67 MOZ_RELEASE_ASSERT(list.begin()->mValue == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.begin()->mValue == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.begin()->mValue == 2
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"list.begin()->mValue == 2", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 67); do { } while (false); do { MOZ_CrashSequence(__null, 67
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
68 MOZ_RELEASE_ASSERT(!list.end())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.end())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.end()))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!list.end()", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 68); do { } while (false); do { MOZ_CrashSequence(__null, 68
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
69 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/TestDoublyLinkedList.cpp", 69
); do { } while (false); do { MOZ_CrashSequence(__null, 69); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
70
71 list.pushBack(&three);
72 {
73 unsigned int check[]{2, 1, 3};
74 CheckListValues(list, check);
75 }
76
77 MOZ_RELEASE_ASSERT(!list.isSingle())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.isSingle())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.isSingle()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.isSingle()"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 77
); do { } while (false); do { MOZ_CrashSequence(__null, 77); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
78 MOZ_RELEASE_ASSERT(list.begin()->mValue == 2)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.begin()->mValue == 2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.begin()->mValue == 2
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"list.begin()->mValue == 2", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 78); do { } while (false); do { MOZ_CrashSequence(__null, 78
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
79 MOZ_RELEASE_ASSERT(!list.end())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.end())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.end()))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!list.end()", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 79); do { } while (false); do { MOZ_CrashSequence(__null, 79
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
80
81 list.remove(&one);
82 {
83 unsigned int check[]{2, 3};
84 CheckListValues(list, check);
85 }
86
87 list.insertBefore(list.find(three), &one);
88 {
89 unsigned int check[]{2, 1, 3};
90 CheckListValues(list, check);
91 }
92
93 list.remove(&three);
94 {
95 unsigned int check[]{2, 1};
96 CheckListValues(list, check);
97 }
98
99 list.insertBefore(list.find(two), &three);
100 {
101 unsigned int check[]{3, 2, 1};
102 CheckListValues(list, check);
103 }
104
105 list.remove(&three);
106 {
107 unsigned int check[]{2, 1};
108 CheckListValues(list, check);
109 }
110
111 list.insertBefore(++list.find(two), &three);
112 {
113 unsigned int check[]{2, 3, 1};
114 CheckListValues(list, check);
115 }
116
117 list.remove(&one);
118 {
119 unsigned int check[]{2, 3};
120 CheckListValues(list, check);
121 }
122
123 list.remove(&two);
124 {
125 unsigned int check[]{3};
126 CheckListValues(list, check);
127 }
128
129 list.insertBefore(list.find(three), &two);
130 {
131 unsigned int check[]{2, 3};
132 CheckListValues(list, check);
133 }
134
135 list.remove(&three);
136 {
137 unsigned int check[]{2};
138 CheckListValues(list, check);
139 }
140
141 MOZ_RELEASE_ASSERT(list.isSingle())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.isSingle())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.isSingle()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("list.isSingle()"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 141
); do { } while (false); do { MOZ_CrashSequence(__null, 141);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
142 list.remove(&two);
143 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/TestDoublyLinkedList.cpp", 143
); do { } while (false); do { MOZ_CrashSequence(__null, 143);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
144 MOZ_RELEASE_ASSERT(!list.isSingle())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.isSingle())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.isSingle()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.isSingle()"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 144
); do { } while (false); do { MOZ_CrashSequence(__null, 144);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
145
146 list.pushBack(&three);
147 {
148 unsigned int check[]{3};
149 CheckListValues(list, check);
150 }
151 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/TestDoublyLinkedList.cpp", 151
); do { } while (false); do { MOZ_CrashSequence(__null, 151);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
152 MOZ_RELEASE_ASSERT(list.isSingle())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(list.isSingle())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(list.isSingle()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("list.isSingle()"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 152
); do { } while (false); do { MOZ_CrashSequence(__null, 152);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
153
154 list.pushFront(&two);
155 {
156 unsigned int check[]{2, 3};
157 CheckListValues(list, check);
158 }
159
160 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/TestDoublyLinkedList.cpp", 160
); do { } while (false); do { MOZ_CrashSequence(__null, 160);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
161 MOZ_RELEASE_ASSERT(!list.isSingle())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!list.isSingle())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!list.isSingle()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!list.isSingle()"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 161
); do { } while (false); do { MOZ_CrashSequence(__null, 161);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
162 // This should modify the values of |two| and |three| as pointers to them are
163 // stored in the list, not copies.
164 for (SomeClass& x : list) {
165 x.incr();
166 }
167
168 MOZ_RELEASE_ASSERT(*list.begin() == two)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(*list.begin() == two)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(*list.begin() == two))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("*list.begin() == two"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 168
); do { } while (false); do { MOZ_CrashSequence(__null, 168);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
169 MOZ_RELEASE_ASSERT(*++list.begin() == three)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(*++list.begin() == three)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(*++list.begin() == three))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("*++list.begin() == three"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 169
); do { } while (false); do { MOZ_CrashSequence(__null, 169);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
170
171 SomeClass four(4);
172 MOZ_RELEASE_ASSERT(++list.begin() == list.find(four))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(++list.begin() == list.find(four))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(++list.begin() == list.find(
four)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("++list.begin() == list.find(four)", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 172); do { } while (false); do { MOZ_CrashSequence(__null, 172
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
173}
174
175struct InTwoLists {
176 explicit InTwoLists(unsigned int aValue) : mValue(aValue) {}
177 DoublyLinkedListElement<InTwoLists> mListOne;
178 DoublyLinkedListElement<InTwoLists> mListTwo;
179 unsigned int mValue;
180
181 struct GetListOneTrait {
182 static DoublyLinkedListElement<InTwoLists>& Get(InTwoLists* aThis) {
183 return aThis->mListOne;
184 }
185 static const DoublyLinkedListElement<InTwoLists>& Get(
186 const InTwoLists* aThis) {
187 return aThis->mListOne;
188 }
189 };
190};
191
192namespace mozilla {
193
194template <>
195struct GetDoublyLinkedListElement<InTwoLists> {
196 static DoublyLinkedListElement<InTwoLists>& Get(InTwoLists* aThis) {
197 return aThis->mListTwo;
198 }
199 static const DoublyLinkedListElement<InTwoLists>& Get(
200 const InTwoLists* aThis) {
201 return aThis->mListTwo;
202 }
203};
204
205} // namespace mozilla
206
207static void TestCustomAccessor() {
208 DoublyLinkedList<InTwoLists, InTwoLists::GetListOneTrait> listOne;
209 DoublyLinkedList<InTwoLists> listTwo;
210
211 InTwoLists one(1);
212 InTwoLists two(2);
213
214 listOne.pushBack(&one);
215 listOne.pushBack(&two);
216 {
217 unsigned int check[]{1, 2};
218 CheckListValues(listOne, check);
219 }
220
221 listTwo.pushBack(&one);
222 listTwo.pushBack(&two);
223 {
224 unsigned int check[]{1, 2};
225 CheckListValues(listOne, check);
226 }
227 {
228 unsigned int check[]{1, 2};
229 CheckListValues(listTwo, check);
230 }
231
232 (void)listTwo.popBack();
233 {
234 unsigned int check[]{1, 2};
235 CheckListValues(listOne, check);
236 }
237 {
238 unsigned int check[]{1};
239 CheckListValues(listTwo, check);
2
Calling 'CheckListValues<mozilla::DoublyLinkedList<InTwoLists>, 1UL>'
240 }
241
242 (void)listOne.popBack();
243 {
244 unsigned int check[]{1};
245 CheckListValues(listOne, check);
246 }
247 {
248 unsigned int check[]{1};
249 CheckListValues(listTwo, check);
250 }
251}
252
253static void TestSafeDoubleLinkedList() {
254 mozilla::SafeDoublyLinkedList<SomeClass> list;
255 auto* elt1 = new SomeClass(0);
256 auto* elt2 = new SomeClass(0);
257 auto* elt3 = new SomeClass(0);
258 auto* elt4 = new SomeClass(0);
259 list.pushBack(elt1);
260 list.pushBack(elt2);
261 list.pushBack(elt3);
262 auto iter = list.begin();
263
264 // basic tests for iterator validity
265 MOZ_RELEASE_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*iter == elt1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*iter == elt1))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("&*iter == elt1"
" (" "iterator returned by begin() must point to the first element!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 267); do { } while (false); do { MOZ_CrashSequence(__null, 267
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
266 &*iter == elt1,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*iter == elt1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*iter == elt1))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("&*iter == elt1"
" (" "iterator returned by begin() must point to the first element!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 267); do { } while (false); do { MOZ_CrashSequence(__null, 267
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
267 "iterator returned by begin() must point to the first element!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*iter == elt1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*iter == elt1))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("&*iter == elt1"
" (" "iterator returned by begin() must point to the first element!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 267); do { } while (false); do { MOZ_CrashSequence(__null, 267
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
268 MOZ_RELEASE_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt2)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt2"
" (" "iterator returned by begin() must have the second element as 'next'!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 270); do { } while (false); do { MOZ_CrashSequence(__null, 270
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
269 &*(iter.next()) == elt2,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt2)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt2"
" (" "iterator returned by begin() must have the second element as 'next'!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 270); do { } while (false); do { MOZ_CrashSequence(__null, 270
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
270 "iterator returned by begin() must have the second element as 'next'!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt2)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt2)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt2"
" (" "iterator returned by begin() must have the second element as 'next'!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 270); do { } while (false); do { MOZ_CrashSequence(__null, 270
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
271 list.remove(elt2);
272 MOZ_RELEASE_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt3)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt3"
" (" "After removal of the 2nd element 'next' must point to the 3rd element!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 274); do { } while (false); do { MOZ_CrashSequence(__null, 274
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
273 &*(iter.next()) == elt3,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt3)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt3"
" (" "After removal of the 2nd element 'next' must point to the 3rd element!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 274); do { } while (false); do { MOZ_CrashSequence(__null, 274
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
274 "After removal of the 2nd element 'next' must point to the 3rd element!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt3)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt3"
" (" "After removal of the 2nd element 'next' must point to the 3rd element!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 274); do { } while (false); do { MOZ_CrashSequence(__null, 274
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
275 ++iter;
276 MOZ_RELEASE_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*iter == elt3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*iter == elt3))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("&*iter == elt3"
" (" "After advancing one step the current element must be the 3rd one!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 278); do { } while (false); do { MOZ_CrashSequence(__null, 278
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
277 &*iter == elt3,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*iter == elt3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*iter == elt3))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("&*iter == elt3"
" (" "After advancing one step the current element must be the 3rd one!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 278); do { } while (false); do { MOZ_CrashSequence(__null, 278
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
278 "After advancing one step the current element must be the 3rd one!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*iter == elt3)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*iter == elt3))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("&*iter == elt3"
" (" "After advancing one step the current element must be the 3rd one!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 278); do { } while (false); do { MOZ_CrashSequence(__null, 278
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
279 MOZ_RELEASE_ASSERT(!iter.next(), "This is the last element of the list!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!iter.next())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!iter.next()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!iter.next()" " ("
"This is the last element of the list!" ")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 279); do { } while (false); do { MOZ_CrashSequence(__null, 279
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
280 list.pushBack(elt4);
281 MOZ_RELEASE_ASSERT(&*(iter.next()) == elt4,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt4)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt4)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt4"
" (" "After adding an element at the end of the list the " "iterator must be updated!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 283); do { } while (false); do { MOZ_CrashSequence(__null, 283
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
282 "After adding an element at the end of the list the "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt4)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt4)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt4"
" (" "After adding an element at the end of the list the " "iterator must be updated!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 283); do { } while (false); do { MOZ_CrashSequence(__null, 283
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
283 "iterator must be updated!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(&*(iter.next()) == elt4)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(&*(iter.next()) == elt4)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&*(iter.next()) == elt4"
" (" "After adding an element at the end of the list the " "iterator must be updated!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 283); do { } while (false); do { MOZ_CrashSequence(__null, 283
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
284
285 // advance to last element, then remove last element
286 ++iter;
287 list.popBack();
288 MOZ_RELEASE_ASSERT(bool(iter) == false,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(bool(iter) == false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(bool(iter) == false))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("bool(iter) == false"
" (" "After removing the last element, the iterator pointing "
"to the last element must be empty!" ")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 290); do { } while (false); do { MOZ_CrashSequence(__null, 290
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
289 "After removing the last element, the iterator pointing "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(bool(iter) == false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(bool(iter) == false))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("bool(iter) == false"
" (" "After removing the last element, the iterator pointing "
"to the last element must be empty!" ")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 290); do { } while (false); do { MOZ_CrashSequence(__null, 290
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
290 "to the last element must be empty!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(bool(iter) == false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(bool(iter) == false))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("bool(iter) == false"
" (" "After removing the last element, the iterator pointing "
"to the last element must be empty!" ")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 290); do { } while (false); do { MOZ_CrashSequence(__null, 290
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
291
292 // iterate the whole remaining list, increment values
293 for (auto& el : list) {
294 el.incr();
295 }
296 MOZ_RELEASE_ASSERT(elt1->mValue == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt1->mValue == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt1->mValue == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt1->mValue == 1"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 296
); do { } while (false); do { MOZ_CrashSequence(__null, 296);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
297 MOZ_RELEASE_ASSERT(elt2->mValue == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt2->mValue == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt2->mValue == 0))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt2->mValue == 0"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 297
); do { } while (false); do { MOZ_CrashSequence(__null, 297);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
298 MOZ_RELEASE_ASSERT(elt3->mValue == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt3->mValue == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt3->mValue == 1))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt3->mValue == 1"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 298
); do { } while (false); do { MOZ_CrashSequence(__null, 298);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
299 MOZ_RELEASE_ASSERT(elt4->mValue == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(elt4->mValue == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(elt4->mValue == 0))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("elt4->mValue == 0"
, "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp", 299
); do { } while (false); do { MOZ_CrashSequence(__null, 299);
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
300
301 // Removing the first element of the list while iterating must empty the
302 // iterator
303 for (auto it = list.begin(); it != list.end(); ++it) {
304 MOZ_RELEASE_ASSERT(bool(it) == true, "The iterator must contain a value!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(bool(it) == true)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(bool(it) == true))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("bool(it) == true"
" (" "The iterator must contain a value!" ")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 304); do { } while (false); do { MOZ_CrashSequence(__null, 304
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
305 list.popFront();
306 MOZ_RELEASE_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(bool(it) == false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(bool(it) == false))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("bool(it) == false"
" (" "After removing the first element, the iterator must be empty!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 308); do { } while (false); do { MOZ_CrashSequence(__null, 308
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
307 bool(it) == false,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(bool(it) == false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(bool(it) == false))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("bool(it) == false"
" (" "After removing the first element, the iterator must be empty!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 308); do { } while (false); do { MOZ_CrashSequence(__null, 308
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
308 "After removing the first element, the iterator must be empty!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(bool(it) == false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(bool(it) == false))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("bool(it) == false"
" (" "After removing the first element, the iterator must be empty!"
")", "/root/firefox-clang/mfbt/tests/TestDoublyLinkedList.cpp"
, 308); do { } while (false); do { MOZ_CrashSequence(__null, 308
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
309 }
310
311 delete elt1;
312 delete elt2;
313 delete elt3;
314 delete elt4;
315}
316
317int main() {
318 TestDoublyLinkedList();
319 TestCustomAccessor();
1
Calling 'TestCustomAccessor'
320 TestSafeDoubleLinkedList();
321 return 0;
322}