1a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar// RUN: %clang_cc1 -triple %itanium_abi_triple -verify -fsyntax-only -std=c11 -Wassign-enum %s 20e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 30e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesenum __attribute__((flag_enum)) flag { 40e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ea = 0x1, 50e2c34f92f00628d48968dfea096d36381f494cbStephen Hines eb = 0x2, 60e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ec = 0x8, 70e2c34f92f00628d48968dfea096d36381f494cbStephen Hines}; 80e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 90e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesenum __attribute__((flag_enum)) flag2 { 100e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ga = 0x1, 110e2c34f92f00628d48968dfea096d36381f494cbStephen Hines gb = 0x4, 120e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 130e2c34f92f00628d48968dfea096d36381f494cbStephen Hines gc = 0x5, // no-warning 140e2c34f92f00628d48968dfea096d36381f494cbStephen Hines gd = 0x7, // expected-warning {{enumeration value 'gd' is out of range}} 150e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ge = ~0x2, // expected-warning {{enumeration value 'ge' is out of range}} 160e2c34f92f00628d48968dfea096d36381f494cbStephen Hines gf = ~0x4, // no-warning 170e2c34f92f00628d48968dfea096d36381f494cbStephen Hines gg = ~0x1, // no-warning 180e2c34f92f00628d48968dfea096d36381f494cbStephen Hines gh = ~0x5, // no-warning 190e2c34f92f00628d48968dfea096d36381f494cbStephen Hines gi = ~0x11, // expected-warning {{enumeration value 'gi' is out of range}} 200e2c34f92f00628d48968dfea096d36381f494cbStephen Hines}; 210e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 220e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesenum __attribute__((flag_enum)) flag3 { 230e2c34f92f00628d48968dfea096d36381f494cbStephen Hines fa = 0x1, 240e2c34f92f00628d48968dfea096d36381f494cbStephen Hines fb = ~0x1u, // no-warning 250e2c34f92f00628d48968dfea096d36381f494cbStephen Hines}; 260e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 270e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// What happens here is that ~0x2 is negative, and so the enum must be signed. 280e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// But ~0x1u is unsigned and has the high bit set, so the enum must be 64-bit. 290e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// The result is that ~0x1u does not have high bits set, and so it is considered 300e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// to be an invalid value. See Sema::IsValueInFlagEnum in SemaDecl.cpp for more 310e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// discussion. 320e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesenum __attribute__((flag_enum)) flag4 { 330e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ha = 0x1, 340e2c34f92f00628d48968dfea096d36381f494cbStephen Hines hb = 0x2, 350e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 360e2c34f92f00628d48968dfea096d36381f494cbStephen Hines hc = ~0x1u, // expected-warning {{enumeration value 'hc' is out of range}} 370e2c34f92f00628d48968dfea096d36381f494cbStephen Hines hd = ~0x2, // no-warning 380e2c34f92f00628d48968dfea096d36381f494cbStephen Hines}; 390e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 400e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesvoid f(void) { 410e2c34f92f00628d48968dfea096d36381f494cbStephen Hines enum flag e = 0; // no-warning 420e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = 0x1; // no-warning 430e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = 0x3; // no-warning 440e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = 0xa; // no-warning 450e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = 0x4; // expected-warning {{integer constant not in range of enumerated type}} 460e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = 0xf; // expected-warning {{integer constant not in range of enumerated type}} 470e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = ~0; // no-warning 480e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = ~0x1; // no-warning 490e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = ~0x2; // no-warning 500e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = ~0x3; // no-warning 510e2c34f92f00628d48968dfea096d36381f494cbStephen Hines e = ~0x4; // expected-warning {{integer constant not in range of enumerated type}} 520e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 530e2c34f92f00628d48968dfea096d36381f494cbStephen Hines switch (e) { 540e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case 0: break; // no-warning 550e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case 0x1: break; // no-warning 560e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case 0x3: break; // no-warning 570e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case 0xa: break; // no-warning 580e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case 0x4: break; // expected-warning {{case value not in enumerated type}} 590e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case 0xf: break; // expected-warning {{case value not in enumerated type}} 600e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case ~0: break; // expected-warning {{case value not in enumerated type}} 610e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case ~0x1: break; // expected-warning {{case value not in enumerated type}} 620e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case ~0x2: break; // expected-warning {{case value not in enumerated type}} 630e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case ~0x3: break; // expected-warning {{case value not in enumerated type}} 640e2c34f92f00628d48968dfea096d36381f494cbStephen Hines case ~0x4: break; // expected-warning {{case value not in enumerated type}} 650e2c34f92f00628d48968dfea096d36381f494cbStephen Hines default: break; 660e2c34f92f00628d48968dfea096d36381f494cbStephen Hines } 670e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 680e2c34f92f00628d48968dfea096d36381f494cbStephen Hines enum flag2 f = ~0x1; // no-warning 690e2c34f92f00628d48968dfea096d36381f494cbStephen Hines f = ~0x1u; // no-warning 700e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 710e2c34f92f00628d48968dfea096d36381f494cbStephen Hines enum flag4 h = ~0x1; // no-warning 720e2c34f92f00628d48968dfea096d36381f494cbStephen Hines h = ~0x1u; // expected-warning {{integer constant not in range of enumerated type}} 730e2c34f92f00628d48968dfea096d36381f494cbStephen Hines} 74