clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name FoldingSet.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libLLVM/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Analysis -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ASMParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/BinaryFormat -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitstream -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /include/llvm/CodeGen -I /include/llvm/CodeGen/PBQP -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Coroutines -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData/Coverage -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/CodeView -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/DWARF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/MSF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/PDB -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Demangle -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/JITLink -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/Orc -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenACC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenMP -I /include/llvm/CodeGen/GlobalISel -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IRReader -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/LTO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Linker -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC/MCParser -I /include/llvm/CodeGen/MIRParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Object -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Option -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Passes -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Scalar -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ADT -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Support -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/Symbolize -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Target -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Utils -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Vectorize -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/IPO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libLLVM/../include -I /usr/src/gnu/usr.bin/clang/libLLVM/obj -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libLLVM/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Support/FoldingSet.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #include "llvm/ADT/FoldingSet.h" |
| 15 | #include "llvm/ADT/Hashing.h" |
| 16 | #include "llvm/ADT/StringRef.h" |
| 17 | #include "llvm/Support/Allocator.h" |
| 18 | #include "llvm/Support/ErrorHandling.h" |
| 19 | #include "llvm/Support/Host.h" |
| 20 | #include "llvm/Support/MathExtras.h" |
| 21 | #include <cassert> |
| 22 | #include <cstring> |
| 23 | using namespace llvm; |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | unsigned FoldingSetNodeIDRef::ComputeHash() const { |
| 31 | return static_cast<unsigned>(hash_combine_range(Data, Data+Size)); |
| 32 | } |
| 33 | |
| 34 | bool FoldingSetNodeIDRef::operator==(FoldingSetNodeIDRef RHS) const { |
| 35 | if (Size != RHS.Size) return false; |
| 36 | return memcmp(Data, RHS.Data, Size*sizeof(*Data)) == 0; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | |
| 41 | bool FoldingSetNodeIDRef::operator<(FoldingSetNodeIDRef RHS) const { |
| 42 | if (Size != RHS.Size) |
| 43 | return Size < RHS.Size; |
| 44 | return memcmp(Data, RHS.Data, Size*sizeof(*Data)) < 0; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | void FoldingSetNodeID::AddPointer(const void *Ptr) { |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | static_assert(sizeof(uintptr_t) <= sizeof(unsigned long long), |
| 58 | "unexpected pointer size"); |
| 59 | AddInteger(reinterpret_cast<uintptr_t>(Ptr)); |
| 60 | } |
| 61 | void FoldingSetNodeID::AddInteger(signed I) { |
| 62 | Bits.push_back(I); |
| 63 | } |
| 64 | void FoldingSetNodeID::AddInteger(unsigned I) { |
| 65 | Bits.push_back(I); |
| 66 | } |
| 67 | void FoldingSetNodeID::AddInteger(long I) { |
| 68 | AddInteger((unsigned long)I); |
| 69 | } |
| 70 | void FoldingSetNodeID::AddInteger(unsigned long I) { |
| 71 | if (sizeof(long) == sizeof(int)) |
| 72 | AddInteger(unsigned(I)); |
| 73 | else if (sizeof(long) == sizeof(long long)) { |
| 74 | AddInteger((unsigned long long)I); |
| 75 | } else { |
| 76 | llvm_unreachable("unexpected sizeof(long)"); |
| 77 | } |
| 78 | } |
| 79 | void FoldingSetNodeID::AddInteger(long long I) { |
| 80 | AddInteger((unsigned long long)I); |
| 81 | } |
| 82 | void FoldingSetNodeID::AddInteger(unsigned long long I) { |
| 83 | AddInteger(unsigned(I)); |
| 84 | AddInteger(unsigned(I >> 32)); |
| 85 | } |
| 86 | |
| 87 | void FoldingSetNodeID::AddString(StringRef String) { |
| 88 | unsigned Size = String.size(); |
| 89 | |
| 90 | unsigned NumInserts = 1 + divideCeil(Size, 4); |
| 91 | Bits.reserve(Bits.size() + NumInserts); |
| 92 | |
| 93 | Bits.push_back(Size); |
| 94 | if (!Size) return; |
| 95 | |
| 96 | unsigned Units = Size / 4; |
| 97 | unsigned Pos = 0; |
| 98 | const unsigned *Base = (const unsigned*) String.data(); |
| 99 | |
| 100 | |
| 101 | if (!((intptr_t)Base & 3)) { |
| 102 | Bits.append(Base, Base + Units); |
| 103 | Pos = (Units + 1) * 4; |
| 104 | } else { |
| 105 | |
| 106 | |
| 107 | |
| 108 | static_assert(sys::IsBigEndianHost || sys::IsLittleEndianHost, |
| 109 | "Unexpected host endianness"); |
| 110 | if (sys::IsBigEndianHost) { |
| 111 | for (Pos += 4; Pos <= Size; Pos += 4) { |
| 112 | unsigned V = ((unsigned char)String[Pos - 4] << 24) | |
| 113 | ((unsigned char)String[Pos - 3] << 16) | |
| 114 | ((unsigned char)String[Pos - 2] << 8) | |
| 115 | (unsigned char)String[Pos - 1]; |
| 116 | Bits.push_back(V); |
| 117 | } |
| 118 | } else { |
| 119 | for (Pos += 4; Pos <= Size; Pos += 4) { |
| 120 | unsigned V = ((unsigned char)String[Pos - 1] << 24) | |
| 121 | ((unsigned char)String[Pos - 2] << 16) | |
| 122 | ((unsigned char)String[Pos - 3] << 8) | |
| 123 | (unsigned char)String[Pos - 4]; |
| 124 | Bits.push_back(V); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | |
| 130 | unsigned V = 0; |
| 131 | |
| 132 | |
| 133 | switch (Pos - Size) { |
| 134 | case 1: V = (V << 8) | (unsigned char)String[Size - 3]; LLVM_FALLTHROUGH; |
| 135 | case 2: V = (V << 8) | (unsigned char)String[Size - 2]; LLVM_FALLTHROUGH; |
| 136 | case 3: V = (V << 8) | (unsigned char)String[Size - 1]; break; |
| 137 | default: return; |
| 138 | } |
| 139 | |
| 140 | Bits.push_back(V); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | void FoldingSetNodeID::AddNodeID(const FoldingSetNodeID &ID) { |
| 145 | Bits.append(ID.Bits.begin(), ID.Bits.end()); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | |
| 150 | unsigned FoldingSetNodeID::ComputeHash() const { |
| 151 | return FoldingSetNodeIDRef(Bits.data(), Bits.size()).ComputeHash(); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | |
| 156 | bool FoldingSetNodeID::operator==(const FoldingSetNodeID &RHS) const { |
| 157 | return *this == FoldingSetNodeIDRef(RHS.Bits.data(), RHS.Bits.size()); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | |
| 162 | bool FoldingSetNodeID::operator==(FoldingSetNodeIDRef RHS) const { |
| 163 | return FoldingSetNodeIDRef(Bits.data(), Bits.size()) == RHS; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | |
| 168 | bool FoldingSetNodeID::operator<(const FoldingSetNodeID &RHS) const { |
| 169 | return *this < FoldingSetNodeIDRef(RHS.Bits.data(), RHS.Bits.size()); |
| 170 | } |
| 171 | |
| 172 | bool FoldingSetNodeID::operator<(FoldingSetNodeIDRef RHS) const { |
| 173 | return FoldingSetNodeIDRef(Bits.data(), Bits.size()) < RHS; |
| 174 | } |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | FoldingSetNodeIDRef |
| 180 | FoldingSetNodeID::Intern(BumpPtrAllocator &Allocator) const { |
| 181 | unsigned *New = Allocator.Allocate<unsigned>(Bits.size()); |
| 182 | std::uninitialized_copy(Bits.begin(), Bits.end(), New); |
| 183 | return FoldingSetNodeIDRef(New, Bits.size()); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | static FoldingSetBase::Node *GetNextPtr(void *NextInBucketPtr) { |
| 196 | |
| 197 | if (reinterpret_cast<intptr_t>(NextInBucketPtr) & 1) |
| 2 | | Assuming the condition is false | |
|
| |
| 198 | return nullptr; |
| 199 | |
| 200 | return static_cast<FoldingSetBase::Node*>(NextInBucketPtr); |
| 4 | | Returning pointer (loaded from 'NextInBucketPtr'), which participates in a condition later | |
|
| 201 | } |
| 202 | |
| 203 | |
| 204 | |
| 205 | static void **GetBucketPtr(void *NextInBucketPtr) { |
| 206 | intptr_t Ptr = reinterpret_cast<intptr_t>(NextInBucketPtr); |
| 207 | assert((Ptr & 1) && "Not a bucket pointer"); |
| 208 | return reinterpret_cast<void**>(Ptr & ~intptr_t(1)); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | |
| 213 | static void **GetBucketFor(unsigned Hash, void **Buckets, unsigned NumBuckets) { |
| 214 | |
| 215 | unsigned BucketNum = Hash & (NumBuckets-1); |
| 216 | return Buckets + BucketNum; |
| 217 | } |
| 218 | |
| 219 | |
| 220 | static void **AllocateBuckets(unsigned NumBuckets) { |
| 221 | void **Buckets = static_cast<void**>(safe_calloc(NumBuckets + 1, |
| 222 | sizeof(void*))); |
| 223 | |
| 224 | Buckets[NumBuckets] = reinterpret_cast<void*>(-1); |
| 225 | return Buckets; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | FoldingSetBase::FoldingSetBase(unsigned Log2InitSize) { |
| 232 | assert(5 < Log2InitSize && Log2InitSize < 32 && |
| 233 | "Initial hash table size out of range"); |
| 234 | NumBuckets = 1 << Log2InitSize; |
| 235 | Buckets = AllocateBuckets(NumBuckets); |
| 236 | NumNodes = 0; |
| 237 | } |
| 238 | |
| 239 | FoldingSetBase::FoldingSetBase(FoldingSetBase &&Arg) |
| 240 | : Buckets(Arg.Buckets), NumBuckets(Arg.NumBuckets), NumNodes(Arg.NumNodes) { |
| 241 | Arg.Buckets = nullptr; |
| 242 | Arg.NumBuckets = 0; |
| 243 | Arg.NumNodes = 0; |
| 244 | } |
| 245 | |
| 246 | FoldingSetBase &FoldingSetBase::operator=(FoldingSetBase &&RHS) { |
| 247 | free(Buckets); |
| 248 | Buckets = RHS.Buckets; |
| 249 | NumBuckets = RHS.NumBuckets; |
| 250 | NumNodes = RHS.NumNodes; |
| 251 | RHS.Buckets = nullptr; |
| 252 | RHS.NumBuckets = 0; |
| 253 | RHS.NumNodes = 0; |
| 254 | return *this; |
| 255 | } |
| 256 | |
| 257 | FoldingSetBase::~FoldingSetBase() { |
| 258 | free(Buckets); |
| 259 | } |
| 260 | |
| 261 | void FoldingSetBase::clear() { |
| 262 | |
| 263 | memset(Buckets, 0, NumBuckets*sizeof(void*)); |
| 264 | |
| 265 | |
| 266 | Buckets[NumBuckets] = reinterpret_cast<void*>(-1); |
| 267 | |
| 268 | |
| 269 | NumNodes = 0; |
| 270 | } |
| 271 | |
| 272 | void FoldingSetBase::GrowBucketCount(unsigned NewBucketCount, |
| 273 | const FoldingSetInfo &Info) { |
| 274 | assert((NewBucketCount > NumBuckets) && |
| 275 | "Can't shrink a folding set with GrowBucketCount"); |
| 276 | assert(isPowerOf2_32(NewBucketCount) && "Bad bucket count!"); |
| 277 | void **OldBuckets = Buckets; |
| 278 | unsigned OldNumBuckets = NumBuckets; |
| 279 | |
| 280 | |
| 281 | Buckets = AllocateBuckets(NewBucketCount); |
| 282 | |
| 283 | NumBuckets = NewBucketCount; |
| 284 | NumNodes = 0; |
| 285 | |
| 286 | |
| 287 | FoldingSetNodeID TempID; |
| 288 | for (unsigned i = 0; i != OldNumBuckets; ++i) { |
| 289 | void *Probe = OldBuckets[i]; |
| 290 | if (!Probe) continue; |
| 291 | while (Node *NodeInBucket = GetNextPtr(Probe)) { |
| 292 | |
| 293 | Probe = NodeInBucket->getNextInBucket(); |
| 294 | NodeInBucket->SetNextInBucket(nullptr); |
| 295 | |
| 296 | |
| 297 | InsertNode(NodeInBucket, |
| 298 | GetBucketFor(Info.ComputeNodeHash(this, NodeInBucket, TempID), |
| 299 | Buckets, NumBuckets), |
| 300 | Info); |
| 301 | TempID.clear(); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | free(OldBuckets); |
| 306 | } |
| 307 | |
| 308 | |
| 309 | |
| 310 | void FoldingSetBase::GrowHashTable(const FoldingSetInfo &Info) { |
| 311 | GrowBucketCount(NumBuckets * 2, Info); |
| 312 | } |
| 313 | |
| 314 | void FoldingSetBase::reserve(unsigned EltCount, const FoldingSetInfo &Info) { |
| 315 | |
| 316 | |
| 317 | |
| 318 | if(EltCount < capacity()) |
| 319 | return; |
| 320 | GrowBucketCount(PowerOf2Floor(EltCount), Info); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | FoldingSetBase::Node *FoldingSetBase::FindNodeOrInsertPos( |
| 327 | const FoldingSetNodeID &ID, void *&InsertPos, const FoldingSetInfo &Info) { |
| 328 | unsigned IDHash = ID.ComputeHash(); |
| 329 | void **Bucket = GetBucketFor(IDHash, Buckets, NumBuckets); |
| 330 | void *Probe = *Bucket; |
| 331 | |
| 332 | InsertPos = nullptr; |
| 333 | |
| 334 | FoldingSetNodeID TempID; |
| 335 | while (Node *NodeInBucket = GetNextPtr(Probe)) { |
| 336 | if (Info.NodeEquals(this, NodeInBucket, ID, IDHash, TempID)) |
| 337 | return NodeInBucket; |
| 338 | TempID.clear(); |
| 339 | |
| 340 | Probe = NodeInBucket->getNextInBucket(); |
| 341 | } |
| 342 | |
| 343 | |
| 344 | InsertPos = Bucket; |
| 345 | return nullptr; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | void FoldingSetBase::InsertNode(Node *N, void *InsertPos, |
| 352 | const FoldingSetInfo &Info) { |
| 353 | assert(!N->getNextInBucket()); |
| 354 | |
| 355 | if (NumNodes+1 > capacity()) { |
| 356 | GrowHashTable(Info); |
| 357 | FoldingSetNodeID TempID; |
| 358 | InsertPos = GetBucketFor(Info.ComputeNodeHash(this, N, TempID), Buckets, |
| 359 | NumBuckets); |
| 360 | } |
| 361 | |
| 362 | ++NumNodes; |
| 363 | |
| 364 | |
| 365 | void **Bucket = static_cast<void**>(InsertPos); |
| 366 | |
| 367 | void *Next = *Bucket; |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | if (!Next) |
| 373 | Next = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(Bucket)|1); |
| 374 | |
| 375 | |
| 376 | N->SetNextInBucket(Next); |
| 377 | *Bucket = N; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | |
| 382 | bool FoldingSetBase::RemoveNode(Node *N) { |
| 383 | |
| 384 | |
| 385 | void *Ptr = N->getNextInBucket(); |
| 386 | if (!Ptr) return false; |
| 387 | |
| 388 | --NumNodes; |
| 389 | N->SetNextInBucket(nullptr); |
| 390 | |
| 391 | |
| 392 | void *NodeNextPtr = Ptr; |
| 393 | |
| 394 | |
| 395 | while (true) { |
| 396 | if (Node *NodeInBucket = GetNextPtr(Ptr)) { |
| 397 | |
| 398 | Ptr = NodeInBucket->getNextInBucket(); |
| 399 | |
| 400 | |
| 401 | |
| 402 | if (Ptr == N) { |
| 403 | NodeInBucket->SetNextInBucket(NodeNextPtr); |
| 404 | return true; |
| 405 | } |
| 406 | } else { |
| 407 | void **Bucket = GetBucketPtr(Ptr); |
| 408 | Ptr = *Bucket; |
| 409 | |
| 410 | |
| 411 | |
| 412 | if (Ptr == N) { |
| 413 | *Bucket = NodeNextPtr; |
| 414 | return true; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | FoldingSetBase::Node * |
| 424 | FoldingSetBase::GetOrInsertNode(FoldingSetBase::Node *N, |
| 425 | const FoldingSetInfo &Info) { |
| 426 | FoldingSetNodeID ID; |
| 427 | Info.GetNodeProfile(this, N, ID); |
| 428 | void *IP; |
| 429 | if (Node *E = FindNodeOrInsertPos(ID, IP, Info)) |
| 430 | return E; |
| 431 | InsertNode(N, IP, Info); |
| 432 | return N; |
| 433 | } |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | FoldingSetIteratorImpl::FoldingSetIteratorImpl(void **Bucket) { |
| 439 | |
| 440 | while (*Bucket != reinterpret_cast<void*>(-1) && |
| 441 | (!*Bucket || !GetNextPtr(*Bucket))) |
| 442 | ++Bucket; |
| 443 | |
| 444 | NodePtr = static_cast<FoldingSetNode*>(*Bucket); |
| 445 | } |
| 446 | |
| 447 | void FoldingSetIteratorImpl::advance() { |
| 448 | |
| 449 | void *Probe = NodePtr->getNextInBucket(); |
| 450 | |
| 451 | if (FoldingSetNode *NextNodeInBucket = GetNextPtr(Probe)) |
| |
| 5 | | Returning from 'GetNextPtr' | |
|
| 6 | | Assuming 'NextNodeInBucket' is null | |
|
| |
| 452 | NodePtr = NextNodeInBucket; |
| 453 | else { |
| 454 | |
| 455 | void **Bucket = GetBucketPtr(Probe); |
| 456 | |
| 457 | |
| 458 | do { |
| 459 | ++Bucket; |
| 8 | | Null pointer value stored to 'Bucket' | |
|
| 460 | } while (*Bucket != reinterpret_cast<void*>(-1) && |
| 9 | | Dereference of null pointer (loaded from variable 'Bucket') |
|
| 461 | (!*Bucket || !GetNextPtr(*Bucket))); |
| 462 | |
| 463 | NodePtr = static_cast<FoldingSetNode*>(*Bucket); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | FoldingSetBucketIteratorImpl::FoldingSetBucketIteratorImpl(void **Bucket) { |
| 471 | Ptr = (!*Bucket || !GetNextPtr(*Bucket)) ? (void*) Bucket : *Bucket; |
| 472 | } |