1*673dc3d4SNico Weber // Make sure ASan doesn't hang in an exec loop if DYLD_INSERT_LIBRARIES is set.
2*673dc3d4SNico Weber // This is a regression test for
3*673dc3d4SNico Weber // https://code.google.com/p/address-sanitizer/issues/detail?id=159
4*673dc3d4SNico Weber 
5*673dc3d4SNico Weber // RUN: %clangxx_asan %s -o %t
6*673dc3d4SNico Weber // RUN: %clangxx -DSHARED_LIB %s \
7*673dc3d4SNico Weber // RUN:     -dynamiclib -o darwin-dummy-shared-lib-so.dylib
8*673dc3d4SNico Weber 
9*673dc3d4SNico Weber // FIXME: the following command line may hang in the case of a regression.
10*673dc3d4SNico Weber // RUN: %env DYLD_INSERT_LIBRARIES=darwin-dummy-shared-lib-so.dylib \
11*673dc3d4SNico Weber // RUN:     %run %t 2>&1 | FileCheck %s || exit 1
12*673dc3d4SNico Weber 
13*673dc3d4SNico Weber // UNSUPPORTED: ios
14*673dc3d4SNico Weber 
15*673dc3d4SNico Weber #if !defined(SHARED_LIB)
16*673dc3d4SNico Weber #include <stdio.h>
17*673dc3d4SNico Weber #include <stdlib.h>
18*673dc3d4SNico Weber 
main()19*673dc3d4SNico Weber int main() {
20*673dc3d4SNico Weber   const char kEnvName[] = "DYLD_INSERT_LIBRARIES";
21*673dc3d4SNico Weber   printf("%s=%s\n", kEnvName, getenv(kEnvName));
22*673dc3d4SNico Weber   // CHECK: {{DYLD_INSERT_LIBRARIES=.*darwin-dummy-shared-lib-so.dylib.*}}
23*673dc3d4SNico Weber   return 0;
24*673dc3d4SNico Weber }
25*673dc3d4SNico Weber #else  // SHARED_LIB
foo()26*673dc3d4SNico Weber void foo() {}
27*673dc3d4SNico Weber #endif  // SHARED_LIB
28