xref: /aosp_15_r20/external/compiler-rt/test/ubsan/TestCases/Misc/enum.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PLAIN
2*7c3d14c8STreehugger Robot // RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E" %s -O3 -o %t && %run %t
3*7c3d14c8STreehugger Robot // RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E : bool" %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-BOOL
4*7c3d14c8STreehugger Robot 
5*7c3d14c8STreehugger Robot // FIXME: UBSan fails to add the correct instrumentation code for some reason on
6*7c3d14c8STreehugger Robot // Windows.
7*7c3d14c8STreehugger Robot // XFAIL: win32
8*7c3d14c8STreehugger Robot 
9*7c3d14c8STreehugger Robot enum E { a = 1 } e;
10*7c3d14c8STreehugger Robot #undef E
11*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)12*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
13*7c3d14c8STreehugger Robot   // memset(&e, 0xff, sizeof(e));
14*7c3d14c8STreehugger Robot   for (unsigned char *p = (unsigned char*)&e; p != (unsigned char*)(&e + 1); ++p)
15*7c3d14c8STreehugger Robot     *p = 0xff;
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot   // CHECK-PLAIN: error: load of value 4294967295, which is not a valid value for type 'enum E'
18*7c3d14c8STreehugger Robot   // FIXME: Support marshalling and display of enum class values.
19*7c3d14c8STreehugger Robot   // CHECK-BOOL: error: load of value <unknown>, which is not a valid value for type 'enum E'
20*7c3d14c8STreehugger Robot   return (int)e != -1;
21*7c3d14c8STreehugger Robot }
22