Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

121 lines
2.9 KiB
C

// RUN: %clang_analyze_cc1 -verify %s -analyzer-checker=core
// This file tests ExprEngine::processSwitch.
int switch_simple(int x) {
// Validate that switch behaves as expected in a very simple situation.
switch (x) {
case 1:
return 13 / x;
case 0:
return 14 / x; // expected-warning {{Division by zero}}
case 2:
return 15 / x;
default:
return 67 / (x - x); // expected-warning {{Division by zero}}
}
}
int switch_default(int x) {
// Validate that the default case is evaluated after excluding the other
// cases -- even if it appears first.
if (x > 2 || x < 0)
return 0;
switch (x) {
default:
return 16 / x; // expected-warning {{Division by zero}}
case 1:
return 13 / x;
case 2:
return 15 / x;
}
}
int switch_unreachable_default(int x) {
// Validate that the default case is not evaluated if it is infeasible.
int zero = 0;
if (x > 2 || x < 0)
return 0;
switch (x) {
default:
return 16 / zero; // no-warning
case 0:
return 456;
case 1:
return 13 / x;
case 2:
return 15 / x;
}
}
enum Color {Red, Green, Blue};
int switch_all_enum_cases_covered(enum Color x) {
// Validate that the default case is not evaluated if the switch is over an
// enum value and all enumerators appear as 'case's.
int zero = 0;
switch (x) {
default:
return 16 / zero; // no-warning
case Red:
case Green:
return 2;
case Blue:
return 3;
}
}
int switch_all_feasible_enum_cases_covered(enum Color x) {
// Highlight a shortcoming of enum/switch handling: here the 'case's cover
// all the enumerators that could appear in the symbolic value 'x', but the
// default is still executed.
// FIXME: The default branch shouldn't be executed here.
int zero = 0;
if (x == Red)
return 1;
switch (x) {
default:
return 16 / zero; // expected-warning {{Division by zero}}
case Green:
return 2;
case Blue:
return 3;
}
}
int switch_no_compound_stmt(int x) {
// Validate that the engine can follow the switch statement even if there is
// no compound statement around the cases. (Yes, this is valid, although
// not very practical.)
switch (x) case 1: case 0: return 16 / x; // expected-warning {{Division by zero}}
return 0;
}
void switch_empty(int x) {
// Validate that the engine does not crash on these empty switches.
// (These are pretty useless, but the analyzer should still handle them.)
switch (x) {}
switch (x)
;
}
int switch_with_case_range(int x) {
// Validate that the GNU case range extension is properly handled.
switch (x) {
case 5:
return 55 / x;
case 2 ... 4:
return 3;
case 0 ... 1:
return 44 / x; // no-warning: there is no state split between 0 and 1
default:
if (x)
return 8;
return 45 / x; // no-warning: x cannot be 0 on the default branch
}
}