xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/speculative_load2.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // Verifies that speculative loads from unions do not happen under asan.
2*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1
3*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1
4*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O2 %s -o %t && %run %t 2>&1
5*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot typedef union {
8*7c3d14c8STreehugger Robot   short q;
9*7c3d14c8STreehugger Robot   struct {
10*7c3d14c8STreehugger Robot     short x;
11*7c3d14c8STreehugger Robot     short y;
12*7c3d14c8STreehugger Robot     int for_alignment;
13*7c3d14c8STreehugger Robot   } w;
14*7c3d14c8STreehugger Robot } U;
15*7c3d14c8STreehugger Robot 
main()16*7c3d14c8STreehugger Robot int main() {
17*7c3d14c8STreehugger Robot   char *buf = new char[2];
18*7c3d14c8STreehugger Robot   buf[0] = buf[1] = 0x0;
19*7c3d14c8STreehugger Robot   U *u = (U *)buf;
20*7c3d14c8STreehugger Robot   short result = u->q == 0 ? 0 : u->w.y;
21*7c3d14c8STreehugger Robot   delete[] buf;
22*7c3d14c8STreehugger Robot   return result;
23*7c3d14c8STreehugger Robot }
24*7c3d14c8STreehugger Robot 
25