Skip to content

Commit

Permalink
Fix unsafe fallthrough in fbcode//glow:GraphOptimizer
Browse files Browse the repository at this point in the history
Reviewed By: jackm321, khabinov

Differential Revision: D48746875

fbshipit-source-id: ab75cafeda0720182ebcd9f930af1e576551af5b
  • Loading branch information
Wang Xu authored and facebook-github-bot committed Aug 28, 2023
1 parent a07fbed commit c81f0d6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
11 changes: 11 additions & 0 deletions lib/Graph/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,27 @@ bool Node::isArithmetic() const {

switch (getKind()) {
ARITHMETIC_NODE_CASE(Add)
[[fallthrough]];
ARITHMETIC_NODE_CASE(Mul)
[[fallthrough]];
ARITHMETIC_NODE_CASE(Sub)
[[fallthrough]];
ARITHMETIC_NODE_CASE(Div)
[[fallthrough]];
ARITHMETIC_NODE_CASE(FloorDiv)
[[fallthrough]];
ARITHMETIC_NODE_CASE(Max)
[[fallthrough]];
ARITHMETIC_NODE_CASE(Min)
[[fallthrough]];
ARITHMETIC_NODE_CASE(CmpLTE)
[[fallthrough]];
ARITHMETIC_NODE_CASE(CmpLT)
[[fallthrough]];
ARITHMETIC_NODE_CASE(CmpEQ)
[[fallthrough]];
ARITHMETIC_NODE_CASE(Pow)
[[fallthrough]];
ARITHMETIC_NODE_CASE(Fmod)
return true;
default:
Expand Down
13 changes: 13 additions & 0 deletions lib/Optimizer/GraphOptimizer/GraphOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5287,19 +5287,32 @@ bool OptimizeQuantization::run(Function *F, const CompilationContext &cctx) {
bool addNewNodeToWorklist = false;
switch (RS->getInput().getNode()->getKind()) {
case Kinded::Kind::RescaleQuantizedNodeKind:
[[fallthrough]];
case Kinded::Kind::QuantizeNodeKind:
addNewNodeToWorklist = true;
[[fallthrough]];
case Kinded::Kind::SplatNodeKind:
[[fallthrough]];
case Kinded::Kind::AddNodeKind:
[[fallthrough]];
case Kinded::Kind::SubNodeKind:
[[fallthrough]];
case Kinded::Kind::MulNodeKind:
[[fallthrough]];
case Kinded::Kind::DivNodeKind:
[[fallthrough]];
case Kinded::Kind::FmodNodeKind:
[[fallthrough]];
case Kinded::Kind::MinNodeKind:
[[fallthrough]];
case Kinded::Kind::MatMulNodeKind:
[[fallthrough]];
case Kinded::Kind::ConvolutionNodeKind:
[[fallthrough]];
case Kinded::Kind::ChannelwiseQuantizedConvolutionNodeKind:
[[fallthrough]];
case Kinded::Kind::FullyConnectedNodeKind:
[[fallthrough]];
case Kinded::Kind::SparseLengthsWeightedSumNodeKind: {
changed = true;
Node *newNode =
Expand Down
18 changes: 9 additions & 9 deletions lib/Quantization/Quantization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ class FunctionQuantizer : public FunctionConverter {
/// where the macro is inserted to keep the nice code formatting.
// clang-format off
#define CASES_FOR_SINGLE_MATCHING_IN_OUT_TYPE \
CASE_SINGLE_MATCHING_INOUT_TYPE(LocalResponseNormalization, Input, Result): \
CASE_SINGLE_MATCHING_INOUT_TYPE(Slice, Input, Result): \
CASE_SINGLE_MATCHING_INOUT_TYPE(Reshape, Input, Result): \
CASE_SINGLE_MATCHING_INOUT_TYPE(Transpose, Input, Result): \
CASE_SINGLE_MATCHING_INOUT_TYPE(TopK, Input, Values): \
CASE_SINGLE_MATCHING_INOUT_TYPE(Gather, Data, Result): \
CASE_SINGLE_MATCHING_INOUT_TYPE(MaxPool, Input, Result): \
CASE_SINGLE_MATCHING_INOUT_TYPE(ResizeNearest, Input, Result): \
CASE_SINGLE_MATCHING_INOUT_TYPE(ResizeBilinear, Input, Result): \
CASE_SINGLE_MATCHING_INOUT_TYPE(LocalResponseNormalization, Input, Result): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(Slice, Input, Result): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(Reshape, Input, Result): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(Transpose, Input, Result): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(TopK, Input, Values): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(Gather, Data, Result): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(MaxPool, Input, Result): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(ResizeNearest, Input, Result): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(ResizeBilinear, Input, Result): [[fallthrough]]; \
CASE_SINGLE_MATCHING_INOUT_TYPE(SpaceToDepth, Input, Result)
// clang-format on

Expand Down

0 comments on commit c81f0d6

Please sign in to comment.