Files
TheRock/compiler/amd-llvm/clang/test/Sema/attr-flag-enum.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
2.7 KiB
C

// RUN: %clang_cc1 -triple %itanium_abi_triple -verify -fsyntax-only -std=c11 -Wassign-enum %s
enum __attribute__((flag_enum)) flag {
ea = 0x1,
eb = 0x2,
ec = 0x8,
};
enum __attribute__((flag_enum)) {
g = 0x7, // expected-warning {{enumeration value 'g' is out of range of flags in enumeration type 'enum (unnamed at}}
};
enum __attribute__((flag_enum)) flag2 {
ga = 0x1,
gb = 0x4,
gc = 0x5, // no-warning
gd = 0x7, // expected-warning {{enumeration value 'gd' is out of range}}
ge = ~0x2, // expected-warning {{enumeration value 'ge' is out of range}}
gf = ~0x4, // no-warning
gg = ~0x1, // no-warning
gh = ~0x5, // no-warning
gi = ~0x11, // expected-warning {{enumeration value 'gi' is out of range}}
};
enum __attribute__((flag_enum)) flag3 {
fa = 0x1,
fb = ~0x1u, // no-warning
};
// What happens here is that ~0x2 is negative, and so the enum must be signed.
// But ~0x1u is unsigned and has the high bit set, so the enum must be 64-bit.
// The result is that ~0x1u does not have high bits set, and so it is considered
// to be an invalid value. See Sema::IsValueInFlagEnum in SemaDecl.cpp for more
// discussion.
enum __attribute__((flag_enum)) flag4 {
ha = 0x1,
hb = 0x2,
hc = ~0x1u, // expected-warning {{enumeration value 'hc' is out of range}}
hd = ~0x2, // no-warning
};
void f(void) {
enum flag e = 0; // no-warning
e = 0x1; // no-warning
e = 0x3; // no-warning
e = 0xa; // no-warning
e = 0x4; // expected-warning {{integer constant not in range of enumerated type}}
e = 0xf; // expected-warning {{integer constant not in range of enumerated type}}
e = ~0; // no-warning
e = ~0x1; // no-warning
e = ~0x2; // no-warning
e = ~0x3; // no-warning
e = ~0x4; // expected-warning {{integer constant not in range of enumerated type}}
switch (e) {
case 0: break; // no-warning
case 0x1: break; // no-warning
case 0x3: break; // no-warning
case 0xa: break; // no-warning
case 0x4: break; // expected-warning {{case value not in enumerated type}}
case 0xf: break; // expected-warning {{case value not in enumerated type}}
case ~0: break; // expected-warning {{case value not in enumerated type}}
case ~0x1: break; // expected-warning {{case value not in enumerated type}}
case ~0x2: break; // expected-warning {{case value not in enumerated type}}
case ~0x3: break; // expected-warning {{case value not in enumerated type}}
case ~0x4: break; // expected-warning {{case value not in enumerated type}}
default: break;
}
enum flag2 f = ~0x1; // no-warning
f = ~0x1u; // no-warning
enum flag4 h = ~0x1; // no-warning
h = ~0x1u; // expected-warning {{integer constant not in range of enumerated type}}
}