xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/inline.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 %s -o %t && %run %t
2*7c3d14c8STreehugger Robot 
3*7c3d14c8STreehugger Robot // Test that no_sanitize_address attribute applies even when the function would
4*7c3d14c8STreehugger Robot // be normally inlined.
5*7c3d14c8STreehugger Robot 
6*7c3d14c8STreehugger Robot #include <stdlib.h>
7*7c3d14c8STreehugger Robot 
8*7c3d14c8STreehugger Robot __attribute__((no_sanitize_address))
f(int * p)9*7c3d14c8STreehugger Robot int f(int *p) {
10*7c3d14c8STreehugger Robot   return *p; // BOOOM?? Nope!
11*7c3d14c8STreehugger Robot }
12*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)13*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
14*7c3d14c8STreehugger Robot   int * volatile x = (int*)malloc(2*sizeof(int) + 2);
15*7c3d14c8STreehugger Robot   int res = f(x + 2);
16*7c3d14c8STreehugger Robot   if (res)
17*7c3d14c8STreehugger Robot     exit(0);
18*7c3d14c8STreehugger Robot   return 0;
19*7c3d14c8STreehugger Robot }
20