New switch idiom
All checks were successful
Tests / Clang total: 932, passed: 932
Clang |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|0|0|0|0|:clap:
Tests / Release [gcc] total: 932, passed: 932
Tests / Release [gcc,aarch64] total: 931, passed: 931
Tests / Coverage total: 930, passed: 930
weaselab/conflict-set/pipeline/head This commit looks good
All checks were successful
Tests / Clang total: 932, passed: 932
Clang |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|0|0|0|0|:clap:
Tests / Release [gcc] total: 932, passed: 932
Tests / Release [gcc,aarch64] total: 931, passed: 931
Tests / Coverage total: 930, passed: 930
weaselab/conflict-set/pipeline/head This commit looks good
Add -Wswitch-enum -Werror=switch-enum to enforce that we explicitly handle all cases, and add a default: __builtin_unreachable() to all switches to make un-enumerated values UB
This commit is contained in:
@@ -22,7 +22,8 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
"MinSizeRel" "RelWithDebInfo")
|
||||
endif()
|
||||
|
||||
add_compile_options(-fdata-sections -ffunction-sections -fstrict-enums)
|
||||
add_compile_options(-fdata-sections -ffunction-sections -Wswitch-enum
|
||||
-Werror=switch-enum)
|
||||
|
||||
# This is encouraged according to
|
||||
# https://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq
|
||||
|
@@ -382,9 +382,10 @@ uint8_t *Node::partialKey() {
|
||||
return ((Node48 *)this)->partialKey();
|
||||
case Type_Node256:
|
||||
return ((Node256 *)this)->partialKey();
|
||||
}
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
struct NodeAllocators {
|
||||
BoundedFreeListAllocator<Node0> node0;
|
||||
@@ -478,9 +479,10 @@ Node *&getChildExists(Node *self, uint8_t index) {
|
||||
assert(self256->bitSet.test(index));
|
||||
return self256->children[index].child;
|
||||
}
|
||||
}
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
// Precondition - an entry for index must exist in the node
|
||||
int64_t &maxVersion(Node *n, ConflictSet::Impl *);
|
||||
@@ -510,9 +512,10 @@ Node *getChild(Node *self, uint8_t index) {
|
||||
auto *self256 = static_cast<Node256 *>(self);
|
||||
return self256->children[index].child;
|
||||
}
|
||||
}
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
template <class NodeT> int getChildGeqSimd(NodeT *self, int child) {
|
||||
static_assert(std::is_same_v<NodeT, Node3> || std::is_same_v<NodeT, Node16>);
|
||||
@@ -590,9 +593,10 @@ int getChildGeq(Node *self, int child) {
|
||||
auto *self48 = static_cast<Node48 *>(self);
|
||||
return self48->bitSet.firstSetGeq(child);
|
||||
}
|
||||
}
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
void setChildrenParents(Node3 *n) {
|
||||
for (int i = 0; i < n->numChildren; ++i) {
|
||||
@@ -652,6 +656,8 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
return result;
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
|
||||
switch (self->type) {
|
||||
@@ -783,9 +789,10 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
self256->bitSet.set(index);
|
||||
return self256->children[index].child;
|
||||
}
|
||||
}
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
Node *nextPhysical(Node *node) {
|
||||
int index = -1;
|
||||
@@ -917,6 +924,8 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
|
||||
}
|
||||
self = newSelf;
|
||||
} break;
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,6 +1072,8 @@ void maybeDownsize(Node *self, NodeAllocators *allocators,
|
||||
allocators->node256.release(self256);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1111,6 +1122,8 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
|
||||
case Type_Node256:
|
||||
allocators->node256.release((Node256 *)self);
|
||||
break;
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
|
||||
switch (parent->type) {
|
||||
@@ -1158,6 +1171,8 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
|
||||
parent256->bitSet.reset(parentsIndex);
|
||||
parent256->children[parentsIndex].child = nullptr;
|
||||
} break;
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
|
||||
--parent->numChildren;
|
||||
@@ -1508,6 +1523,8 @@ int64_t maxBetweenExclusive(Node *n, int begin, int end) {
|
||||
begin, end);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
||||
fprintf(stderr, "At `%s', max version in (%02x, %02x) is %" PRId64 "\n",
|
||||
@@ -1711,7 +1728,7 @@ struct CheckRangeLeftSide {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DownLeftSpine:
|
||||
case DownLeftSpine: {
|
||||
if (n->entryPresent) {
|
||||
ok = n->entry.rangeVersion <= readVersion;
|
||||
return true;
|
||||
@@ -1719,7 +1736,9 @@ struct CheckRangeLeftSide {
|
||||
int c = getChildGeq(n, 0);
|
||||
assert(c >= 0);
|
||||
n = getChildExists(n, c);
|
||||
break;
|
||||
} break;
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1837,7 +1856,7 @@ struct CheckRangeRightSide {
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case DownLeftSpine:
|
||||
case DownLeftSpine: {
|
||||
if (n->entryPresent) {
|
||||
ok = n->entry.rangeVersion <= readVersion;
|
||||
return true;
|
||||
@@ -1845,7 +1864,9 @@ struct CheckRangeRightSide {
|
||||
int c = getChildGeq(n, 0);
|
||||
assert(c >= 0);
|
||||
n = getChildExists(n, c);
|
||||
break;
|
||||
} break;
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2380,9 +2401,10 @@ int64_t &maxVersion(Node *n, ConflictSet::Impl *impl) {
|
||||
assert(n256->bitSet.test(index));
|
||||
return n256->children[index].childMaxVersion;
|
||||
}
|
||||
}
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
Node *&getInTree(Node *n, ConflictSet::Impl *impl) {
|
||||
return n->parent == nullptr ? impl->root
|
||||
@@ -2651,6 +2673,8 @@ Iterator firstGeq(Node *n, std::string_view key) {
|
||||
case Type_Node256:
|
||||
minNumChildren = kMinChildrenNode256;
|
||||
break;
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
if (node->numChildren + int(node->entryPresent) < minNumChildren) {
|
||||
fprintf(stderr,
|
||||
@@ -2708,9 +2732,10 @@ int64_t getNodeSize(struct Node *n) {
|
||||
return sizeof(Node48);
|
||||
case Type_Node256:
|
||||
return sizeof(Node256);
|
||||
}
|
||||
default:
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
int64_t getSearchPathLength(Node *n) {
|
||||
assert(n != nullptr);
|
||||
|
Reference in New Issue
Block a user