xref: /aosp_15_r20/external/compiler-rt/test/msan/c-strdup.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clang_msan -O0 %s -o %t && %run %t >%t.out 2>&1
2*7c3d14c8STreehugger Robot // RUN: %clang_msan -O1 %s -o %t && %run %t >%t.out 2>&1
3*7c3d14c8STreehugger Robot // RUN: %clang_msan -O2 %s -o %t && %run %t >%t.out 2>&1
4*7c3d14c8STreehugger Robot // RUN: %clang_msan -O3 %s -o %t && %run %t >%t.out 2>&1
5*7c3d14c8STreehugger Robot 
6*7c3d14c8STreehugger Robot // Test that strdup in C programs is intercepted.
7*7c3d14c8STreehugger Robot // GLibC headers translate strdup to __strdup at -O1 and higher.
8*7c3d14c8STreehugger Robot 
9*7c3d14c8STreehugger Robot #include <stdlib.h>
10*7c3d14c8STreehugger Robot #include <string.h>
main(int argc,char ** argv)11*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
12*7c3d14c8STreehugger Robot   char buf[] = "abc";
13*7c3d14c8STreehugger Robot   char *p = strdup(buf);
14*7c3d14c8STreehugger Robot   if (*p)
15*7c3d14c8STreehugger Robot     exit(0);
16*7c3d14c8STreehugger Robot   return 0;
17*7c3d14c8STreehugger Robot }
18