Files
TheRock/compiler/amd-llvm/clang/test/Analysis/enum-cast-out-of-range.c
T
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

78 lines
3.3 KiB
C

// RUN: %clang_analyze_cc1 \
// RUN: -analyzer-checker=core,optin.core.EnumCastOutOfRange \
// RUN: -analyzer-output text \
// RUN: -verify %s
// expected-note@+1 + {{enum declared here}}
enum En_t {
En_0 = -4,
En_1,
En_2 = 1,
En_3,
En_4 = 4
};
void unscopedUnspecifiedCStyle(void) {
enum En_t Below = (enum En_t)(-5); // expected-warning {{not in the valid range of values for 'En_t'}}
// expected-note@-1 {{not in the valid range of values for 'En_t'}}
enum En_t NegVal1 = (enum En_t)(-4); // OK.
enum En_t NegVal2 = (enum En_t)(-3); // OK.
enum En_t InRange1 = (enum En_t)(-2); // expected-warning {{not in the valid range of values for 'En_t'}}
// expected-note@-1 {{not in the valid range of values for 'En_t'}}
enum En_t InRange2 = (enum En_t)(-1); // expected-warning {{not in the valid range of values for 'En_t'}}
// expected-note@-1 {{not in the valid range of values for 'En_t'}}
enum En_t InRange3 = (enum En_t)(0); // expected-warning {{not in the valid range of values for 'En_t'}}
// expected-note@-1 {{not in the valid range of values for 'En_t'}}
enum En_t PosVal1 = (enum En_t)(1); // OK.
enum En_t PosVal2 = (enum En_t)(2); // OK.
enum En_t InRange4 = (enum En_t)(3); // expected-warning {{not in the valid range of values for 'En_t'}}
// expected-note@-1 {{not in the valid range of values for 'En_t'}}
enum En_t PosVal3 = (enum En_t)(4); // OK.
enum En_t Above = (enum En_t)(5); // expected-warning {{not in the valid range of values for 'En_t'}}
// expected-note@-1 {{not in the valid range of values for 'En_t'}}
}
enum En_t unused;
void unusedExpr(void) {
// Following line is not something that EnumCastOutOfRangeChecker should
// evaluate. Checker should either ignore this line or process it without
// producing any warnings. However, compilation will (and should) still
// generate a warning having nothing to do with this checker.
unused; // expected-warning {{expression result unused}}
}
// Test typedef-ed anonymous enums
typedef enum { // expected-note {{enum declared here}}
TD_0 = 0,
} TD_t;
void testTypeDefEnum(void) {
(void)(TD_t)(-1); // expected-warning {{not in the valid range of values for the enum}}
// expected-note@-1 {{not in the valid range of values for the enum}}
}
// Test expression tracking
void set(int* p, int v) {
*p = v; // expected-note {{The value -1 is assigned to 'i'}}
}
void testTrackExpression(int i) {
set(&i, -1); // expected-note {{Passing the value -1 via 2nd parameter 'v'}}
// expected-note@-1 {{Calling 'set'}}
// expected-note@-2 {{Returning from 'set'}}
(void)(enum En_t)(i); // expected-warning {{not in the valid range of values for 'En_t'}}
// expected-note@-1 {{not in the valid range of values for 'En_t'}}
}
enum __attribute__((flag_enum)) FlagEnum {
FE_BIT_1 = 1 << 0,
FE_BIT_2 = 1 << 1,
FE_BIT_3 = 1 << 2,
};
void testFlagEnum_gh_76208(void) {
enum FlagEnum First2BitsSet = (enum FlagEnum)(FE_BIT_1 | FE_BIT_2); // no-warning: Enums with the attribute 'flag_enum' are not checked
(void)First2BitsSet;
}