Skip to content

Commit

Permalink
Enable bugprone-switch-missing-default-case (halide#8048)
Browse files Browse the repository at this point in the history
* Upgrade clang-format and clang-tidy to use LLVM 17

* trigger buildbots

* trigger buildbots

* trigger buildbots

* trigger buildbots

* Enable `bugprone-switch-missing-default-case`

...and fix existing warnings.

* Update .clang-tidy

* Update Parameter.cpp

* Update .clang-tidy

* Update .clang-tidy

* Update .clang-tidy

* Update .clang-tidy

* Update CPlusPlusMangle.cpp
  • Loading branch information
steven-johnson authored and ardier committed Mar 3, 2024
1 parent 5b03436 commit 3a58321
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Checks: >
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
-bugprone-easily-swappable-parameters,
-bugprone-empty-catch, # TODO: consider enabling
-bugprone-empty-catch,
-bugprone-exception-escape,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
Expand Down Expand Up @@ -66,7 +66,7 @@ Checks: >
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-swapped-arguments,
-bugprone-switch-missing-default-case, # TODO: consider enabling
bugprone-switch-missing-default-case,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
Expand All @@ -93,7 +93,7 @@ Checks: >
-misc-const-correctness,
misc-definitions-in-headers,
misc-header-include-cycle,
-misc-include-cleaner, # TODO: consider enabling
-misc-include-cleaner,
misc-misleading-bidirectional,
misc-misleading-identifier,
misc-misplaced-const,
Expand Down Expand Up @@ -128,7 +128,7 @@ Checks: >
-modernize-replace-random-shuffle,
-modernize-return-braced-init-list,
-modernize-shrink-to-fit,
-modernize-type-traits, # TODO: consider enabling
-modernize-type-traits,
-modernize-unary-static-assert,
-modernize-use-auto,
modernize-use-bool-literals,
Expand Down
20 changes: 12 additions & 8 deletions src/CPlusPlusMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,10 @@ MangledNamePart mangle_type(const Type &type, const Target &target, PreviousDecl
return "H";
case 64:
return "_J";
default:
internal_error << "Unexpected integer size: " << type.bits() << ".\n";
return "";
}
internal_error << "Unexpected integer size: " << type.bits() << ".\n";
return "";
} else if (type.is_uint()) {
switch (type.bits()) {
case 1:
Expand All @@ -261,9 +262,10 @@ MangledNamePart mangle_type(const Type &type, const Target &target, PreviousDecl
return "I";
case 64:
return "_K";
default:
internal_error << "Unexpected unsigned integer size: " << type.bits() << "\n";
return "";
}
internal_error << "Unexpected unsigned integer size: " << type.bits() << "\n";
return "";
} else if (type.is_float()) {
if (type.bits() == 32) {
return "M";
Expand Down Expand Up @@ -546,9 +548,10 @@ std::string mangle_type(const Type &type, const Target &target, PrevPrefixes &pr
} else {
return "l";
}
default:
internal_error << "Unexpected integer size: " << type.bits() << ".\n";
return "";
}
internal_error << "Unexpected integer size: " << type.bits() << ".\n";
return "";
} else if (type.is_uint()) {
switch (type.bits()) {
case 1:
Expand All @@ -571,9 +574,10 @@ std::string mangle_type(const Type &type, const Target &target, PrevPrefixes &pr
} else {
return "m";
}
default:
internal_error << "Unexpected unsigned integer size: " << type.bits() << "\n";
return "";
}
internal_error << "Unexpected unsigned integer size: " << type.bits() << "\n";
return "";
} else if (type.is_float()) {
if (type.bits() == 32) {
return "f";
Expand Down
6 changes: 6 additions & 0 deletions src/CodeGen_OpenCL_Dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ void CodeGen_OpenCL_Dev::CodeGen_OpenCL_C::visit(const Call *op) {
rhs << "(int4)(" << coord[0] << idx << ", " << coord[1] << idx
<< ", " << coord[2] << idx << ", 0)).s0";
break;
default:
internal_error << "Unsupported dims";
break;
}
print_assignment(op->type.with_bits(32).with_lanes(1), rhs.str());
results[i] = id;
Expand Down Expand Up @@ -448,6 +451,9 @@ void CodeGen_OpenCL_Dev::CodeGen_OpenCL_C::visit(const Call *op) {
write_image << "(int4)(" << coord[0] << idx << ", " << coord[1] << idx
<< ", " << coord[2] << idx << ", 0)";
break;
default:
internal_error << "Unsupported dims";
break;
}
write_image << ", (" << print_type(value_type.with_bits(32).with_lanes(4))
<< ")(" << value << idx << ", 0, 0, 0));\n";
Expand Down
4 changes: 4 additions & 0 deletions src/HexagonOptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ string type_suffix(Type type, bool signed_variants) {
return prefix + "h";
case 32:
return prefix + "w";
default:
break;
}
} else if (type.is_uint()) {
switch (type.bits()) {
Expand All @@ -100,6 +102,8 @@ string type_suffix(Type type, bool signed_variants) {
return prefix + "uh";
case 32:
return prefix + "uw";
default:
break;
}
}
internal_error << "Unsupported HVX type: " << type << "\n";
Expand Down
8 changes: 8 additions & 0 deletions src/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Expr Parameter::scalar_expr() const {
return Expr(sv.u.f32);
case 64:
return Expr(sv.u.f64);
default:
break;
}
} else if (t.is_int()) {
switch (t.bits()) {
Expand All @@ -153,6 +155,8 @@ Expr Parameter::scalar_expr() const {
return Expr(sv.u.i32);
case 64:
return Expr(sv.u.i64);
default:
break;
}
} else if (t.is_uint()) {
switch (t.bits()) {
Expand All @@ -166,12 +170,16 @@ Expr Parameter::scalar_expr() const {
return Expr(sv.u.u32);
case 64:
return Expr(sv.u.u64);
default:
break;
}
} else if (t.is_handle()) {
// handles are always uint64 internally.
switch (t.bits()) {
case 64:
return Expr(sv.u.u64);
default:
break;
}
}
internal_error << "Unsupported type " << t << " in scalar_expr\n";
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/openglcompute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ WEAK const char *gl_error_name(int32_t err) {
case 0x8031:
return "GL_TABLE_TOO_LARGE";
break;
default:
break;
}
return "<unknown GL error>";
}
Expand Down
3 changes: 3 additions & 0 deletions tools/halide_image_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,9 @@ bool load_mat(const std::string &filename, ImageType *im) {
case miDOUBLE:
type = halide_type_of<double>();
break;
default:
check(false, "Unknown header");
return false;
}

*im = ImageType(type, extents);
Expand Down

0 comments on commit 3a58321

Please sign in to comment.