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")
|
"MinSizeRel" "RelWithDebInfo")
|
||||||
endif()
|
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
|
# This is encouraged according to
|
||||||
# https://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq
|
# https://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq
|
||||||
|
@@ -382,8 +382,9 @@ uint8_t *Node::partialKey() {
|
|||||||
return ((Node48 *)this)->partialKey();
|
return ((Node48 *)this)->partialKey();
|
||||||
case Type_Node256:
|
case Type_Node256:
|
||||||
return ((Node256 *)this)->partialKey();
|
return ((Node256 *)this)->partialKey();
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NodeAllocators {
|
struct NodeAllocators {
|
||||||
@@ -478,8 +479,9 @@ Node *&getChildExists(Node *self, uint8_t index) {
|
|||||||
assert(self256->bitSet.test(index));
|
assert(self256->bitSet.test(index));
|
||||||
return self256->children[index].child;
|
return self256->children[index].child;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Precondition - an entry for index must exist in the node
|
// Precondition - an entry for index must exist in the node
|
||||||
@@ -510,8 +512,9 @@ Node *getChild(Node *self, uint8_t index) {
|
|||||||
auto *self256 = static_cast<Node256 *>(self);
|
auto *self256 = static_cast<Node256 *>(self);
|
||||||
return self256->children[index].child;
|
return self256->children[index].child;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class NodeT> int getChildGeqSimd(NodeT *self, int child) {
|
template <class NodeT> int getChildGeqSimd(NodeT *self, int child) {
|
||||||
@@ -590,8 +593,9 @@ int getChildGeq(Node *self, int child) {
|
|||||||
auto *self48 = static_cast<Node48 *>(self);
|
auto *self48 = static_cast<Node48 *>(self);
|
||||||
return self48->bitSet.firstSetGeq(child);
|
return self48->bitSet.firstSetGeq(child);
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setChildrenParents(Node3 *n) {
|
void setChildrenParents(Node3 *n) {
|
||||||
@@ -652,6 +656,8 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (self->type) {
|
switch (self->type) {
|
||||||
@@ -783,8 +789,9 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
|||||||
self256->bitSet.set(index);
|
self256->bitSet.set(index);
|
||||||
return self256->children[index].child;
|
return self256->children[index].child;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *nextPhysical(Node *node) {
|
Node *nextPhysical(Node *node) {
|
||||||
@@ -917,6 +924,8 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
|
|||||||
}
|
}
|
||||||
self = newSelf;
|
self = newSelf;
|
||||||
} break;
|
} break;
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1063,6 +1072,8 @@ void maybeDownsize(Node *self, NodeAllocators *allocators,
|
|||||||
allocators->node256.release(self256);
|
allocators->node256.release(self256);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1111,6 +1122,8 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
|
|||||||
case Type_Node256:
|
case Type_Node256:
|
||||||
allocators->node256.release((Node256 *)self);
|
allocators->node256.release((Node256 *)self);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (parent->type) {
|
switch (parent->type) {
|
||||||
@@ -1158,6 +1171,8 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
|
|||||||
parent256->bitSet.reset(parentsIndex);
|
parent256->bitSet.reset(parentsIndex);
|
||||||
parent256->children[parentsIndex].child = nullptr;
|
parent256->children[parentsIndex].child = nullptr;
|
||||||
} break;
|
} break;
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
|
|
||||||
--parent->numChildren;
|
--parent->numChildren;
|
||||||
@@ -1508,6 +1523,8 @@ int64_t maxBetweenExclusive(Node *n, int begin, int end) {
|
|||||||
begin, end);
|
begin, end);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
||||||
fprintf(stderr, "At `%s', max version in (%02x, %02x) is %" PRId64 "\n",
|
fprintf(stderr, "At `%s', max version in (%02x, %02x) is %" PRId64 "\n",
|
||||||
@@ -1711,7 +1728,7 @@ struct CheckRangeLeftSide {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DownLeftSpine:
|
case DownLeftSpine: {
|
||||||
if (n->entryPresent) {
|
if (n->entryPresent) {
|
||||||
ok = n->entry.rangeVersion <= readVersion;
|
ok = n->entry.rangeVersion <= readVersion;
|
||||||
return true;
|
return true;
|
||||||
@@ -1719,7 +1736,9 @@ struct CheckRangeLeftSide {
|
|||||||
int c = getChildGeq(n, 0);
|
int c = getChildGeq(n, 0);
|
||||||
assert(c >= 0);
|
assert(c >= 0);
|
||||||
n = getChildExists(n, c);
|
n = getChildExists(n, c);
|
||||||
break;
|
} break;
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1837,7 +1856,7 @@ struct CheckRangeRightSide {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case DownLeftSpine:
|
case DownLeftSpine: {
|
||||||
if (n->entryPresent) {
|
if (n->entryPresent) {
|
||||||
ok = n->entry.rangeVersion <= readVersion;
|
ok = n->entry.rangeVersion <= readVersion;
|
||||||
return true;
|
return true;
|
||||||
@@ -1845,7 +1864,9 @@ struct CheckRangeRightSide {
|
|||||||
int c = getChildGeq(n, 0);
|
int c = getChildGeq(n, 0);
|
||||||
assert(c >= 0);
|
assert(c >= 0);
|
||||||
n = getChildExists(n, c);
|
n = getChildExists(n, c);
|
||||||
break;
|
} break;
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2380,8 +2401,9 @@ int64_t &maxVersion(Node *n, ConflictSet::Impl *impl) {
|
|||||||
assert(n256->bitSet.test(index));
|
assert(n256->bitSet.test(index));
|
||||||
return n256->children[index].childMaxVersion;
|
return n256->children[index].childMaxVersion;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *&getInTree(Node *n, ConflictSet::Impl *impl) {
|
Node *&getInTree(Node *n, ConflictSet::Impl *impl) {
|
||||||
@@ -2651,6 +2673,8 @@ Iterator firstGeq(Node *n, std::string_view key) {
|
|||||||
case Type_Node256:
|
case Type_Node256:
|
||||||
minNumChildren = kMinChildrenNode256;
|
minNumChildren = kMinChildrenNode256;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
if (node->numChildren + int(node->entryPresent) < minNumChildren) {
|
if (node->numChildren + int(node->entryPresent) < minNumChildren) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@@ -2708,8 +2732,9 @@ int64_t getNodeSize(struct Node *n) {
|
|||||||
return sizeof(Node48);
|
return sizeof(Node48);
|
||||||
case Type_Node256:
|
case Type_Node256:
|
||||||
return sizeof(Node256);
|
return sizeof(Node256);
|
||||||
|
default:
|
||||||
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t getSearchPathLength(Node *n) {
|
int64_t getSearchPathLength(Node *n) {
|
||||||
|
Reference in New Issue
Block a user