xref: /aosp_15_r20/external/compiler-rt/test/msan/cxa_atexit.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O0 %s -o %t && %run %t %p
2*7c3d14c8STreehugger Robot 
3*7c3d14c8STreehugger Robot // PR17377: C++ module destructors get stale argument shadow.
4*7c3d14c8STreehugger Robot 
5*7c3d14c8STreehugger Robot #include <stdio.h>
6*7c3d14c8STreehugger Robot #include <stdlib.h>
7*7c3d14c8STreehugger Robot class A {
8*7c3d14c8STreehugger Robot public:
9*7c3d14c8STreehugger Robot   // This destructor get stale argument shadow left from the call to f().
~A()10*7c3d14c8STreehugger Robot   ~A() {
11*7c3d14c8STreehugger Robot     if (this)
12*7c3d14c8STreehugger Robot       exit(0);
13*7c3d14c8STreehugger Robot   }
14*7c3d14c8STreehugger Robot };
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot A a;
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot __attribute__((noinline))
f(long x)19*7c3d14c8STreehugger Robot void f(long x) {
20*7c3d14c8STreehugger Robot }
21*7c3d14c8STreehugger Robot 
main(void)22*7c3d14c8STreehugger Robot int main(void) {
23*7c3d14c8STreehugger Robot   long  x;
24*7c3d14c8STreehugger Robot   long * volatile p = &x;
25*7c3d14c8STreehugger Robot   // This call poisons TLS shadow for the first function argument.
26*7c3d14c8STreehugger Robot   f(*p);
27*7c3d14c8STreehugger Robot   return 0;
28*7c3d14c8STreehugger Robot }
29