├── lib ├── asan │ ├── asan_lock.h │ ├── asan.syms.extra │ ├── tests │ │ ├── asan_test.ignore │ │ ├── asan_mac_test.h │ │ └── asan_exceptions_test.cc │ ├── scripts │ │ └── CMakeLists.txt │ └── asan_blacklist.txt ├── ubsan │ └── ubsan.syms.extra ├── msan │ ├── msan.syms.extra │ ├── msan_blacklist.txt │ └── tests │ │ └── msan_test_config.h ├── builtins │ ├── Darwin-excludes │ │ ├── ios.txt │ │ ├── osx.txt │ │ ├── iossim.txt │ │ ├── iossim-x86_64.txt │ │ ├── osx-x86_64.txt │ │ ├── CMakeLists.txt │ │ ├── ios7-arm64.txt │ │ ├── 10.4-x86_64.txt │ │ └── README.TXT │ ├── macho_embedded │ │ ├── i386.txt │ │ ├── CMakeLists.txt │ │ ├── thumb2-64.txt │ │ ├── arm.txt │ │ └── thumb2.txt │ ├── x86_64 │ │ ├── floatdisf.c │ │ ├── floatdidf.c │ │ └── floatdixf.c │ ├── truncdfhf2.c │ ├── truncdfsf2.c │ ├── arm │ │ ├── aeabi_drsub.c │ │ ├── aeabi_frsub.c │ │ ├── aeabi_cdcmpeq_check_nan.c │ │ ├── aeabi_cfcmpeq_check_nan.c │ │ ├── softfloat-alias.list │ │ ├── sync_fetch_and_and_4.S │ │ ├── sync_fetch_and_or_4.S │ │ └── sync_fetch_and_xor_4.S │ ├── extendsfdf2.c │ ├── fixunsdfsi.c │ ├── fixdfsi.c │ ├── fixsfsi.c │ ├── fixunstfdi.c │ ├── fixunstfsi.c │ ├── fixunstfti.c │ ├── fixunsdfti.c │ ├── trunctfdf2.c │ ├── trunctfsf2.c │ ├── fixtfdi.c │ ├── fixtfsi.c │ └── fixtfti.c ├── dfsan │ └── dfsan.syms.extra ├── cfi │ └── CMakeLists.txt ├── tsan │ ├── rtl │ │ └── tsan.syms.extra │ ├── tests │ │ ├── unit │ │ │ └── CMakeLists.txt │ │ └── rtl │ │ │ └── CMakeLists.txt │ └── check_cmake.sh ├── Makefile.mk ├── interception │ ├── CMakeLists.txt │ └── interception_mac.cc └── profile │ ├── InstrProfilingUtil.h │ └── Makefile.mk ├── test ├── msan │ ├── Linux │ │ ├── glob_test_root │ │ │ ├── aa │ │ │ ├── ab │ │ │ └── ba │ │ ├── xattr_test_root │ │ │ └── a │ │ ├── lit.local.cfg │ │ ├── mallinfo.cc │ │ ├── tcgetattr.cc │ │ ├── forkpty.cc │ │ └── glob_nomatch.cc │ ├── scandir_test_root │ │ ├── aaa │ │ ├── aab │ │ └── bbb │ ├── sync_lock_set_and_test.cc │ ├── default_blacklist.cc │ ├── textdomain.cc │ ├── lit.site.cfg.in │ ├── setlocale.cc │ ├── errno.cc │ ├── tzset.cc │ ├── icmp_slt_allones.cc │ ├── initgroups.cc │ ├── strxfrm.cc │ ├── ftime.cc │ ├── test.h │ ├── times.cc │ ├── inline.cc │ ├── dlerror.cc │ ├── ioctl.cc │ ├── rand_r.cc │ ├── memcmp_test.cc │ ├── sem_getvalue.cc │ ├── unpoison_string.cc │ ├── strerror_r-non-gnu.c │ ├── msan_print_shadow3.cc │ ├── tls_reuse.cc │ ├── poison_in_free.cc │ ├── c-strdup.c │ ├── pthread_getattr_np_deadlock.cc │ ├── vector_select.cc │ ├── pthread_setcancelstate.cc │ ├── Unit │ │ └── lit.site.cfg.in │ ├── cxa_atexit.cc │ ├── backtrace.cc │ ├── vector_cvt.cc │ ├── no_sanitize_memory_prop.cc │ ├── msan_dump_shadow.cc │ └── sigwait.cc ├── asan │ └── TestCases │ │ ├── Posix │ │ ├── glob_test_root │ │ │ ├── aa │ │ │ ├── ab │ │ │ └── ba │ │ ├── asan-symbolize-bad-path.cc │ │ ├── lit.local.cfg │ │ ├── assign_large_valloc_to_global.cc │ │ ├── strerror_r_test.cc │ │ ├── freopen.cc │ │ └── asprintf.cc │ │ ├── Helpers │ │ ├── initialization-constexpr-extra.cc │ │ ├── initialization-blacklist.txt │ │ ├── initialization-blacklist-extra2.cc │ │ ├── lit.local.cfg │ │ ├── initialization-bug-extra.cc │ │ ├── blacklist-extra.cc │ │ ├── initialization-bug-extra2.cc │ │ ├── init-order-atexit-extra.cc │ │ ├── initialization-nobug-extra.cc │ │ ├── initialization-blacklist-extra.cc │ │ └── echo-env.cc │ │ ├── Windows │ │ ├── windows_h.cc │ │ ├── hello_world.cc │ │ ├── stack_array_sanity.cc │ │ ├── oom.cc │ │ ├── global_const_string.cc │ │ ├── use_after_return_linkage.cc │ │ ├── bitfield.cc │ │ ├── operator_delete_wrong_argument.cc │ │ ├── lit.local.cfg │ │ ├── default_options.cc │ │ ├── on_error_callback.cc │ │ ├── dll_large_function.cc │ │ ├── beginthreadex.cc │ │ ├── null_deref.cc │ │ ├── dll_and_lib.cc │ │ ├── shadow_mapping_failure.cc │ │ ├── dll_null_deref.cc │ │ ├── iostream_sbo.cc │ │ ├── malloc_left_oob.cc │ │ ├── thread_simple.cc │ │ ├── malloc_right_oob.cc │ │ ├── operator_new_left_oob.cc │ │ ├── calloc_left_oob.cc │ │ ├── operator_new_right_oob.cc │ │ ├── realloc_left_oob.cc │ │ ├── realloc_right_oob.cc │ │ ├── calloc_right_oob.cc │ │ ├── stack_array_left_oob.cc │ │ ├── stack_array_right_oob.cc │ │ ├── coverage-basic.cc │ │ └── thread_suspended.cc │ │ ├── Linux │ │ ├── lit.local.cfg │ │ ├── asan_default_suppressions.cc │ │ ├── globals-gc-sections.cc │ │ ├── asan_dlopen_test.cc │ │ ├── asan_rt_confict_test-1.cc │ │ ├── leak.cc │ │ ├── rlimit_mmap_test.cc │ │ ├── init_fini_sections.cc │ │ └── asan_preload_test-2.cc │ │ ├── Darwin │ │ ├── lit.local.cfg │ │ ├── empty-section.cc │ │ ├── asan_gen_prefixes.cc │ │ ├── malloc_zone-protected.cc │ │ ├── objc-odr.mm │ │ └── abort_on_error.cc │ │ ├── asan_options-help.cc │ │ ├── default_blacklist.cc │ │ ├── Android │ │ └── lit.local.cfg │ │ ├── sleep_before_dying.c │ │ ├── asan_and_llvm_coverage_test.cc │ │ ├── interface_test.cc │ │ ├── use-after-scope-nobug.cc │ │ ├── force_inline_opt0.cc │ │ ├── default_options.cc │ │ ├── frexp_interceptor.cc │ │ ├── lsan_annotations.cc │ │ ├── on_error_callback.cc │ │ ├── no_asan_gen_globals.c │ │ ├── strip_path_prefix.c │ │ ├── alloca_safe_access.cc │ │ ├── inline.cc │ │ ├── huge_negative_hea_oob.cc │ │ ├── global-demangle.cc │ │ ├── poison_partial.cc │ │ ├── memcmp_strict_test.cc │ │ ├── atexit_stats.cc │ │ ├── alloca_big_alignment.cc │ │ ├── alloca_overflow_partial.cc │ │ ├── alloca_overflow_right.cc │ │ ├── alloca_underflow_left.cc │ │ ├── stack-frame-demangle.cc │ │ ├── time_interceptor.cc │ │ ├── use-after-scope.cc │ │ ├── coverage-and-lsan.cc │ │ ├── partial_right.cc │ │ ├── use-after-poison.cc │ │ ├── memcmp_test.cc │ │ ├── vla_loop_overfow.cc │ │ ├── describe_address.cc │ │ ├── heap-overflow-large.cc │ │ ├── strcspn-2.c │ │ ├── strpbrk-2.c │ │ ├── strspn-1.c │ │ ├── strspn-2.c │ │ ├── vla_condition_overflow.cc │ │ ├── alloca_detect_custom_size_.cc │ │ ├── sanity_check_pure_c.c │ │ ├── strcspn-1.c │ │ └── strpbrk-1.c ├── tsan │ ├── suppressions_race.cc.supp │ ├── suppressions_race2.cc.supp │ ├── suppressions_global.cc.supp │ ├── ignore_lib2.cc.supp │ ├── ignore_lib0.cc.supp │ ├── ignore_lib3.cc.supp │ ├── ignore_lib1.cc.supp │ ├── free_race.c.supp │ ├── Linux │ │ └── lit.local.cfg │ ├── libcxx │ │ ├── lit.local.cfg │ │ └── std_shared_ptr.cc │ ├── bench_acquire_release.cc │ ├── thread_leak.c │ ├── thread_leak2.c │ ├── lit.site.cfg.in │ ├── thread_leak4.c │ ├── bench_acquire_only.cc │ ├── thread_end_with_ignore2.cc │ ├── thread_detach.c │ ├── deflake.bash │ ├── tiny_race.c │ ├── atomic_free.cc │ ├── interface_atomic_test.c │ ├── bench_single_writer.cc │ ├── printf-1.c │ ├── atomic_free2.cc │ ├── thread_leak3.c │ ├── stack_race.cc │ ├── atexit2.cc │ ├── tls_race.cc │ ├── atexit.cc │ ├── longjmp.cc │ ├── heap_race.cc │ ├── sleep_sync2.cc │ ├── Unit │ │ └── lit.site.cfg.in │ ├── bench_rwmutex.cc │ ├── virtual_inheritance_compile_bug.cc │ ├── ignore_lib_lib.h │ ├── race_stress.cc │ ├── bench_ten_mutexes.cc │ ├── setuid2.c │ ├── suppress_same_address.cc │ ├── thread_leak5.c │ ├── bench_mutex.cc │ ├── sunrpc.cc │ ├── race_on_mutex2.c │ ├── static_init1.cc │ ├── halt_on_error.cc │ ├── bench_release_only.cc │ ├── longjmp2.cc │ ├── simple_race.c │ ├── suppress_same_stacks.cc │ ├── stack_race2.cc │ ├── global_race2.cc │ ├── malloc_stack.cc │ ├── thread_end_with_ignore.cc │ ├── tls_race2.cc │ ├── race_on_puts.cc │ ├── setuid.c │ ├── vptr_harmful_race4.cc │ ├── fd_close_norace2.cc │ ├── free_race2.c │ └── mutex_bad_unlock.cc ├── profile │ ├── Inputs │ │ ├── instrprof-dlopen-func.c │ │ ├── instrprof-dlopen-func2.c │ │ ├── instrprof-dynamic-header.h │ │ ├── gcc-flag-compatibility.c │ │ ├── instrprof-dynamic-a.cpp │ │ ├── instrprof-dynamic-b.cpp │ │ └── instrprof-dynamic-main.cpp │ ├── lit.site.cfg.in │ ├── instrprof-set-filename.c │ ├── instrprof-override-filename.c │ ├── CMakeLists.txt │ ├── instrprof-override-filename-with-env.c │ └── instrprof-reset-counters.c ├── cfi │ ├── icall │ │ ├── lit.local.cfg │ │ └── external-call.c │ ├── lit.site.cfg.in │ └── README.txt ├── safestack │ ├── utils.h │ ├── init.c │ ├── lto.c │ ├── lit.site.cfg.in │ ├── overflow.c │ ├── buffer-copy.c │ └── buffer-copy-vla.c ├── ubsan │ ├── TestCases │ │ ├── TypeCheck │ │ │ ├── Function │ │ │ │ └── lit.local.cfg │ │ │ ├── vptr-virtual-base-construction.cpp │ │ │ └── vptr-virtual-base.cpp │ │ ├── Misc │ │ │ ├── Linux │ │ │ │ ├── lit.local.cfg │ │ │ │ └── ubsan_options.cc │ │ │ ├── unreachable.cpp │ │ │ ├── vla.c │ │ │ ├── nonnull.cpp │ │ │ ├── bool.cpp │ │ │ └── deduplication.cpp │ │ └── Integer │ │ │ ├── div-overflow.cpp │ │ │ ├── mul-overflow.cpp │ │ │ └── summary.cpp │ └── lit.site.cfg.in ├── sanitizer_common │ ├── TestCases │ │ ├── options-help.cc │ │ ├── Darwin │ │ │ ├── lit.local.cfg │ │ │ └── abort_on_error.cc │ │ ├── Linux │ │ │ ├── lit.local.cfg │ │ │ ├── aligned_alloc.c │ │ │ ├── clock_gettime.c │ │ │ ├── mlock_test.cc │ │ │ ├── sched_getparam.cc │ │ │ ├── abort_on_error.cc │ │ │ └── getpwnam_r_invalid_user.cc │ │ ├── Posix │ │ │ └── lit.local.cfg │ │ ├── strspn.c │ │ ├── strcspn.c │ │ ├── strstr.c │ │ ├── strpbrk.c │ │ ├── corelimit.cc │ │ ├── strcasestr.c │ │ ├── pthread_mutexattr_get.cc │ │ └── options-invalid.cc │ ├── lit.site.cfg.in │ └── Unit │ │ └── lit.site.cfg.in ├── builtins │ └── Unit │ │ └── ppc │ │ ├── DD.h │ │ └── test ├── dfsan │ ├── Inputs │ │ └── flags_abilist.txt │ ├── lit.site.cfg.in │ ├── CMakeLists.txt │ └── vararg.c ├── lsan │ ├── TestCases │ │ ├── sanity_check_pure_c.c │ │ ├── new_array_with_dtor_0.cc │ │ ├── ignore_object_errors.cc │ │ ├── fork.cc │ │ └── link_turned_off.cc │ └── lit.site.cfg.in └── BlocksRuntime │ ├── macro.c │ ├── modglobal.c │ ├── c99.c │ ├── flagsisa.c │ ├── shorthandexpression.c │ ├── block-static.c │ ├── orbars.c │ ├── sizeof.c │ ├── returnfunctionptr.c │ └── voidarg.c ├── make └── platform │ ├── clang_macho_embedded_test_input.c │ ├── clang_linux_test_input.c │ ├── multi_arch.mk │ └── clang_darwin_test_input.c ├── .gitignore ├── .arcconfig ├── unittests └── CMakeLists.txt ├── README.txt ├── cmake └── Modules │ └── CompilerRTLink.cmake └── www ├── content.css └── menu.html.incl /lib/asan/asan_lock.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/msan/Linux/glob_test_root/aa: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/msan/Linux/glob_test_root/ab: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/msan/Linux/glob_test_root/ba: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/msan/Linux/xattr_test_root/a: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/msan/scandir_test_root/aaa: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/msan/scandir_test_root/aab: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/msan/scandir_test_root/bbb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/ubsan/ubsan.syms.extra: -------------------------------------------------------------------------------- 1 | __ubsan_* 2 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/glob_test_root/aa: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/glob_test_root/ab: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/glob_test_root/ba: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /make/platform/clang_macho_embedded_test_input.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/msan/msan.syms.extra: -------------------------------------------------------------------------------- 1 | __msan_* 2 | __ubsan_* 3 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/ios.txt: -------------------------------------------------------------------------------- 1 | apple_versioning 2 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/osx.txt: -------------------------------------------------------------------------------- 1 | apple_versioning 2 | -------------------------------------------------------------------------------- /test/tsan/suppressions_race.cc.supp: -------------------------------------------------------------------------------- 1 | race:Thread1 2 | 3 | -------------------------------------------------------------------------------- /test/tsan/suppressions_race2.cc.supp: -------------------------------------------------------------------------------- 1 | race:Thread2 2 | 3 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/iossim.txt: -------------------------------------------------------------------------------- 1 | apple_versioning 2 | -------------------------------------------------------------------------------- /test/tsan/suppressions_global.cc.supp: -------------------------------------------------------------------------------- 1 | race:RacyGlobal 2 | 3 | -------------------------------------------------------------------------------- /lib/asan/asan.syms.extra: -------------------------------------------------------------------------------- 1 | __asan_* 2 | __lsan_* 3 | __ubsan_* 4 | -------------------------------------------------------------------------------- /lib/dfsan/dfsan.syms.extra: -------------------------------------------------------------------------------- 1 | dfsan_* 2 | __dfsan_* 3 | __dfsw_* 4 | -------------------------------------------------------------------------------- /test/tsan/ignore_lib2.cc.supp: -------------------------------------------------------------------------------- 1 | called_from_lib:ignore_lib2 2 | 3 | -------------------------------------------------------------------------------- /test/tsan/ignore_lib0.cc.supp: -------------------------------------------------------------------------------- 1 | called_from_lib:/libignore_lib0.so 2 | 3 | -------------------------------------------------------------------------------- /test/tsan/ignore_lib3.cc.supp: -------------------------------------------------------------------------------- 1 | called_from_lib:ignore_lib3.so 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | darwin_fat 3 | clang_darwin 4 | multi_arch 5 | *.sw? 6 | -------------------------------------------------------------------------------- /test/profile/Inputs/instrprof-dlopen-func.c: -------------------------------------------------------------------------------- 1 | void func(int K) { if (K) {} } 2 | -------------------------------------------------------------------------------- /test/tsan/ignore_lib1.cc.supp: -------------------------------------------------------------------------------- 1 | called_from_lib:/libignore_lib1.so$ 2 | 3 | -------------------------------------------------------------------------------- /test/profile/Inputs/instrprof-dlopen-func2.c: -------------------------------------------------------------------------------- 1 | void func2(int K) { if (K) {} } 2 | -------------------------------------------------------------------------------- /test/tsan/free_race.c.supp: -------------------------------------------------------------------------------- 1 | # Suppression for a use-after-free in free_race.c 2 | race:^Thread2$ 3 | -------------------------------------------------------------------------------- /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "project_id" : "compiler-rt", 3 | "conduit_uri" : "http://reviews.llvm.org/" 4 | } 5 | -------------------------------------------------------------------------------- /lib/asan/tests/asan_test.ignore: -------------------------------------------------------------------------------- 1 | # blacklisted functions for instrumented ASan unit test 2 | fun:*IgnoreTest* 3 | fun:*SomeOtherFunc* 4 | -------------------------------------------------------------------------------- /lib/asan/scripts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(ANDROID) 2 | add_compiler_rt_script(asan_device_setup) 3 | add_dependencies(asan asan_device_setup) 4 | endif() 5 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/initialization-constexpr-extra.cc: -------------------------------------------------------------------------------- 1 | // Constexpr: 2 | int getCoolestInteger(); 3 | static int coolest_integer = getCoolestInteger(); 4 | -------------------------------------------------------------------------------- /test/profile/Inputs/instrprof-dynamic-header.h: -------------------------------------------------------------------------------- 1 | template void bar(int X) { 2 | if (X) { 3 | X *= 4; 4 | } 5 | } 6 | void a(); 7 | void b(); 8 | -------------------------------------------------------------------------------- /test/profile/Inputs/gcc-flag-compatibility.c: -------------------------------------------------------------------------------- 1 | int X = 0; 2 | 3 | int main() { 4 | int i; 5 | for (i = 0; i < 100; i++) 6 | X += i; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/initialization-blacklist.txt: -------------------------------------------------------------------------------- 1 | global:*badGlobal*=init 2 | type:*badNamespace::BadClass*=init 3 | src:*initialization-blacklist-extra2.cc=init 4 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/initialization-blacklist-extra2.cc: -------------------------------------------------------------------------------- 1 | int zero_init(); 2 | int badSrcGlobal = zero_init(); 3 | int readBadSrcGlobal() { return badSrcGlobal; } 4 | 5 | -------------------------------------------------------------------------------- /test/profile/Inputs/instrprof-dynamic-a.cpp: -------------------------------------------------------------------------------- 1 | #include "instrprof-dynamic-header.h" 2 | void a() { 3 | if (true) { 4 | bar(1); 5 | bar(1); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/profile/Inputs/instrprof-dynamic-b.cpp: -------------------------------------------------------------------------------- 1 | #include "instrprof-dynamic-header.h" 2 | void b() { 3 | if (true) { 4 | bar(1); 5 | bar(1); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /unittests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | configure_lit_site_cfg( 2 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.common.unit.configured.in 3 | ${CMAKE_CURRENT_BINARY_DIR}/lit.common.unit.configured) 4 | -------------------------------------------------------------------------------- /test/cfi/icall/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # The cfi-icall checker is only supported on x86 and x86_64 for now. 2 | if config.root.host_arch not in ['x86', 'x86_64']: 3 | config.unsupported = True 4 | -------------------------------------------------------------------------------- /test/cfi/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 2 | lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg") 3 | -------------------------------------------------------------------------------- /test/msan/sync_lock_set_and_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | 3 | int main(void) { 4 | int i; 5 | __sync_lock_test_and_set(&i, 0); 6 | return i; 7 | } 8 | -------------------------------------------------------------------------------- /lib/cfi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_custom_target(cfi) 2 | add_compiler_rt_resource_file(cfi_blacklist cfi_blacklist.txt) 3 | add_dependencies(cfi cfi_blacklist) 4 | add_dependencies(compiler-rt cfi) 5 | -------------------------------------------------------------------------------- /make/platform/clang_linux_test_input.c: -------------------------------------------------------------------------------- 1 | // This file is used to check if we can produce working executables 2 | // for i386 and x86_64 archs on Linux. 3 | #include 4 | int main(){} 5 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # Sources in this directory are helper files for tests which test functionality 2 | # involving multiple translation units. 3 | config.suffixes = [] 4 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/initialization-bug-extra.cc: -------------------------------------------------------------------------------- 1 | // This file simply declares a dynamically initialized var by the name of 'y'. 2 | int initY() { 3 | return 5; 4 | } 5 | int y = initY(); 6 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/windows_h.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: %run %t 3 | 4 | // Just make sure we can parse 5 | #include 6 | 7 | int main() {} 8 | -------------------------------------------------------------------------------- /test/safestack/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | static inline void break_optimization(void *arg) { 5 | __asm__ __volatile__("" : : "r" (arg) : "memory"); 6 | } 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/iossim-x86_64.txt: -------------------------------------------------------------------------------- 1 | addtf3 2 | divtf3 3 | multf3 4 | powitf2 5 | subtf3 6 | trampoline_setup 7 | addtf3 8 | divtf3 9 | multf3 10 | powitf2 11 | subtf3 12 | trampoline_setup 13 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/osx-x86_64.txt: -------------------------------------------------------------------------------- 1 | addtf3 2 | divtf3 3 | multf3 4 | powitf2 5 | subtf3 6 | trampoline_setup 7 | addtf3 8 | divtf3 9 | multf3 10 | powitf2 11 | subtf3 12 | trampoline_setup 13 | -------------------------------------------------------------------------------- /test/safestack/init.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_safestack %s -o %t 2 | // RUN: %run %t 3 | 4 | // Basic smoke test for the runtime library. 5 | 6 | int main(int argc, char **argv) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /lib/builtins/macho_embedded/i386.txt: -------------------------------------------------------------------------------- 1 | i686.get_pc_thunk.eax 2 | i686.get_pc_thunk.ebp 3 | i686.get_pc_thunk.ebx 4 | i686.get_pc_thunk.ecx 5 | i686.get_pc_thunk.edi 6 | i686.get_pc_thunk.edx 7 | i686.get_pc_thunk.esi 8 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/blacklist-extra.cc: -------------------------------------------------------------------------------- 1 | // This function is broken, but this file is blacklisted 2 | int externalBrokenFunction(int argc) { 3 | char x[10] = {0}; 4 | return x[argc * 10]; // BOOM 5 | } 6 | -------------------------------------------------------------------------------- /test/msan/default_blacklist.cc: -------------------------------------------------------------------------------- 1 | // Test that MSan uses the default blacklist from resource directory. 2 | // RUN: %clangxx_msan -### %s 2>&1 | FileCheck %s 3 | // CHECK: fsanitize-blacklist={{.*}}msan_blacklist.txt 4 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/TypeCheck/Function/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # The function type checker is only supported on x86 and x86_64 for now. 2 | if config.root.host_arch not in ['x86', 'x86_64']: 3 | config.unsupported = True 4 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/initialization-bug-extra2.cc: -------------------------------------------------------------------------------- 1 | // 'z' is dynamically initialized global from different TU. 2 | extern int z; 3 | int __attribute__((noinline)) initY() { 4 | return z + 1; 5 | } 6 | int y = initY(); 7 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB filter_files ${CMAKE_CURRENT_SOURCE_DIR}/*.txt) 2 | foreach(filter_file ${filter_files}) 3 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${filter_file}) 4 | endforeach() 5 | -------------------------------------------------------------------------------- /lib/builtins/macho_embedded/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB filter_files ${CMAKE_CURRENT_SOURCE_DIR}/*.txt) 2 | foreach(filter_file ${filter_files}) 3 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${filter_file}) 4 | endforeach() 5 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/hello_world.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: %run %t | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | printf("Hello, world!\n"); 8 | // CHECK: Hello, world! 9 | } 10 | -------------------------------------------------------------------------------- /test/profile/Inputs/instrprof-dynamic-main.cpp: -------------------------------------------------------------------------------- 1 | #include "instrprof-dynamic-header.h" 2 | void foo(int K) { if (K) {} } 3 | int main(int argc, char *argv[]) { 4 | foo(5); 5 | bar(1); 6 | a(); 7 | b(); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/options-help.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -O0 %s -o %t 2 | // RUN: %env_tool_opts=help=1 %run %t 2>&1 | FileCheck %s 3 | 4 | int main() { 5 | } 6 | 7 | // CHECK: Available flags for {{.*}}Sanitizer: 8 | // CHECK: handle_segv 9 | -------------------------------------------------------------------------------- /test/msan/Linux/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os not in ['Linux']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /test/tsan/Linux/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os not in ['Linux']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /test/tsan/libcxx/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if not root.has_libcxx: 9 | config.unsupported = True 10 | 11 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/asan-symbolize-bad-path.cc: -------------------------------------------------------------------------------- 1 | // Test that asan_symbolize does not hang when provided with an non-existing 2 | // path. 3 | // RUN: echo '#0 0xabcdabcd (%T/bad/path+0x1234)' | %asan_symbolize | FileCheck %s 4 | // CHECK: #0 0xabcdabcd 5 | -------------------------------------------------------------------------------- /test/builtins/Unit/ppc/DD.h: -------------------------------------------------------------------------------- 1 | #ifndef __DD_HEADER 2 | #define __DD_HEADER 3 | 4 | #include 5 | 6 | typedef union { 7 | long double ld; 8 | struct { 9 | double hi; 10 | double lo; 11 | }; 12 | } DD; 13 | 14 | #endif // __DD_HEADER 15 | -------------------------------------------------------------------------------- /test/safestack/lto.c: -------------------------------------------------------------------------------- 1 | // REQUIRES: lto 2 | 3 | // RUN: %clang_lto_safestack %s -o %t 4 | // RUN: %run %t 5 | 6 | // Test that safe stack works with LTO. 7 | 8 | int main() { 9 | char c[] = "hello world"; 10 | puts(c); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os not in ['Linux']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os in ['Windows']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /test/asan/TestCases/Darwin/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os not in ['Darwin']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Misc/Linux/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os not in ['Linux']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/ios7-arm64.txt: -------------------------------------------------------------------------------- 1 | clzti2 2 | divti3 3 | fixdfti 4 | fixsfti 5 | fixunsdfti 6 | floattidf 7 | floattisf 8 | floatuntidf 9 | floatuntisf 10 | gcc_personality_v0 11 | modti3 12 | powidf2 13 | powisf2 14 | udivmodti4 15 | udivti3 16 | umodti3 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/assign_large_valloc_to_global.cc: -------------------------------------------------------------------------------- 1 | // Make sure we don't report a leak nor hang. 2 | // RUN: %clangxx_asan -O3 %s -o %t && %run %t 3 | #include 4 | #include 5 | int *p; 6 | int main() { posix_memalign((void **)&p, 4096, 1 << 20); } 7 | -------------------------------------------------------------------------------- /test/dfsan/Inputs/flags_abilist.txt: -------------------------------------------------------------------------------- 1 | fun:f=uninstrumented 2 | 3 | fun:main=uninstrumented 4 | fun:main=discard 5 | 6 | fun:dfsan_create_label=uninstrumented 7 | fun:dfsan_create_label=discard 8 | 9 | fun:dfsan_set_label=uninstrumented 10 | fun:dfsan_set_label=discard 11 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Darwin/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os not in ['Darwin']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Linux/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os not in ['Linux']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Posix/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.host_os in ['Windows', 'Darwin']: 9 | config.unsupported = True 10 | -------------------------------------------------------------------------------- /test/msan/textdomain.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | const char *td = textdomain("abcd"); 8 | if (td[0] == 0) { 9 | printf("Try read"); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /lib/builtins/macho_embedded/thumb2-64.txt: -------------------------------------------------------------------------------- 1 | sync_fetch_and_add_8 2 | sync_fetch_and_sub_8 3 | sync_fetch_and_and_8 4 | sync_fetch_and_or_8 5 | sync_fetch_and_xor_8 6 | sync_fetch_and_nand_8 7 | sync_fetch_and_max_8 8 | sync_fetch_and_umax_8 9 | sync_fetch_and_min_8 10 | sync_fetch_and_umin_8 11 | -------------------------------------------------------------------------------- /test/dfsan/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 3 | 4 | # Load tool-specific config that would do the real work. 5 | lit_config.load_config(config, "@DFSAN_LIT_TESTS_DIR@/lit.cfg") 6 | -------------------------------------------------------------------------------- /test/msan/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 3 | 4 | # Load tool-specific config that would do the real work. 5 | lit_config.load_config(config, "@MSAN_LIT_SOURCE_DIR@/lit.cfg") 6 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Linux/aligned_alloc.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang -std=c11 -O0 %s -o %t && %run %t 2 | #include 3 | extern void *aligned_alloc (size_t alignment, size_t size); 4 | int main() { 5 | volatile void *p = aligned_alloc(128, 1024); 6 | free((void*)p); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /lib/tsan/rtl/tsan.syms.extra: -------------------------------------------------------------------------------- 1 | __tsan_init 2 | __tsan_read* 3 | __tsan_write* 4 | __tsan_vptr* 5 | __tsan_func* 6 | __tsan_atomic* 7 | __tsan_java* 8 | __tsan_unaligned* 9 | __tsan_release 10 | __tsan_acquire 11 | __ubsan_* 12 | Annotate* 13 | WTFAnnotate* 14 | RunningOnValgrind 15 | ValgrindSlowdown 16 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/init-order-atexit-extra.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class C { 4 | public: 5 | C() { value = 42; } 6 | ~C() { } 7 | int value; 8 | }; 9 | 10 | C c; 11 | 12 | void AccessC() { 13 | printf("C value: %d\n", c.value); 14 | } 15 | 16 | int main() { return 0; } 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/stack_array_sanity.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: %run %t | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | int subscript = 1; 8 | char buffer[42]; 9 | buffer[subscript] = 42; 10 | printf("OK\n"); 11 | // CHECK: OK 12 | } 13 | -------------------------------------------------------------------------------- /test/asan/TestCases/asan_options-help.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t 2 | // RUN: %env_asan_opts=help=1 %run %t 2>&1 | FileCheck %s 3 | 4 | int main() { 5 | } 6 | 7 | // CHECK: Available flags for AddressSanitizer: 8 | // CHECK-DAG: handle_segv 9 | // CHECK-DAG: check_initialization_order 10 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Misc/unreachable.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=unreachable %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s 2 | 3 | int main(int, char **argv) { 4 | // CHECK: unreachable.cpp:5:3: runtime error: execution reached a __builtin_unreachable() call 5 | __builtin_unreachable(); 6 | } 7 | -------------------------------------------------------------------------------- /test/msan/setlocale.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main(void) { 8 | char *locale = setlocale (LC_ALL, ""); 9 | assert(locale); 10 | if (locale[0]) 11 | exit(0); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /lib/builtins/macho_embedded/arm.txt: -------------------------------------------------------------------------------- 1 | aeabi_cdcmpeq 2 | aeabi_cdrcmple 3 | aeabi_cfcmpeq 4 | aeabi_cfrcmple 5 | aeabi_dcmpeq 6 | aeabi_dcmpge 7 | aeabi_dcmpgt 8 | aeabi_dcmple 9 | aeabi_dcmplt 10 | aeabi_drsub 11 | aeabi_fcmpeq 12 | aeabi_fcmpge 13 | aeabi_fcmpgt 14 | aeabi_fcmple 15 | aeabi_fcmplt 16 | aeabi_frsub 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/oom.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | while (true) { 8 | void *ptr = malloc(200 * 1024 * 1024); // 200MB 9 | free(ptr); 10 | } 11 | // CHECK: failed to allocate 12 | } 13 | -------------------------------------------------------------------------------- /test/lsan/TestCases/sanity_check_pure_c.c: -------------------------------------------------------------------------------- 1 | // Check that we can build C code. 2 | // RUN: %clang_lsan %s -o %t 3 | #ifdef __cplusplus 4 | #error "This test must be built in C mode" 5 | #endif 6 | 7 | int main() { 8 | // FIXME: ideally this should somehow check that we don't have libstdc++ 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/strspn.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang %s -o %t && %run %t 2>&1 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char **argv) { 7 | size_t r; 8 | char s1[] = "ab"; 9 | char s2[] = "ac"; 10 | r = strspn(s1, s2); 11 | assert(r == 1); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/strcspn.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang %s -o %t && %run %t 2>&1 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char **argv) { 7 | size_t r; 8 | char s1[] = "ad"; 9 | char s2[] = "cd"; 10 | r = strcspn(s1, s2); 11 | assert(r == 1); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/strstr.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang %s -o %t && %run %t 2>&1 2 | 3 | #include 4 | #include 5 | int main(int argc, char **argv) { 6 | char *r = 0; 7 | char s1[] = "ab"; 8 | char s2[] = "b"; 9 | r = strstr(s1, s2); 10 | assert(r == s1 + 1); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /lib/msan/msan_blacklist.txt: -------------------------------------------------------------------------------- 1 | # Blacklist for MemorySanitizer. Turns off instrumentation of particular 2 | # functions or sources. Use with care. You may set location of blacklist 3 | # at compile-time using -fsanitize-blacklist= flag. 4 | 5 | # Example usage: 6 | # fun:*bad_function_name* 7 | # src:file_with_tricky_code.cc 8 | -------------------------------------------------------------------------------- /test/asan/TestCases/default_blacklist.cc: -------------------------------------------------------------------------------- 1 | // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 2 | // XFAIL: android 3 | // 4 | // Test that ASan uses the default blacklist from resource directory. 5 | // RUN: %clangxx_asan -### %s 2>&1 | FileCheck %s 6 | // CHECK: fsanitize-blacklist={{.*}}asan_blacklist.txt 7 | -------------------------------------------------------------------------------- /lib/builtins/x86_64/floatdisf.c: -------------------------------------------------------------------------------- 1 | /* This file is distributed under the University of Illinois Open Source 2 | * License. See LICENSE.TXT for details. 3 | */ 4 | 5 | #ifdef __x86_64__ 6 | 7 | #include "../int_lib.h" 8 | 9 | float __floatdisf(int64_t a) 10 | { 11 | return (float)a; 12 | } 13 | 14 | #endif /* __x86_64__ */ 15 | -------------------------------------------------------------------------------- /test/asan/TestCases/Android/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | if root.android != "1": 9 | config.unsupported = True 10 | 11 | config.substitutions.append( ("%device", "/data/local/tmp/Output") ) 12 | -------------------------------------------------------------------------------- /test/asan/TestCases/sleep_before_dying.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: %env_asan_opts=sleep_before_dying=1 not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | int main() { 6 | char *x = (char*)malloc(10 * sizeof(char)); 7 | free(x); 8 | return x[5]; 9 | // CHECK: Sleeping for 1 second 10 | } 11 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/strpbrk.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang %s -o %t && %run %t 2>&1 2 | 3 | #include 4 | #include 5 | 6 | 7 | int main(int argc, char **argv) { 8 | char *r = 0; 9 | char s1[] = "ad"; 10 | char s2[] = "cd"; 11 | r = strpbrk(s1, s2); 12 | assert(r == s1 + 1); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /lib/builtins/macho_embedded/thumb2.txt: -------------------------------------------------------------------------------- 1 | switch16 2 | switch32 3 | switch8 4 | switchu8 5 | sync_fetch_and_add_4 6 | sync_fetch_and_sub_4 7 | sync_fetch_and_and_4 8 | sync_fetch_and_or_4 9 | sync_fetch_and_xor_4 10 | sync_fetch_and_nand_4 11 | sync_fetch_and_max_4 12 | sync_fetch_and_umax_4 13 | sync_fetch_and_min_4 14 | sync_fetch_and_umin_4 15 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/initialization-nobug-extra.cc: -------------------------------------------------------------------------------- 1 | // Linker initialized: 2 | int getAB(); 3 | static int ab = getAB(); 4 | // Function local statics: 5 | int countCalls(); 6 | static int one = countCalls(); 7 | // Trivial constructor, non-trivial destructor: 8 | int getStructWithDtorValue(); 9 | static int val = getStructWithDtorValue(); 10 | -------------------------------------------------------------------------------- /test/asan/TestCases/asan_and_llvm_coverage_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -coverage -O0 %s -o %t 2 | // RUN: %env_asan_opts=check_initialization_order=1 %run %t 2>&1 | FileCheck %s 3 | // XFAIL: android,win32 4 | #include 5 | int foo() { return 1; } 6 | int XXX = foo(); 7 | int main() { 8 | printf("PASS\n"); 9 | // CHECK: PASS 10 | } 11 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Linux/clock_gettime.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang %s -Wl,-as-needed -o %t && %run %t 2 | // Regression test for PR15823 3 | // (http://llvm.org/bugs/show_bug.cgi?id=15823). 4 | #include 5 | #include 6 | 7 | int main() { 8 | struct timespec ts; 9 | clock_gettime(CLOCK_REALTIME, &ts); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Compiler-RT 2 | ================================ 3 | 4 | This directory and its subdirectories contain source code for the compiler 5 | support routines. 6 | 7 | Compiler-RT is open source software. You may freely distribute it under the 8 | terms of the license agreement found in LICENSE.txt. 9 | 10 | ================================ 11 | 12 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/asan_default_suppressions.cc: -------------------------------------------------------------------------------- 1 | // Test that we use the suppressions from __asan_default_suppressions. 2 | // RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s 3 | extern "C" { 4 | const char *__asan_default_suppressions() { return "FooBar"; } 5 | } 6 | // CHECK: AddressSanitizer: failed to parse suppressions 7 | int main() {} 8 | -------------------------------------------------------------------------------- /test/msan/Linux/mallinfo.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 2 | // REQUIRES: stable-runtime 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | int main(void) { 10 | struct mallinfo mi = mallinfo(); 11 | assert(__msan_test_shadow(&mi, sizeof(mi)) == -1); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/global_const_string.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: %run %t | FileCheck %s 3 | 4 | #include 5 | #include 6 | 7 | int main(void) { 8 | static const char *foo = "foobarspam"; 9 | printf("Global string is `%s`\n", foo); 10 | // CHECK: Global string is `foobarspam` 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/asan/TestCases/interface_test.cc: -------------------------------------------------------------------------------- 1 | // Check that user may include ASan interface header. 2 | // RUN: %clang_asan %s -o %t && %run %t 3 | // RUN: %clang_asan -x c %s -o %t && %run %t 4 | // RUN: %clang %s -pie -o %t && %run %t 5 | // RUN: %clang -x c %s -pie -o %t && %run %t 6 | #include 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/strerror_r_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && %run %t 2 | 3 | // Regression test for PR17138. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | char buf[1024]; 11 | char *res = (char *)strerror_r(300, buf, sizeof(buf)); 12 | printf("%p\n", res); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/cfi/README.txt: -------------------------------------------------------------------------------- 1 | The tests in this directory use a common convention for exercising the 2 | functionality associated with bit sets of different sizes. When certain 3 | macros are defined the tests instantiate classes that force the bit sets 4 | to be of certain sizes. 5 | 6 | - B32 forces 32-bit bit sets. 7 | - B64 forces 64-bit bit sets. 8 | - BM forces memory bit sets. 9 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Linux/mlock_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang %s -o %t && %run %t 2 | // XFAIL: lsan 3 | 4 | #include 5 | #include 6 | 7 | int main() { 8 | assert(0 == mlockall(MCL_CURRENT)); 9 | assert(0 == mlock((void *)0x12345, 0x5678)); 10 | assert(0 == munlockall()); 11 | assert(0 == munlock((void *)0x987, 0x654)); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lib/builtins/x86_64/floatdidf.c: -------------------------------------------------------------------------------- 1 | /* This file is distributed under the University of Illinois Open Source 2 | * License. See LICENSE.TXT for details. 3 | */ 4 | 5 | /* double __floatdidf(di_int a); */ 6 | 7 | #ifdef __x86_64__ 8 | 9 | #include "../int_lib.h" 10 | 11 | double __floatdidf(int64_t a) 12 | { 13 | return (double)a; 14 | } 15 | 16 | #endif /* __x86_64__ */ 17 | -------------------------------------------------------------------------------- /lib/tsan/tests/unit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TSAN_UNIT_TEST_SOURCES 2 | tsan_clock_test.cc 3 | tsan_flags_test.cc 4 | tsan_mman_test.cc 5 | tsan_mutex_test.cc 6 | tsan_shadow_test.cc 7 | tsan_stack_test.cc 8 | tsan_sync_test.cc 9 | tsan_unit_test_main.cc 10 | tsan_vector_test.cc) 11 | 12 | add_tsan_unittest(TsanUnitTest 13 | SOURCES ${TSAN_UNIT_TEST_SOURCES}) 14 | -------------------------------------------------------------------------------- /test/asan/TestCases/use-after-scope-nobug.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && %run %t 2 | // XFAIL: * 3 | 4 | #include 5 | 6 | int main() { 7 | int *p = 0; 8 | // Variable goes in and out of scope. 9 | for (int i = 0; i < 3; i++) { 10 | int x = 0; 11 | p = &x; 12 | } 13 | printf("PASSED\n"); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/safestack/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | ## Autogenerated by LLVM/Clang configuration. 2 | # Do not edit! 3 | 4 | # Load common config for all compiler-rt lit tests. 5 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 6 | 7 | # Load tool-specific config that would do the real work. 8 | lit_config.load_config(config, "@SAFESTACK_LIT_SOURCE_DIR@/lit.cfg") 9 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Linux/sched_getparam.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -O0 %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main(void) { 8 | struct sched_param param; 9 | int res = sched_getparam(0, ¶m); 10 | assert(res == 0); 11 | if (param.sched_priority == 42) printf(".\n"); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/msan/errno.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int x; 11 | int *volatile p = &x; 12 | errno = *p; 13 | int res = read(-1, 0, 0); 14 | assert(res == -1); 15 | if (errno) printf("errno %d\n", errno); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/msan/tzset.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | extern char *tzname[2]; 8 | 9 | int main(void) { 10 | if (!strlen(tzname[0]) || !strlen(tzname[1])) 11 | exit(1); 12 | tzset(); 13 | if (!strlen(tzname[0]) || !strlen(tzname[1])) 14 | exit(1); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /lib/builtins/x86_64/floatdixf.c: -------------------------------------------------------------------------------- 1 | /* This file is distributed under the University of Illinois Open Source 2 | * License. See LICENSE.TXT for details. 3 | */ 4 | 5 | /* long double __floatdixf(di_int a); */ 6 | 7 | #ifdef __x86_64__ 8 | 9 | #include "../int_lib.h" 10 | 11 | long double __floatdixf(int64_t a) 12 | { 13 | return (long double)a; 14 | } 15 | 16 | #endif /* __i386__ */ 17 | -------------------------------------------------------------------------------- /test/msan/icmp_slt_allones.cc: -------------------------------------------------------------------------------- 1 | // PR24561 2 | // RUN: %clangxx_msan -O2 -g %s -o %t && %run %t 3 | 4 | #include 5 | 6 | struct A { 7 | int c1 : 7; 8 | int c8 : 1; 9 | int c9 : 1; 10 | A(); 11 | }; 12 | 13 | __attribute__((noinline)) A::A() : c8(1) {} 14 | 15 | int main() { 16 | A* a = new A(); 17 | if (a->c8 == 0) 18 | printf("zz\n"); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Integer/div-overflow.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s 2 | 3 | #include 4 | 5 | int main() { 6 | unsigned(0x80000000) / -1; 7 | 8 | // CHECK: div-overflow.cpp:9:23: runtime error: division of -2147483648 by -1 cannot be represented in type 'int' 9 | int32_t(0x80000000) / -1; 10 | } 11 | -------------------------------------------------------------------------------- /test/BlocksRuntime/macro.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | // CONFIG open rdar://6718399 8 | #include 9 | 10 | void foo() { 11 | void (^bbb)(void) = Block_copy(^ { 12 | int j, cnt; 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /test/lsan/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 3 | 4 | # Tool-specific config options. 5 | config.lsan_lit_test_mode = "@LSAN_LIT_TEST_MODE@" 6 | 7 | # Load tool-specific config that would do the real work. 8 | lit_config.load_config(config, "@LSAN_LIT_SOURCE_DIR@/lit.common.cfg") 9 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/freopen.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && %run %t 2 | 3 | // This fails on i386 Linux due to a glibc versioned symbols mixup. 4 | // REQUIRES: asan-64-bits 5 | 6 | #include 7 | #include 8 | 9 | int main() { 10 | FILE *fp = fopen("/dev/null", "w"); 11 | assert(fp); 12 | freopen(NULL, "a", fp); 13 | fclose(fp); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/asan/TestCases/force_inline_opt0.cc: -------------------------------------------------------------------------------- 1 | // This test checks that we are no instrumenting a memory access twice 2 | // (before and after inlining) 3 | // RUN: %clangxx_asan -O1 %s -o %t && %run %t 4 | // RUN: %clangxx_asan -O0 %s -o %t && %run %t 5 | __attribute__((always_inline)) 6 | void foo(int *x) { 7 | *x = 0; 8 | } 9 | 10 | int main() { 11 | int x; 12 | foo(&x); 13 | return x; 14 | } 15 | -------------------------------------------------------------------------------- /test/builtins/Unit/ppc/test: -------------------------------------------------------------------------------- 1 | for FILE in $(ls *.c); do 2 | if gcc -arch ppc -O0 $FILE ../../../Release/ppc/libcompiler_rt.Optimized.a -mlong-double-128 3 | then 4 | echo "Testing $FILE" 5 | if ./a.out 6 | then 7 | rm ./a.out 8 | else 9 | echo "fail" 10 | # exit 1 11 | fi 12 | else 13 | echo "$FILE failed to compile" 14 | # exit 1 15 | fi 16 | done 17 | echo "pass" 18 | exit 19 | -------------------------------------------------------------------------------- /test/msan/initgroups.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include // FreeBSD declares initgroups() here. 6 | 7 | int main(void) { 8 | initgroups("root", 0); 9 | // The above fails unless you are root. Does not matter, MSan false positive 10 | // (which we are testing for) happens anyway. 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/corelimit.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -O0 %s -o %t && %run %t 2 | // XFAIL: lsan 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | int main() { 9 | struct rlimit lim_core; 10 | getrlimit(RLIMIT_CORE, &lim_core); 11 | void *p; 12 | if (sizeof(p) == 8) { 13 | assert(0 == lim_core.rlim_max); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/tsan/bench_acquire_release.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | #include "bench.h" 5 | 6 | int x; 7 | 8 | void thread(int tid) { 9 | for (int i = 0; i < bench_niter; i++) 10 | __atomic_fetch_add(&x, 1, __ATOMIC_ACQ_REL); 11 | } 12 | 13 | void bench() { 14 | start_thread_group(bench_nthread, thread); 15 | } 16 | 17 | // CHECK: DONE 18 | 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/Darwin/empty-section.cc: -------------------------------------------------------------------------------- 1 | // Regression test with an empty (length = 0) custom section. 2 | 3 | // RUN: %clangxx_asan -g -O0 %s -c -o %t.o 4 | // RUN: %clangxx_asan -g -O0 %t.o -o %t -sectcreate mysegment mysection /dev/null 5 | // RUN: %run %t 2>&1 | FileCheck %s 6 | 7 | #include 8 | 9 | int main() { 10 | printf("Hello, world!\n"); 11 | // CHECK: Hello, world! 12 | } 13 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/use_after_return_linkage.cc: -------------------------------------------------------------------------------- 1 | // Make sure LIBCMT doesn't accidentally get added to the list of DEFAULTLIB 2 | // directives. REQUIRES: asan-dynamic-runtime 3 | // RUN: %clang_cl_asan -LD %s | FileCheck %s 4 | // CHECK: Creating library 5 | // CHECK-NOT: LIBCMT 6 | 7 | void foo(int *p) { *p = 42; } 8 | 9 | __declspec(dllexport) void bar() { 10 | int x; 11 | foo(&x); 12 | } 13 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/TypeCheck/vptr-virtual-base-construction.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr %s -o %t 2 | // RUN: %run %t 3 | 4 | // REQUIRES: cxxabi 5 | 6 | int volatile n; 7 | 8 | struct A { virtual ~A() {} }; 9 | struct B: virtual A {}; 10 | struct C: virtual A { ~C() { n = 0; } }; 11 | struct D: virtual B, virtual C {}; 12 | 13 | int main() { delete new D; } 14 | -------------------------------------------------------------------------------- /test/msan/strxfrm.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) { 9 | const char *p = "abcdef"; 10 | char q[10]; 11 | size_t n = strxfrm(q, p, sizeof(q)); 12 | assert(n < sizeof(q)); 13 | __msan_check_mem_is_initialized(q, n + 1); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/tsan/thread_leak.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | void *Thread(void *x) { 6 | return 0; 7 | } 8 | 9 | int main() { 10 | pthread_t t; 11 | pthread_create(&t, 0, Thread, 0); 12 | pthread_join(t, 0); 13 | printf("PASS\n"); 14 | return 0; 15 | } 16 | 17 | // CHECK-NOT: WARNING: ThreadSanitizer: thread leak 18 | -------------------------------------------------------------------------------- /test/tsan/thread_leak2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | void *Thread(void *x) { 6 | return 0; 7 | } 8 | 9 | int main() { 10 | pthread_t t; 11 | pthread_create(&t, 0, Thread, 0); 12 | pthread_detach(t); 13 | printf("PASS\n"); 14 | return 0; 15 | } 16 | 17 | // CHECK-NOT: WARNING: ThreadSanitizer: thread leak 18 | -------------------------------------------------------------------------------- /make/platform/multi_arch.mk: -------------------------------------------------------------------------------- 1 | Description := Example configuration for build two libraries for separate \ 2 | architectures. 3 | 4 | Configs := m32 m64 5 | Arch := i386 6 | Arch.m64 := x86_64 7 | 8 | CC := clang 9 | 10 | CFLAGS := -Wall -Werror 11 | CFLAGS.m32 := $(CFLAGS) -m32 -O3 12 | CFLAGS.m64 := $(CFLAGS) -m64 -O3 13 | 14 | FUNCTIONS := moddi3 floatundixf udivdi3 15 | FUNCTIONS.m64 := $(FUNCTIONS) lshrdi3 16 | -------------------------------------------------------------------------------- /test/asan/TestCases/default_options.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O2 %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | const char *kAsanDefaultOptions="verbosity=1 help=1"; 5 | 6 | extern "C" 7 | __attribute__((no_sanitize_address)) 8 | const char *__asan_default_options() { 9 | // CHECK: Available flags for AddressSanitizer: 10 | return kAsanDefaultOptions; 11 | } 12 | 13 | int main() { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/msan/ftime.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 2 | 3 | // ftime() is deprecated on FreeBSD. 4 | // XFAIL: freebsd 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | int main(void) { 12 | struct timeb tb; 13 | int res = ftime(&tb); 14 | assert(!res); 15 | assert(__msan_test_shadow(&tb, sizeof(tb)) == -1); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/tsan/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | ## Autogenerated by LLVM/Clang configuration. 2 | # Do not edit! 3 | 4 | config.has_libcxx = @TSAN_HAS_LIBCXX@ 5 | 6 | # Load common config for all compiler-rt lit tests. 7 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 8 | 9 | # Load tool-specific config that would do the real work. 10 | lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg") 11 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/strcasestr.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang %s -o %t && %run %t 2>&1 2 | 3 | // There's no interceptor for strcasestr on Windows 4 | // XFAIL: win32 5 | 6 | #define _GNU_SOURCE 7 | #include 8 | #include 9 | int main(int argc, char **argv) { 10 | char *r = 0; 11 | char s1[] = "aB"; 12 | char s2[] = "b"; 13 | r = strcasestr(s1, s2); 14 | assert(r == s1 + 1); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/lsan/TestCases/new_array_with_dtor_0.cc: -------------------------------------------------------------------------------- 1 | // Regression test: 2 | // https://code.google.com/p/address-sanitizer/issues/detail?id=257 3 | // RUN: %clangxx_lsan %s -o %t && %run %t 2>&1 | FileCheck %s 4 | 5 | #include 6 | 7 | struct T { 8 | ~T() { printf("~T\n"); } 9 | }; 10 | 11 | T *t; 12 | 13 | int main(int argc, char **argv) { 14 | t = new T[argc - 1]; 15 | printf("OK\n"); 16 | } 17 | 18 | // CHECK: OK 19 | 20 | -------------------------------------------------------------------------------- /test/tsan/thread_leak4.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *x) { 5 | sleep(100); // leave the thread "running" 6 | return 0; 7 | } 8 | 9 | int main() { 10 | pthread_t t; 11 | pthread_create(&t, 0, Thread, 0); 12 | printf("DONE\n"); 13 | return 0; 14 | } 15 | 16 | // CHECK: DONE 17 | // CHECK-NOT: WARNING: ThreadSanitizer: thread leak 18 | 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/frexp_interceptor.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | 3 | // Test the frexp() interceptor. 4 | 5 | #include 6 | #include 7 | #include 8 | int main() { 9 | double x = 3.14; 10 | int *exp = (int*)malloc(sizeof(int)); 11 | free(exp); 12 | double y = frexp(x, exp); 13 | // CHECK: use-after-free 14 | // CHECK: SUMMARY 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/tsan/bench_acquire_only.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | #include "bench.h" 5 | 6 | int x; 7 | 8 | void thread(int tid) { 9 | for (int i = 0; i < bench_niter; i++) 10 | __atomic_load_n(&x, __ATOMIC_ACQUIRE); 11 | } 12 | 13 | void bench() { 14 | __atomic_store_n(&x, 0, __ATOMIC_RELEASE); 15 | start_thread_group(bench_nthread, thread); 16 | } 17 | 18 | // CHECK: DONE 19 | 20 | -------------------------------------------------------------------------------- /test/tsan/thread_end_with_ignore2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l); 3 | 4 | int main() { 5 | AnnotateIgnoreWritesBegin("", 0); 6 | } 7 | 8 | // CHECK: ThreadSanitizer: main thread finished with ignores enabled 9 | // CHECK: Ignore was enabled at: 10 | // CHECK: #0 AnnotateIgnoreWritesBegin 11 | // CHECK: #1 main 12 | 13 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/globals-gc-sections.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan %s -o %t -Wl,--gc-sections -ffunction-sections -mllvm -asan-globals=0 2 | // RUN: %clangxx_asan %s -o %t -Wl,--gc-sections -ffunction-sections -mllvm -asan-globals=1 3 | 4 | // https://code.google.com/p/address-sanitizer/issues/detail?id=260 5 | // XFAIL: * 6 | 7 | int undefined(); 8 | 9 | int (*unused)() = undefined; 10 | 11 | int main() { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/asan/TestCases/lsan_annotations.cc: -------------------------------------------------------------------------------- 1 | // Check that LSan annotations work fine. 2 | // RUN: %clangxx_asan -O0 %s -o %t && %run %t 3 | // RUN: %clangxx_asan -O3 %s -o %t && %run %t 4 | 5 | #include 6 | #include 7 | 8 | int main() { 9 | int *x = new int; 10 | __lsan_ignore_object(x); 11 | { 12 | __lsan::ScopedDisabler disabler; 13 | double *y = new double; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/on_error_callback.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | 3 | #include 4 | #include 5 | 6 | extern "C" 7 | void __asan_on_error() { 8 | fprintf(stderr, "__asan_on_error called\n"); 9 | fflush(stderr); 10 | } 11 | 12 | int main() { 13 | char *x = (char*)malloc(10 * sizeof(char)); 14 | free(x); 15 | return x[5]; 16 | // CHECK: __asan_on_error called 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/bitfield.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: %run %t 3 | 4 | #include 5 | 6 | typedef struct _S { 7 | unsigned int bf1:1; 8 | unsigned int bf2:2; 9 | unsigned int bf3:3; 10 | unsigned int bf4:4; 11 | } S; 12 | 13 | int main(void) { 14 | S *s = (S*)malloc(sizeof(S)); 15 | s->bf1 = 1; 16 | s->bf2 = 2; 17 | s->bf3 = 3; 18 | s->bf4 = 4; 19 | free(s); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/msan/test.h: -------------------------------------------------------------------------------- 1 | #if __LP64__ 2 | # define SANITIZER_WORDSIZE 64 3 | #else 4 | # define SANITIZER_WORDSIZE 32 5 | #endif 6 | 7 | // This is a simplified version of GetMaxVirtualAddress function. 8 | unsigned long SystemVMA () { 9 | #if SANITIZER_WORDSIZE == 64 10 | unsigned long vma = (unsigned long)__builtin_frame_address(0); 11 | return SANITIZER_WORDSIZE - __builtin_clzll(vma); 12 | #else 13 | return SANITIZER_WORDSIZE; 14 | #endif 15 | } 16 | -------------------------------------------------------------------------------- /test/BlocksRuntime/modglobal.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | #include 7 | 8 | // CONFIG 9 | 10 | int AGlobal; 11 | 12 | int main(int argc, char *argv[]) { 13 | void (^f)(void) = ^ { AGlobal++; }; 14 | 15 | printf("%s: success\n", argv[0]); 16 | return 0; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/operator_delete_wrong_argument.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | int *x = new int[42]; 8 | delete (x + 1); 9 | // CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed 10 | // CHECK: {{#0 0x.* operator delete}} 11 | // CHECK: {{#1 .* main .*operator_delete_wrong_argument.cc}}:[[@LINE-3]] 12 | } 13 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/lit.local.cfg: -------------------------------------------------------------------------------- 1 | def getRoot(config): 2 | if not config.parent: 3 | return config 4 | return getRoot(config.parent) 5 | 6 | root = getRoot(config) 7 | 8 | # We only run a small set of tests on Windows for now. 9 | # Override the parent directory's "unsupported" decision until we can handle 10 | # all of its tests. 11 | if root.host_os in ['Windows']: 12 | config.unsupported = False 13 | else: 14 | config.unsupported = True 15 | -------------------------------------------------------------------------------- /test/asan/TestCases/no_asan_gen_globals.c: -------------------------------------------------------------------------------- 1 | // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 2 | // XFAIL: android 3 | // FIXME: http://llvm.org/bugs/show_bug.cgi?id=22682 4 | // REQUIRES: asan-64-bits 5 | // 6 | // Make sure __asan_gen_* strings do not end up in the symbol table. 7 | 8 | // RUN: %clang_asan %s -o %t.exe 9 | // RUN: nm %t.exe | FileCheck %s 10 | 11 | int x, y, z; 12 | int main() { return 0; } 13 | // CHECK-NOT: __asan_gen_ 14 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/asan_dlopen_test.cc: -------------------------------------------------------------------------------- 1 | // Test that dlopen of dynamic runtime is prohibited. 2 | // 3 | // RUN: %clangxx %s -DRT=\"%shared_libasan\" -o %t -ldl 4 | // RUN: not %run %t 2>&1 | FileCheck %s 5 | // REQUIRES: asan-dynamic-runtime 6 | // XFAIL: android 7 | 8 | #include 9 | 10 | int main(int argc, char **argv) { 11 | dlopen(RT, RTLD_LAZY); 12 | return 0; 13 | } 14 | 15 | // CHECK: ASan runtime does not come first in initial library list 16 | -------------------------------------------------------------------------------- /test/asan/TestCases/strip_path_prefix.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: %env_asan_opts=strip_path_prefix='"%S/"' not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | int main() { 6 | char *x = (char*)malloc(10 * sizeof(char)); 7 | free(x); 8 | return x[5]; 9 | // Check that paths in error report don't start with slash. 10 | // CHECK: heap-use-after-free 11 | // CHECK: #0 0x{{.*}} in main {{.*}}strip_path_prefix.c:[[@LINE-3]] 12 | } 13 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/initialization-blacklist-extra.cc: -------------------------------------------------------------------------------- 1 | int zero_init() { return 0; } 2 | int badGlobal = zero_init(); 3 | int readBadGlobal() { return badGlobal; } 4 | 5 | namespace badNamespace { 6 | class BadClass { 7 | public: 8 | BadClass() { value = 0; } 9 | int value; 10 | }; 11 | // Global object with non-trivial constructor. 12 | BadClass bad_object; 13 | } // namespace badNamespace 14 | 15 | int accessBadObject() { return badNamespace::bad_object.value; } 16 | -------------------------------------------------------------------------------- /test/msan/Linux/tcgetattr.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t %p 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char *argv[]) { 11 | int fd = getpt(); 12 | assert(fd >= 0); 13 | 14 | struct termios t; 15 | int res = tcgetattr(fd, &t); 16 | assert(!res); 17 | 18 | if (t.c_iflag == 0) 19 | exit(0); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/msan/times.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | int main(void) { 10 | struct tms t; 11 | clock_t res = times(&t); 12 | assert(res != (clock_t)-1); 13 | 14 | if (t.tms_utime) printf("1\n"); 15 | if (t.tms_stime) printf("2\n"); 16 | if (t.tms_cutime) printf("3\n"); 17 | if (t.tms_cstime) printf("4\n"); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/alloca_safe_access.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t 2 | // RUN: %run %t 2>&1 3 | // 4 | 5 | #include 6 | 7 | __attribute__((noinline)) void foo(int index, int len) { 8 | volatile char str[len] __attribute__((aligned(32))); 9 | assert(!(reinterpret_cast(str) & 31L)); 10 | str[index] = '1'; 11 | } 12 | 13 | int main(int argc, char **argv) { 14 | foo(4, 5); 15 | foo(39, 40); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/msan/inline.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O3 %s -o %t && %run %t 2 | 3 | // Test that no_sanitize_memory attribute applies even when the function would 4 | // be normally inlined. 5 | 6 | #include 7 | 8 | __attribute__((no_sanitize_memory)) 9 | int f(int *p) { 10 | if (*p) // BOOOM?? Nope! 11 | exit(0); 12 | return 0; 13 | } 14 | 15 | int main(int argc, char **argv) { 16 | int x; 17 | int * volatile p = &x; 18 | int res = f(p); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/profile/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | ## Autogenerated by LLVM/Clang configuration. 2 | # Do not edit! 3 | 4 | # Tool-specific config options. 5 | config.profile_lit_binary_dir = "@PROFILE_LIT_BINARY_DIR@" 6 | 7 | # Load common config for all compiler-rt lit tests. 8 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 9 | 10 | # Load tool-specific config that would do the real work. 11 | lit_config.load_config(config, "@PROFILE_LIT_SOURCE_DIR@/lit.cfg") 12 | -------------------------------------------------------------------------------- /lib/tsan/tests/rtl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TSAN_RTL_TEST_SOURCES 2 | tsan_bench.cc 3 | tsan_mop.cc 4 | tsan_mutex.cc 5 | tsan_posix.cc 6 | tsan_string.cc 7 | tsan_test.cc 8 | tsan_thread.cc) 9 | 10 | if(UNIX AND NOT APPLE) 11 | list(APPEND TSAN_RTL_TEST_SOURCES tsan_test_util_linux.cc) 12 | endif() 13 | 14 | set(TSAN_RTL_TEST_HEADERS 15 | tsan_test_util.h) 16 | 17 | add_tsan_unittest(TsanRtlTest 18 | SOURCES ${TSAN_RTL_TEST_SOURCES} 19 | HEADERS ${TSAN_RTL_TEST_HEADERS}) 20 | -------------------------------------------------------------------------------- /make/platform/clang_darwin_test_input.c: -------------------------------------------------------------------------------- 1 | /* Include the headers we use in int_lib.h, to verify that they work. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | // Force us to link at least one symbol in a system library 10 | // to detect systems where we don't have those for a given 11 | // architecture. 12 | int main(int argc, const char **argv) { 13 | int x; 14 | memcpy(&x,&argc,sizeof(int)); 15 | } 16 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/asan_rt_confict_test-1.cc: -------------------------------------------------------------------------------- 1 | // Test that preloading dynamic runtime to statically sanitized 2 | // executable is prohibited. 3 | // 4 | // RUN: %clangxx_asan_static %s -o %t 5 | // RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s 6 | 7 | // REQUIRES: asan-dynamic-runtime 8 | // XFAIL: android 9 | 10 | #include 11 | int main(int argc, char **argv) { return 0; } 12 | 13 | // CHECK: Your application is linked against incompatible ASan runtimes 14 | -------------------------------------------------------------------------------- /test/tsan/thread_detach.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *x) { 5 | barrier_wait(&barrier); 6 | return 0; 7 | } 8 | 9 | int main() { 10 | barrier_init(&barrier, 2); 11 | pthread_t t; 12 | pthread_create(&t, 0, Thread, 0); 13 | barrier_wait(&barrier); 14 | pthread_detach(t); 15 | printf("PASS\n"); 16 | return 0; 17 | } 18 | 19 | // CHECK-NOT: WARNING: ThreadSanitizer: thread leak 20 | // CHECK: PASS 21 | -------------------------------------------------------------------------------- /test/msan/dlerror.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | // 3 | // AArch64 shows fails with uninitialized bytes in __interceptor_strcmp from 4 | // dlfcn/dlerror.c:107 (glibc). 5 | // XFAIL: aarch64 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main(void) { 13 | void *p = dlopen("/bad/file/name", RTLD_NOW); 14 | assert(!p); 15 | char *s = dlerror(); 16 | printf("%s, %zu\n", s, strlen(s)); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/10.4-x86_64.txt: -------------------------------------------------------------------------------- 1 | absvti2 2 | addvti3 3 | ashlti3 4 | ashrti3 5 | clzti2 6 | cmpti2 7 | ctzti2 8 | divti3 9 | ffsti2 10 | fixdfti 11 | fixsfti 12 | fixunsdfti 13 | fixunssfti 14 | fixunsxfti 15 | fixxfti 16 | floattidf 17 | floattisf 18 | floattixf 19 | floatuntidf 20 | floatuntisf 21 | floatuntixf 22 | lshrti3 23 | modti3 24 | muloti4 25 | multi3 26 | mulvti3 27 | negti2 28 | negvti2 29 | parityti2 30 | popcountti2 31 | subvti3 32 | ucmpti2 33 | udivmodti4 34 | udivti3 35 | umodti3 36 | -------------------------------------------------------------------------------- /test/tsan/deflake.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script is used to deflake inherently flaky tsan tests. 3 | # It is invoked from lit tests as: 4 | # %deflake mybinary 5 | # which is then substituted by lit to: 6 | # $(dirname %s)/deflake.bash mybinary 7 | # The script runs the target program up to 10 times, 8 | # until it fails (i.e. produces a race report). 9 | 10 | for i in $(seq 1 10); do 11 | OUT=`$@ 2>&1` 12 | if [[ $? != 0 ]]; then 13 | echo "$OUT" 14 | exit 0 15 | fi 16 | done 17 | exit 1 18 | -------------------------------------------------------------------------------- /test/BlocksRuntime/c99.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | // 8 | // c99.m 9 | // 10 | // CONFIG C99 rdar://problem/6399225 11 | 12 | #import 13 | #import 14 | 15 | int main(int argc, char *argv[]) { 16 | void (^blockA)(void) = ^ { ; }; 17 | blockA(); 18 | printf("%s: success\n", argv[0]); 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/inline.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O3 %s -o %t && %run %t 2 | 3 | // Test that no_sanitize_address attribute applies even when the function would 4 | // be normally inlined. 5 | 6 | #include 7 | 8 | __attribute__((no_sanitize_address)) 9 | int f(int *p) { 10 | return *p; // BOOOM?? Nope! 11 | } 12 | 13 | int main(int argc, char **argv) { 14 | int * volatile x = (int*)malloc(2*sizeof(int) + 2); 15 | int res = f(x + 2); 16 | if (res) 17 | exit(0); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/msan/ioctl.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 2 | // RUN: %clangxx_msan -O3 -g %s -o %t && %run %t 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char **argv) { 11 | int fd = socket(AF_INET, SOCK_DGRAM, 0); 12 | 13 | unsigned int z; 14 | int res = ioctl(fd, FIOGETOWN, &z); 15 | assert(res == 0); 16 | close(fd); 17 | if (z) 18 | exit(0); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/ubsan/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 3 | 4 | # Tool-specific config options. 5 | config.ubsan_lit_test_mode = "@UBSAN_LIT_TEST_MODE@" 6 | config.target_cflags = "@UBSAN_TEST_TARGET_CFLAGS@" 7 | config.target_arch = "@UBSAN_TEST_TARGET_ARCH@" 8 | 9 | # Load tool-specific config that would do the real work. 10 | lit_config.load_config(config, "@UBSAN_LIT_TESTS_DIR@/lit.common.cfg") 11 | -------------------------------------------------------------------------------- /test/BlocksRuntime/flagsisa.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | #include 8 | 9 | /* CONFIG rdar://6310599 10 | */ 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | __block int flags; 15 | __block void *isa; 16 | 17 | ^{ flags=1; isa = (void *)isa; }; 18 | printf("%s: success\n", argv[0]); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /test/msan/rand_r.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 2 | // RUN: %clangxx_msan -O0 -g -DUNINIT %s -o %t && not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) { 9 | unsigned seed; 10 | #ifndef UNINIT 11 | seed = 42; 12 | #endif 13 | int v = rand_r(&seed); 14 | // CHECK: MemorySanitizer: use-of-uninitialized-value 15 | // CHECK: in main{{.*}}rand_r.cc:[[@LINE-2]] 16 | if (v) printf(".\n"); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/tsan/tiny_race.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | int Global; 5 | 6 | void *Thread1(void *x) { 7 | barrier_wait(&barrier); 8 | Global = 42; 9 | return x; 10 | } 11 | 12 | int main() { 13 | barrier_init(&barrier, 2); 14 | pthread_t t; 15 | pthread_create(&t, 0, Thread1, 0); 16 | Global = 43; 17 | barrier_wait(&barrier); 18 | pthread_join(t, 0); 19 | return Global; 20 | } 21 | 22 | // CHECK: WARNING: ThreadSanitizer: data race 23 | -------------------------------------------------------------------------------- /test/msan/memcmp_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // RUN: MSAN_OPTIONS=intercept_memcmp=0 %run %t 4 | 5 | #include 6 | int main(int argc, char **argv) { 7 | char a1[4]; 8 | char a2[4]; 9 | for (int i = 0; i < argc * 3; i++) 10 | a2[i] = a1[i] = i; 11 | int res = memcmp(a1, a2, 4); 12 | return res; 13 | // CHECK: Uninitialized bytes in __interceptor_memcmp at offset 3 14 | // CHECK: MemorySanitizer: use-of-uninitialized-value 15 | } 16 | -------------------------------------------------------------------------------- /lib/tsan/check_cmake.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -u 3 | set -e 4 | 5 | ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 6 | if [ -d "$ROOT/llvm-build" ]; then 7 | cd $ROOT/llvm-build 8 | else 9 | mkdir -p $ROOT/llvm-build 10 | cd $ROOT/llvm-build 11 | CC=clang CXX=clang++ cmake -G Ninja -DLLVM_ENABLE_WERROR=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON $ROOT/../../../.. 12 | fi 13 | ninja 14 | ninja check-sanitizer 15 | ninja check-tsan 16 | ninja check-asan 17 | ninja check-msan 18 | ninja check-lsan 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/Darwin/asan_gen_prefixes.cc: -------------------------------------------------------------------------------- 1 | // Make sure __asan_gen_* strings have the correct prefixes on Darwin 2 | // ("L" in __TEXT,__cstring, "l" in __TEXT,__const 3 | 4 | // RUN: %clang_asan %s -S -o %t.s 5 | // RUN: cat %t.s | FileCheck %s || exit 1 6 | 7 | int x, y, z; 8 | int main() { return 0; } 9 | // CHECK: .section{{.*}}__TEXT,__const 10 | // CHECK: l___asan_gen_ 11 | // CHECK: .section{{.*}}__TEXT,__cstring,cstring_literals 12 | // CHECK: L___asan_gen_ 13 | // CHECK: L___asan_gen_ 14 | // CHECK: L___asan_gen_ 15 | -------------------------------------------------------------------------------- /test/msan/sem_getvalue.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main(void) { 8 | sem_t sem; 9 | int res = sem_init(&sem, 0, 42); 10 | assert(res == 0); 11 | 12 | int v; 13 | res = sem_getvalue(&sem, &v); 14 | assert(res == 0); 15 | __msan_check_mem_is_initialized(&v, sizeof(v)); 16 | assert(v == 42); 17 | 18 | res = sem_destroy(&sem); 19 | assert(res == 0); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/asan/TestCases/huge_negative_hea_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O %s -o %t && not %run %t 2>&1 | FileCheck %s 3 | // Check that we can find huge buffer overflows to the left. 4 | #include 5 | #include 6 | int main(int argc, char **argv) { 7 | char *x = (char*)malloc(1 << 20); 8 | memset(x, 0, 10); 9 | int res = x[-argc * 4000]; // BOOOM 10 | // CHECK: is located 4000 bytes to the left of 11 | free(x); 12 | return res; 13 | } 14 | -------------------------------------------------------------------------------- /test/msan/unpoison_string.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t 2 | // RUN: %run %t 3 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -O3 %s -o %t 4 | // RUN: %run %t 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char **argv) { 11 | char s[20] = "string"; 12 | __msan_poison(s, sizeof(s)); 13 | __msan_unpoison_string(s); 14 | assert(__msan_test_shadow(s, sizeof(s)) == strlen("string") + 1); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/tsan/atomic_free.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *a) { 5 | __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST); 6 | barrier_wait(&barrier); 7 | return 0; 8 | } 9 | 10 | int main() { 11 | barrier_init(&barrier, 2); 12 | int *a = new int(0); 13 | pthread_t t; 14 | pthread_create(&t, 0, Thread, a); 15 | barrier_wait(&barrier); 16 | delete a; 17 | pthread_join(t, 0); 18 | } 19 | 20 | // CHECK: WARNING: ThreadSanitizer: data race 21 | -------------------------------------------------------------------------------- /test/tsan/interface_atomic_test.c: -------------------------------------------------------------------------------- 1 | // Test that we can include header with TSan atomic interface. 2 | // RUN: %clang_tsan %s -o %t && %run %t | FileCheck %s 3 | #include 4 | #include 5 | 6 | int main() { 7 | __tsan_atomic32 a; 8 | __tsan_atomic32_store(&a, 100, __tsan_memory_order_release); 9 | int res = __tsan_atomic32_load(&a, __tsan_memory_order_acquire); 10 | if (res == 100) { 11 | // CHECK: PASS 12 | printf("PASS\n"); 13 | return 0; 14 | } 15 | return 1; 16 | } 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/leak.cc: -------------------------------------------------------------------------------- 1 | // Minimal test for LeakSanitizer+AddressSanitizer. 2 | // REQUIRES: leak-detection 3 | // 4 | // RUN: %clangxx_asan %s -o %t 5 | // RUN: %env_asan_opts=detect_leaks=1 not %run %t 2>&1 | FileCheck %s 6 | // RUN: not %run %t 2>&1 | FileCheck %s 7 | // RUN: %env_asan_opts=detect_leaks=0 %run %t 8 | #include 9 | int *t; 10 | 11 | int main(int argc, char **argv) { 12 | t = new int[argc - 1]; 13 | printf("t: %p\n", t); 14 | t = 0; 15 | } 16 | // CHECK: LeakSanitizer: detected memory leaks 17 | -------------------------------------------------------------------------------- /test/msan/strerror_r-non-gnu.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_msan -std=c99 -O0 -g %s -o %t && %run %t 2 | 3 | // strerror_r under a weird set of circumstances can be redirected to 4 | // __xpg_strerror_r. Test that MSan handles this correctly. 5 | 6 | #define _POSIX_C_SOURCE 200112 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main() { 13 | char buf[1000]; 14 | int res = strerror_r(EINVAL, buf, sizeof(buf)); 15 | assert(!res); 16 | volatile int z = strlen(buf); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/tsan/bench_single_writer.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | #include "bench.h" 5 | 6 | int x; 7 | 8 | void thread(int tid) { 9 | if (tid == 0) { 10 | for (int i = 0; i < bench_niter; i++) 11 | __atomic_store_n(&x, 0, __ATOMIC_RELEASE); 12 | } else { 13 | for (int i = 0; i < bench_niter; i++) 14 | __atomic_load_n(&x, __ATOMIC_ACQUIRE); 15 | } 16 | } 17 | 18 | void bench() { 19 | start_thread_group(bench_nthread, thread); 20 | } 21 | 22 | // CHECK: DONE 23 | 24 | -------------------------------------------------------------------------------- /test/tsan/printf-1.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS=check_printf=1 %run %t 2>&1 | FileCheck %s 3 | // RUN: ASAN_OPTIONS=check_printf=0 %run %t 2>&1 | FileCheck %s 4 | // RUN: %run %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | int main() { 8 | volatile char c = '0'; 9 | volatile int x = 12; 10 | volatile float f = 1.239; 11 | volatile char s[] = "34"; 12 | printf("%c %d %.3f %s\n", c, x, f, s); 13 | return 0; 14 | // Check that printf works fine under Tsan. 15 | // CHECK: 0 12 1.239 34 16 | } 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/rlimit_mmap_test.cc: -------------------------------------------------------------------------------- 1 | // Check that we properly report mmap failure. 2 | // RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static volatile void *x; 9 | 10 | int main(int argc, char **argv) { 11 | struct rlimit mmap_resource_limit = { 0, 0 }; 12 | assert(0 == setrlimit(RLIMIT_AS, &mmap_resource_limit)); 13 | x = malloc(10000000); 14 | // CHECK: ERROR: Failed to mmap 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/default_options.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O2 %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | // FIXME: merge this with the common default_options test when we can run common 5 | // tests on Windows. 6 | 7 | const char *kAsanDefaultOptions="verbosity=1 help=1"; 8 | 9 | extern "C" 10 | __attribute__((no_sanitize_address)) 11 | const char *__asan_default_options() { 12 | // CHECK: Available flags for AddressSanitizer: 13 | return kAsanDefaultOptions; 14 | } 15 | 16 | int main() { 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/msan/msan_print_shadow3.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t >%t.out 2>&1 2 | // RUN: FileCheck %s < %t.out 3 | 4 | #include 5 | #include 6 | 7 | int main(void) { 8 | unsigned long long x = 0; // For 8-byte alignment. 9 | uint32_t x_s = 0x12345678U; 10 | __msan_partial_poison(&x, &x_s, sizeof(x_s)); 11 | __msan_print_shadow(&x, sizeof(x_s)); 12 | return 0; 13 | } 14 | 15 | // CHECK: Shadow map of [{{.*}}), 4 bytes: 16 | // CHECK: 0x{{.*}}: 87654321 ........ ........ ........ 17 | -------------------------------------------------------------------------------- /test/tsan/atomic_free2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *a) { 5 | barrier_wait(&barrier); 6 | __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST); 7 | return 0; 8 | } 9 | 10 | int main() { 11 | barrier_init(&barrier, 2); 12 | int *a = new int(0); 13 | pthread_t t; 14 | pthread_create(&t, 0, Thread, a); 15 | delete a; 16 | barrier_wait(&barrier); 17 | pthread_join(t, 0); 18 | } 19 | 20 | // CHECK: WARNING: ThreadSanitizer: heap-use-after-free 21 | -------------------------------------------------------------------------------- /test/tsan/thread_leak3.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *x) { 5 | barrier_wait(&barrier); 6 | return 0; 7 | } 8 | 9 | int main() { 10 | barrier_init(&barrier, 2); 11 | pthread_t t; 12 | pthread_create(&t, 0, Thread, 0); 13 | barrier_wait(&barrier); 14 | sleep(1); // wait for the thread to finish and exit 15 | return 0; 16 | } 17 | 18 | // CHECK: WARNING: ThreadSanitizer: thread leak 19 | // CHECK: SUMMARY: ThreadSanitizer: thread leak{{.*}}main 20 | -------------------------------------------------------------------------------- /test/asan/TestCases/Posix/asprintf.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1 | FileCheck %s 3 | 4 | #ifndef _GNU_SOURCE 5 | #define _GNU_SOURCE 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | int main(int argc, char **argv) { 12 | char *p; 13 | int res = asprintf(&p, "%d", argc); 14 | fprintf(stderr, "x%d %sx\n", res, p); 15 | // CHECK: x1 1x 16 | free(p); 17 | fprintf(stderr, "DONE\n"); 18 | // CHECK: DONE 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/tsan/stack_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *a) { 5 | barrier_wait(&barrier); 6 | *(int*)a = 43; 7 | return 0; 8 | } 9 | 10 | int main() { 11 | barrier_init(&barrier, 2); 12 | int Var = 42; 13 | pthread_t t; 14 | pthread_create(&t, 0, Thread, &Var); 15 | Var = 43; 16 | barrier_wait(&barrier); 17 | pthread_join(t, 0); 18 | } 19 | 20 | // CHECK: WARNING: ThreadSanitizer: data race 21 | // CHECK: Location is stack of main thread. 22 | 23 | -------------------------------------------------------------------------------- /test/asan/TestCases/global-demangle.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | 3 | namespace XXX { 4 | class YYY { 5 | public: 6 | static char ZZZ[]; 7 | }; 8 | char YYY::ZZZ[] = "abc"; 9 | } 10 | 11 | int main(int argc, char **argv) { 12 | return (int)XXX::YYY::ZZZ[argc + 5]; // BOOM 13 | // CHECK: {{READ of size 1 at 0x.*}} 14 | // CHECK: {{0x.* is located 2 bytes to the right of global variable}} 15 | // CHECK: 'XXX::YYY::ZZZ' {{.*}} of size 4 16 | // CHECK: 'XXX::YYY::ZZZ' is ascii string 'abc' 17 | } 18 | -------------------------------------------------------------------------------- /test/tsan/atexit2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | 3 | #include 4 | #include 5 | 6 | int n; 7 | const int N = 10000; 8 | 9 | static void atexit1() { 10 | n++; 11 | } 12 | 13 | static void atexit0() { 14 | fprintf(stderr, "run count: %d\n", n); 15 | } 16 | 17 | int main() { 18 | atexit(atexit0); 19 | for (int i = 0; i < N; i++) 20 | atexit(atexit1); 21 | } 22 | 23 | // CHECK-NOT: FATAL: ThreadSanitizer 24 | // CHECK-NOT: WARNING: ThreadSanitizer 25 | // CHECK: run count: 10000 26 | 27 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Misc/vla.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang -fsanitize=vla-bound %s -O3 -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MINUS-ONE 3 | // RUN: %run %t a 2>&1 | FileCheck %s --check-prefix=CHECK-ZERO 4 | // RUN: %run %t a b 5 | 6 | int main(int argc, char **argv) { 7 | // CHECK-MINUS-ONE: vla.c:9:11: runtime error: variable length array bound evaluates to non-positive value -1 8 | // CHECK-ZERO: vla.c:9:11: runtime error: variable length array bound evaluates to non-positive value 0 9 | int arr[argc - 2]; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/init_fini_sections.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan %s -o %t && %run %t | FileCheck %s 2 | 3 | #include 4 | 5 | static void foo() { 6 | printf("foo\n"); 7 | } 8 | 9 | int main() { 10 | return 0; 11 | } 12 | 13 | __attribute__((section(".preinit_array"))) 14 | void (*call_foo)(void) = &foo; 15 | 16 | __attribute__((section(".init_array"))) 17 | void (*call_foo_2)(void) = &foo; 18 | 19 | __attribute__((section(".fini_array"))) 20 | void (*call_foo_3)(void) = &foo; 21 | 22 | // CHECK: foo 23 | // CHECK: foo 24 | // CHECK: foo 25 | -------------------------------------------------------------------------------- /test/sanitizer_common/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") 3 | 4 | # Tool-specific config options. 5 | config.tool_name = "@SANITIZER_COMMON_LIT_TEST_MODE@" 6 | config.target_cflags = "@SANITIZER_COMMON_TEST_TARGET_CFLAGS@" 7 | config.target_arch = "@SANITIZER_COMMON_TEST_TARGET_ARCH@" 8 | 9 | # Load tool-specific config that would do the real work. 10 | lit_config.load_config(config, "@SANITIZER_COMMON_LIT_SOURCE_DIR@/lit.common.cfg") 11 | 12 | -------------------------------------------------------------------------------- /test/tsan/tls_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *a) { 5 | barrier_wait(&barrier); 6 | *(int*)a = 43; 7 | return 0; 8 | } 9 | 10 | int main() { 11 | barrier_init(&barrier, 2); 12 | static __thread int Var = 42; 13 | pthread_t t; 14 | pthread_create(&t, 0, Thread, &Var); 15 | Var = 43; 16 | barrier_wait(&barrier); 17 | pthread_join(t, 0); 18 | } 19 | 20 | // CHECK: WARNING: ThreadSanitizer: data race 21 | // CHECK: Location is TLS of main thread. 22 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/on_error_callback.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | 3 | // FIXME: merge this with the common on_error_callback test when we can run 4 | // common tests on Windows. 5 | 6 | #include 7 | #include 8 | 9 | extern "C" 10 | void __asan_on_error() { 11 | fprintf(stderr, "__asan_on_error called"); 12 | fflush(0); 13 | } 14 | 15 | int main() { 16 | char *x = (char*)malloc(10 * sizeof(char)); 17 | free(x); 18 | return x[5]; 19 | // CHECK: __asan_on_error called 20 | } 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/poison_partial.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // RUN: not %run %t heap 2>&1 | FileCheck %s 4 | // RUN: %env_asan_opts=poison_partial=0 %run %t 5 | // RUN: %env_asan_opts=poison_partial=0 %run %t heap 6 | #include 7 | char g[21]; 8 | char *x; 9 | 10 | int main(int argc, char **argv) { 11 | if (argc >= 2) 12 | x = new char[21]; 13 | else 14 | x = &g[0]; 15 | memset(x, 0, 21); 16 | int *y = (int*)x; 17 | return y[5]; 18 | } 19 | // CHECK: 0 bytes to the right 20 | -------------------------------------------------------------------------------- /test/asan/TestCases/Helpers/echo-env.cc: -------------------------------------------------------------------------------- 1 | // Helper binary for 2 | // lit_tests/TestCases/Darwin/unset-insert-libraries-on-exec.cc 3 | // Prints the environment variable with the given name. 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) { 8 | if (argc != 2) { 9 | printf("Usage: %s ENVNAME\n", argv[0]); 10 | exit(1); 11 | } 12 | const char *value = getenv(argv[1]); 13 | if (value) { 14 | printf("%s = %s\n", argv[1], value); 15 | } else { 16 | printf("%s not set.\n", argv[1]); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/msan/Linux/forkpty.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -lutil -o %t && %run %t 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int 8 | main (int argc, char** argv) 9 | { 10 | int master, slave; 11 | openpty(&master, &slave, NULL, NULL, NULL); 12 | assert(__msan_test_shadow(&master, sizeof(master)) == -1); 13 | assert(__msan_test_shadow(&slave, sizeof(slave)) == -1); 14 | 15 | int master2; 16 | forkpty(&master2, NULL, NULL, NULL); 17 | assert(__msan_test_shadow(&master2, sizeof(master2)) == -1); 18 | } 19 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/pthread_mutexattr_get.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -O0 %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | pthread_mutexattr_t ma; 8 | int res = pthread_mutexattr_init(&ma); 9 | assert(res == 0); 10 | res = pthread_mutexattr_setpshared(&ma, 1); 11 | assert(res == 0); 12 | int pshared; 13 | res = pthread_mutexattr_getpshared(&ma, &pshared); 14 | assert(res == 0); 15 | assert(pshared == 1); 16 | res = pthread_mutexattr_destroy(&ma); 17 | assert(res == 0); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/dfsan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(DFSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 2 | 3 | configure_lit_site_cfg( 4 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in 5 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg) 6 | 7 | set(DFSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) 8 | if(NOT COMPILER_RT_STANDALONE_BUILD) 9 | list(APPEND DFSAN_TEST_DEPS dfsan) 10 | endif() 11 | 12 | add_lit_testsuite(check-dfsan "Running the DataFlowSanitizer tests" 13 | ${CMAKE_CURRENT_BINARY_DIR} 14 | DEPENDS ${DFSAN_TEST_DEPS}) 15 | set_target_properties(check-dfsan PROPERTIES FOLDER "DFSan tests") 16 | -------------------------------------------------------------------------------- /test/msan/tls_reuse.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | 3 | // Check that when TLS block is reused between threads, its shadow is cleaned. 4 | 5 | #include 6 | #include 7 | 8 | int __thread x; 9 | 10 | void *ThreadFn(void *) { 11 | if (!x) 12 | printf("zzz\n"); 13 | int y; 14 | int * volatile p = &y; 15 | x = *p; 16 | return 0; 17 | } 18 | 19 | int main(void) { 20 | pthread_t t; 21 | for (int i = 0; i < 100; ++i) { 22 | pthread_create(&t, 0, ThreadFn, 0); 23 | pthread_join(t, 0); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Misc/nonnull.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=returns-nonnull-attribute %s -O3 -o %t 2 | // RUN: %run %t foo 3 | // RUN: %run %t 2>&1 | FileCheck %s 4 | 5 | __attribute__((returns_nonnull)) char *foo(char *a); 6 | 7 | char *foo(char *a) { 8 | return a; 9 | // CHECK: nonnull.cpp:[[@LINE+2]]:1: runtime error: null pointer returned from function declared to never return null 10 | // CHECK-NEXT: nonnull.cpp:[[@LINE-5]]:16: note: returns_nonnull attribute specified here 11 | } 12 | 13 | int main(int argc, char **argv) { 14 | return foo(argv[1]) == 0; 15 | } 16 | -------------------------------------------------------------------------------- /lib/asan/asan_blacklist.txt: -------------------------------------------------------------------------------- 1 | # Blacklist for AddressSanitizer. Turns off instrumentation of particular 2 | # functions or sources. Use with care. You may set location of blacklist 3 | # at compile-time using -fsanitize-blacklist= flag. 4 | 5 | # Example usage: 6 | # fun:*bad_function_name* 7 | # src:file_with_tricky_code.cc 8 | # global:*global_with_bad_access_or_initialization* 9 | # global:*global_with_initialization_issues*=init 10 | # type:*Namespace::ClassName*=init 11 | 12 | # Stack buffer overflow in VC/INCLUDE/xlocnum, see http://goo.gl/L4qqUG 13 | fun:*_Find_elem@*@std* 14 | -------------------------------------------------------------------------------- /test/msan/poison_in_free.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && not %run %t >%t.out 2>&1 2 | // FileCheck %s <%t.out 3 | // RUN: %clangxx_msan -O0 %s -o %t && MSAN_OPTIONS=poison_in_free=0 %run %t >%t.out 2>&1 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char **argv) { 10 | char *volatile x = (char*)malloc(50 * sizeof(char)); 11 | memset(x, 0, 50); 12 | free(x); 13 | return x[25]; 14 | // CHECK: MemorySanitizer: use-of-uninitialized-value 15 | // CHECK: #0 {{.*}} in main{{.*}}poison_in_free.cc:[[@LINE-2]] 16 | } 17 | -------------------------------------------------------------------------------- /test/profile/instrprof-set-filename.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_profgen -o %t -O3 %s 2 | // RUN: %run %t %t.profraw 3 | // RUN: llvm-profdata merge -o %t.profdata %t.profraw 4 | // RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s 5 | 6 | void __llvm_profile_set_filename(const char *); 7 | int main(int argc, const char *argv[]) { 8 | // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]] 9 | if (argc < 2) 10 | return 1; 11 | __llvm_profile_set_filename(argv[1]); 12 | return 0; 13 | } 14 | // CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2} 15 | -------------------------------------------------------------------------------- /test/asan/TestCases/Darwin/malloc_zone-protected.cc: -------------------------------------------------------------------------------- 1 | // Make sure the zones created by malloc_create_zone() are write-protected. 2 | #include 3 | #include 4 | 5 | // RUN: %clangxx_asan %s -o %t 6 | // RUN: not %run %t 2>&1 | FileCheck %s 7 | 8 | 9 | void *pwn(malloc_zone_t *unused_zone, size_t unused_size) { 10 | printf("PWNED\n"); 11 | return NULL; 12 | } 13 | 14 | int main() { 15 | malloc_zone_t *zone = malloc_create_zone(0, 0); 16 | zone->malloc = pwn; 17 | void *v = malloc_zone_malloc(zone, 1); 18 | // CHECK-NOT: PWNED 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/msan/c-strdup.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_msan -O0 %s -o %t && %run %t >%t.out 2>&1 2 | // RUN: %clang_msan -O1 %s -o %t && %run %t >%t.out 2>&1 3 | // RUN: %clang_msan -O2 %s -o %t && %run %t >%t.out 2>&1 4 | // RUN: %clang_msan -O3 %s -o %t && %run %t >%t.out 2>&1 5 | 6 | // Test that strdup in C programs is intercepted. 7 | // GLibC headers translate strdup to __strdup at -O1 and higher. 8 | 9 | #include 10 | #include 11 | int main(int argc, char **argv) { 12 | char buf[] = "abc"; 13 | char *p = strdup(buf); 14 | if (*p) 15 | exit(0); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/options-invalid.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -O0 %s -o %t 2 | // RUN: %env_tool_opts=invalid_option_name=10,verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-V1 3 | // RUN: %env_tool_opts=invalid_option_name=10 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-V0 4 | 5 | #include 6 | 7 | int main() { 8 | fprintf(stderr, "done\n"); 9 | } 10 | 11 | // CHECK-V1: WARNING: found 1 unrecognized 12 | // CHECK-V1: invalid_option_name 13 | // CHECK-V0-NOT: WARNING: found 1 unrecognized 14 | // CHECK-V0-NOT: invalid_option_name 15 | // CHECK: done 16 | -------------------------------------------------------------------------------- /test/tsan/atexit.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | 3 | #include 4 | #include 5 | 6 | class Logger { 7 | public: 8 | Logger() { 9 | fprintf(stderr, "Logger ctor\n"); 10 | } 11 | 12 | ~Logger() { 13 | fprintf(stderr, "Logger dtor\n"); 14 | } 15 | }; 16 | 17 | Logger logger; 18 | 19 | void log_from_atexit() { 20 | fprintf(stderr, "In log_from_atexit\n"); 21 | } 22 | 23 | int main() { 24 | atexit(log_from_atexit); 25 | } 26 | 27 | // CHECK: Logger ctor 28 | // CHECK: In log_from_atexit 29 | // CHECK: Logger dtor 30 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Misc/bool.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=bool %s -O3 -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // RUN: %env_ubsan_opts=print_summary=1:report_error_type=1 not %run %t 2>&1 | FileCheck %s --check-prefix=SUMMARY 4 | 5 | unsigned char NotABool = 123; 6 | 7 | int main(int argc, char **argv) { 8 | bool *p = (bool*)&NotABool; 9 | 10 | // CHECK: bool.cpp:[[@LINE+1]]:10: runtime error: load of value 123, which is not a valid value for type 'bool' 11 | return *p; 12 | // SUMMARY: SUMMARY: {{.*}}Sanitizer: invalid-bool-load {{.*}}bool.cpp:[[@LINE-1]] 13 | } 14 | -------------------------------------------------------------------------------- /lib/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/Makefile.mk --------------------------------------*- Makefile -*--===# 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is distributed under the University of Illinois Open Source 6 | # License. See LICENSE.TXT for details. 7 | # 8 | #===------------------------------------------------------------------------===# 9 | 10 | SubDirs := 11 | 12 | # Add submodules. 13 | SubDirs += asan 14 | SubDirs += builtins 15 | SubDirs += interception 16 | SubDirs += lsan 17 | SubDirs += profile 18 | SubDirs += sanitizer_common 19 | SubDirs += ubsan 20 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/dll_large_function.cc: -------------------------------------------------------------------------------- 1 | // Make sure we can link a DLL with large functions which would mean 2 | // functions such as __asan_loadN and __asan_storeN will be called 3 | // from the DLL. We simulate the large function with 4 | // -mllvm -asan-instrumentation-with-call-threshold=0. 5 | // RUN: %clang_cl_asan %s -c -Fo%t.obj -mllvm -asan-instrumentation-with-call-threshold=0 6 | // RUN: link /nologo /DLL /OUT:%t.dll %t.obj %asan_dll_thunk 7 | // REQUIRES: asan-static-runtime 8 | 9 | void f(long* foo, long* bar) { 10 | // One load and one store 11 | *foo = *bar; 12 | } 13 | -------------------------------------------------------------------------------- /test/msan/pthread_getattr_np_deadlock.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && %run %t 2 | 3 | // Regression test for a deadlock in pthread_getattr_np 4 | 5 | #include 6 | #include 7 | 8 | void *ThreadFn(void *) { 9 | pthread_attr_t attr; 10 | int res = pthread_getattr_np(pthread_self(), &attr); 11 | assert(!res); 12 | return 0; 13 | } 14 | 15 | int main(void) { 16 | pthread_t t; 17 | int res = pthread_create(&t, 0, ThreadFn, 0); 18 | assert(!res); 19 | res = pthread_join(t, 0); 20 | assert(!res); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/msan/vector_select.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -c -o %t 2 | // RUN: %clangxx_msan -O3 %s -c -o %t 3 | 4 | // Regression test for MemorySanitizer instrumentation of a select instruction 5 | // with vector arguments. 6 | 7 | #if defined(__x86_64__) 8 | #include 9 | 10 | __m128d select(bool b, __m128d c, __m128d d) 11 | { 12 | return b ? c : d; 13 | } 14 | #elif defined (__mips64) || defined (__powerpc64__) 15 | typedef double __w64d __attribute__ ((vector_size(16))); 16 | 17 | __w64d select(bool b, __w64d c, __w64d d) 18 | { 19 | return b ? c : d; 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /test/safestack/overflow.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_safestack %s -o %t 2 | // RUN: %run %t 3 | 4 | // RUN: %clang_nosafestack -fno-stack-protector %s -o %t 5 | // RUN: not %run %t 6 | 7 | // Test that buffer overflows on the unsafe stack do not affect variables on the 8 | // safe stack. 9 | 10 | __attribute__((noinline)) 11 | void fct(volatile int *buffer) 12 | { 13 | memset(buffer - 1, 0, 7 * sizeof(int)); 14 | } 15 | 16 | int main(int argc, char **argv) 17 | { 18 | int value1 = 42; 19 | int buffer[5]; 20 | int value2 = 42; 21 | fct(buffer); 22 | return value1 != 42 || value2 != 42; 23 | } 24 | -------------------------------------------------------------------------------- /test/tsan/longjmp.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | 3 | // Longjmp assembly has not been implemented for mips64 or aarch64 yet 4 | // XFAIL: mips64 5 | // XFAIL: aarch64 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int foo(jmp_buf env) { 12 | longjmp(env, 42); 13 | } 14 | 15 | int main() { 16 | jmp_buf env; 17 | if (setjmp(env) == 42) { 18 | printf("JUMPED\n"); 19 | return 0; 20 | } 21 | foo(env); 22 | printf("FAILED\n"); 23 | return 0; 24 | } 25 | 26 | // CHECK-NOT: FAILED 27 | // CHECK: JUMPED 28 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Misc/Linux/ubsan_options.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=integer -fsanitize-recover=integer %s -o %t 2 | // RUN: not %t 2>&1 | FileCheck %s 3 | 4 | // __ubsan_default_options() doesn't work on Darwin. 5 | // XFAIL: darwin 6 | 7 | #include 8 | 9 | extern "C" const char *__ubsan_default_options() { 10 | return "halt_on_error=1"; 11 | } 12 | 13 | int main() { 14 | (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull)); 15 | // CHECK: ubsan_options.cc:[[@LINE-1]]:44: runtime error: unsigned integer overflow 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/beginthreadex.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: %run %t 3 | 4 | #include 5 | #include 6 | 7 | unsigned WINAPI thread_proc(void *) { 8 | volatile char stack_buffer[42]; 9 | for (int i = 0; i < sizeof(stack_buffer); ++i) 10 | stack_buffer[i] = 42; 11 | return 0; 12 | } 13 | 14 | int main() { 15 | HANDLE thr = (HANDLE)_beginthreadex(NULL, 0, thread_proc, NULL, 0, NULL); 16 | if (thr == 0) 17 | return 1; 18 | if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE)) 19 | return 2; 20 | CloseHandle(thr); 21 | } 22 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Linux/abort_on_error.cc: -------------------------------------------------------------------------------- 1 | // Check that sanitizers call _exit() on Linux by default (i.e. 2 | // abort_on_error=0). See also Darwin/abort_on_error.cc. 3 | 4 | // RUN: %clangxx %s -o %t 5 | 6 | // Intentionally don't inherit the default options. 7 | // RUN: %tool_options='' not %run %t 2>&1 8 | 9 | // When we use lit's default options, we shouldn't crash either. On Linux 10 | // lit doesn't set options anyway. 11 | // RUN: not %run %t 2>&1 12 | 13 | namespace __sanitizer { 14 | void Die(); 15 | } 16 | 17 | int main() { 18 | __sanitizer::Die(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/tsan/heap_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | #include 4 | #include 5 | #include 6 | 7 | void *Thread(void *a) { 8 | ((int*)a)[0]++; 9 | barrier_wait(&barrier); 10 | return NULL; 11 | } 12 | 13 | int main() { 14 | barrier_init(&barrier, 2); 15 | int *p = new int(42); 16 | pthread_t t; 17 | pthread_create(&t, NULL, Thread, p); 18 | barrier_wait(&barrier); 19 | p[0]++; 20 | pthread_join(t, NULL); 21 | delete p; 22 | } 23 | 24 | // CHECK: WARNING: ThreadSanitizer: data race 25 | -------------------------------------------------------------------------------- /test/tsan/sleep_sync2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | int X = 0; 5 | 6 | void *Thread(void *p) { 7 | X = 42; 8 | barrier_wait(&barrier); 9 | return 0; 10 | } 11 | 12 | int main() { 13 | barrier_init(&barrier, 2); 14 | pthread_t t; 15 | sleep(1); // must not appear in the report 16 | pthread_create(&t, 0, Thread, 0); 17 | barrier_wait(&barrier); 18 | X = 43; 19 | pthread_join(t, 0); 20 | return 0; 21 | } 22 | 23 | // CHECK: WARNING: ThreadSanitizer: data race 24 | // CHECK-NOT: As if synchronized via sleep 25 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Integer/mul-overflow.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s 2 | 3 | #include 4 | 5 | int main() { 6 | // These promote to 'int'. 7 | (void)(int8_t(-2) * int8_t(0x7f)); 8 | (void)(int16_t(0x7fff) * int16_t(0x7fff)); 9 | (void)(uint16_t(0xffff) * int16_t(0x7fff)); 10 | (void)(uint16_t(0xffff) * uint16_t(0x8000)); 11 | 12 | // CHECK: mul-overflow.cpp:13:27: runtime error: signed integer overflow: 65535 * 32769 cannot be represented in type 'int' 13 | (void)(uint16_t(0xffff) * uint16_t(0x8001)); 14 | } 15 | -------------------------------------------------------------------------------- /test/BlocksRuntime/shorthandexpression.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | /* 8 | * shorthandexpression.c 9 | * testObjects 10 | * 11 | * Created by Blaine Garst on 9/16/08. 12 | * 13 | * CONFIG error: 14 | */ 15 | 16 | 17 | void foo() { 18 | void (^b)(void) = ^(void)printf("hello world\n"); 19 | } 20 | 21 | int main(int argc, char *argv[]) { 22 | printf("%s: this shouldn't compile\n", argv[0]); 23 | return 1; 24 | } 25 | -------------------------------------------------------------------------------- /test/lsan/TestCases/ignore_object_errors.cc: -------------------------------------------------------------------------------- 1 | // Test for incorrect use of __lsan_ignore_object(). 2 | // RUN: %clangxx_lsan %s -o %t 3 | // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 2>&1 | FileCheck %s 4 | 5 | #include 6 | #include 7 | 8 | #include "sanitizer/lsan_interface.h" 9 | 10 | int main() { 11 | void *p = malloc(1337); 12 | fprintf(stderr, "Test alloc: %p.\n", p); 13 | __lsan_ignore_object(p); 14 | __lsan_ignore_object(p); 15 | free(p); 16 | __lsan_ignore_object(p); 17 | return 0; 18 | } 19 | // CHECK: Test alloc: [[ADDR:.*]]. 20 | // CHECK-NOT: SUMMARY: {{.*}} leaked 21 | -------------------------------------------------------------------------------- /test/msan/pthread_setcancelstate.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main(void) { 8 | int oldstate; 9 | int oldtype; 10 | int res = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); 11 | assert(res == 0); 12 | __msan_check_mem_is_initialized(&oldstate, sizeof(oldstate)); 13 | 14 | res = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); 15 | assert(res == 0); 16 | __msan_check_mem_is_initialized(&oldtype, sizeof(oldtype)); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/tsan/Unit/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | ## Autogenerated by LLVM/Clang configuration. 2 | # Do not edit! 3 | 4 | # Load common config for all compiler-rt unit tests. 5 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured") 6 | 7 | # Setup config name. 8 | config.name = 'ThreadSanitizer-Unit' 9 | 10 | # Setup test source and exec root. For unit tests, we define 11 | # it as build directory with ASan unit tests. 12 | # FIXME: De-hardcode this path. 13 | config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/tsan/tests" 14 | config.test_source_root = config.test_exec_root 15 | -------------------------------------------------------------------------------- /lib/interception/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Build for the runtime interception helper library. 2 | 3 | set(INTERCEPTION_SOURCES 4 | interception_linux.cc 5 | interception_mac.cc 6 | interception_win.cc 7 | interception_type_test.cc 8 | ) 9 | 10 | include_directories(..) 11 | 12 | set(INTERCEPTION_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 13 | append_no_rtti_flag(INTERCEPTION_CFLAGS) 14 | 15 | add_compiler_rt_object_libraries(RTInterception 16 | OS ${SANITIZER_COMMON_SUPPORTED_OS} 17 | ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH} 18 | SOURCES ${INTERCEPTION_SOURCES} 19 | CFLAGS ${INTERCEPTION_CFLAGS}) 20 | -------------------------------------------------------------------------------- /test/msan/Linux/glob_nomatch.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t %p 2 | // RUN: %clangxx_msan -O3 %s -o %t && %run %t %p 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char *argv[]) { 10 | assert(argc == 2); 11 | char buf[1024]; 12 | snprintf(buf, sizeof(buf), "%s/%s", argv[1], "glob_test_root/*c"); 13 | 14 | glob_t globbuf; 15 | int res = glob(buf, 0, 0, &globbuf); 16 | assert(res == GLOB_NOMATCH); 17 | assert(globbuf.gl_pathc == 0); 18 | if (globbuf.gl_pathv == 0) 19 | exit(0); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/profile/instrprof-override-filename.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_profgen -o %t -O3 %s 2 | // RUN: %run %t %t.profraw 3 | // RUN: llvm-profdata merge -o %t.profdata %t.profraw 4 | // RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s 5 | 6 | void __llvm_profile_override_default_filename(const char *); 7 | int main(int argc, const char *argv[]) { 8 | // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]] 9 | if (argc < 2) 10 | return 1; 11 | __llvm_profile_override_default_filename(argv[1]); 12 | return 0; 13 | } 14 | // CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2} 15 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Darwin/abort_on_error.cc: -------------------------------------------------------------------------------- 1 | // Check that sanitizers on OS X crash the process by default (i.e. 2 | // abort_on_error=1). See also Linux/abort_on_error.cc. 3 | 4 | // RUN: %clangxx %s -o %t 5 | 6 | // Intentionally don't inherit the default options. 7 | // RUN: %tool_options='' not --crash %run %t 2>&1 8 | 9 | // When we use lit's default options, we shouldn't crash. 10 | // RUN: not %run %t 2>&1 11 | 12 | int global; 13 | 14 | int main() { 15 | volatile int *a = new int[100]; 16 | delete[] a; 17 | global = a[0]; // use-after-free: triggers ASan report. 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/tsan/bench_rwmutex.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | #include "bench.h" 5 | 6 | pthread_rwlock_t mtx; 7 | 8 | void thread(int tid) { 9 | for (int i = 0; i < bench_niter; i++) { 10 | pthread_rwlock_rdlock(&mtx); 11 | pthread_rwlock_unlock(&mtx); 12 | } 13 | } 14 | 15 | void bench() { 16 | pthread_rwlock_init(&mtx, 0); 17 | pthread_rwlock_wrlock(&mtx); 18 | pthread_rwlock_unlock(&mtx); 19 | pthread_rwlock_rdlock(&mtx); 20 | pthread_rwlock_unlock(&mtx); 21 | start_thread_group(bench_nthread, thread); 22 | } 23 | 24 | // CHECK: DONE 25 | 26 | -------------------------------------------------------------------------------- /test/tsan/virtual_inheritance_compile_bug.cc: -------------------------------------------------------------------------------- 1 | // Regression test for http://code.google.com/p/thread-sanitizer/issues/detail?id=3. 2 | // The C++ variant is much more compact that the LLVM IR equivalent. 3 | 4 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 5 | #include 6 | struct AAA { virtual long aaa () { return 0; } }; // NOLINT 7 | struct BBB: virtual AAA { unsigned long bbb; }; // NOLINT 8 | struct CCC: virtual AAA { }; 9 | struct DDD: CCC, BBB { DDD(); }; // NOLINT 10 | DDD::DDD() { } 11 | int main() { 12 | DDD d; 13 | printf("OK\n"); 14 | } 15 | // CHECK: OK 16 | -------------------------------------------------------------------------------- /test/asan/TestCases/memcmp_strict_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=strict_memcmp=0 %run %t 2 | // RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=strict_memcmp=1 not %run %t 2>&1 | FileCheck %s 3 | // Default to strict_memcmp=1. 4 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | #include 8 | int main() { 9 | char kFoo[] = "foo"; 10 | char kFubar[] = "fubar"; 11 | int res = memcmp(kFoo, kFubar, strlen(kFubar)); 12 | printf("res: %d\n", res); 13 | // CHECK: AddressSanitizer: stack-buffer-overflow 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/tsan/ignore_lib_lib.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void *volatile mem; 8 | volatile int len; 9 | 10 | void *Thread(void *p) { 11 | while ((p = __atomic_load_n(&mem, __ATOMIC_ACQUIRE)) == 0) 12 | usleep(100); 13 | memset(p, 0, len); 14 | return 0; 15 | } 16 | 17 | extern "C" void libfunc() { 18 | pthread_t t; 19 | pthread_create(&t, 0, Thread, 0); 20 | len = 10; 21 | __atomic_store_n(&mem, malloc(len), __ATOMIC_RELEASE); 22 | pthread_join(t, 0); 23 | free(mem); 24 | fprintf(stderr, "OK\n"); 25 | } 26 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/null_deref.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | // FIXME: merge this with the common null_deref test when we can run common 3 | // tests on Windows. 4 | 5 | __attribute__((noinline)) 6 | static void NullDeref(int *ptr) { 7 | // CHECK: ERROR: AddressSanitizer: access-violation on unknown address 8 | // CHECK: {{0x0*000.. .*pc 0x.*}} 9 | ptr[10]++; // BOOM 10 | } 11 | int main() { 12 | NullDeref((int*)0); 13 | // CHECK: {{ #1 0x.* in main.*null_deref.cc:}}[[@LINE-1]]:3 14 | // CHECK: AddressSanitizer can not provide additional info. 15 | } 16 | -------------------------------------------------------------------------------- /test/asan/TestCases/atexit_stats.cc: -------------------------------------------------------------------------------- 1 | // Make sure we report atexit stats. 2 | // RUN: %clangxx_asan -O3 %s -o %t 3 | // RUN: %env_asan_opts=atexit=1:print_stats=1 %run %t 2>&1 | FileCheck %s 4 | // 5 | // No atexit output on Android due to 6 | // https://code.google.com/p/address-sanitizer/issues/detail?id=263 7 | // XFAIL: android 8 | 9 | #include 10 | #if !defined(__APPLE__) && !defined(__FreeBSD__) 11 | #include 12 | #endif 13 | int *p1 = (int*)malloc(900); 14 | int *p2 = (int*)malloc(90000); 15 | int *p3 = (int*)malloc(9000000); 16 | int main() { } 17 | 18 | // CHECK: AddressSanitizer exit stats: 19 | -------------------------------------------------------------------------------- /test/msan/Unit/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | ## Autogenerated by LLVM/Clang configuration. 2 | # Do not edit! 3 | 4 | # Load common config for all compiler-rt unit tests. 5 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured") 6 | 7 | # Setup config name. 8 | config.name = 'MemorySanitizer-Unit' 9 | 10 | # Setup test source and exec root. For unit tests, we define 11 | # it as build directory with MSan unit tests. 12 | # FIXME: Don't use hardcoded path to MSan unit tests. 13 | config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/msan/tests" 14 | config.test_source_root = config.test_exec_root 15 | -------------------------------------------------------------------------------- /test/msan/cxa_atexit.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t %p 2 | 3 | // PR17377: C++ module destructors get stale argument shadow. 4 | 5 | #include 6 | #include 7 | class A { 8 | public: 9 | // This destructor get stale argument shadow left from the call to f(). 10 | ~A() { 11 | if (this) 12 | exit(0); 13 | } 14 | }; 15 | 16 | A a; 17 | 18 | __attribute__((noinline)) 19 | void f(long x) { 20 | } 21 | 22 | int main(void) { 23 | long x; 24 | long * volatile p = &x; 25 | // This call poisons TLS shadow for the first function argument. 26 | f(*p); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc: -------------------------------------------------------------------------------- 1 | // Regression test for a crash in getpwnam_r and similar interceptors. 2 | // RUN: %clangxx -O0 -g %s -o %t && %run %t 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main(void) { 13 | struct passwd pwd; 14 | struct passwd *pwdres; 15 | char buf[10000]; 16 | int res = getpwnam_r("no-such-user", &pwd, buf, sizeof(buf), &pwdres); 17 | assert(res == 0 || res == ENOENT); 18 | assert(pwdres == 0); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/tsan/libcxx/std_shared_ptr.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | int v1 = 0; 8 | int v2 = 0; 9 | std::thread t1; 10 | std::thread t2; 11 | 12 | { 13 | auto thingy = std::make_shared(42); 14 | t1 = std::thread([thingy, &v1] { v1 = *thingy; }); 15 | t2 = std::thread([thingy, &v2] { v2 = *thingy; }); 16 | } 17 | 18 | t1.join(); 19 | t2.join(); 20 | printf("%d %d\n", v1, v2); 21 | // CHECK-NOT: ThreadSanitizer: data race 22 | // CHECK: 42 42 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /lib/builtins/truncdfhf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/truncdfhf2.c - double -> half conversion --------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #define SRC_DOUBLE 11 | #define DST_HALF 12 | #include "fp_trunc_impl.inc" 13 | 14 | ARM_EABI_FNALIAS(d2h, truncdfhf2) 15 | 16 | COMPILER_RT_ABI uint16_t __truncdfhf2(double a) { 17 | return __truncXfYf2__(a); 18 | } 19 | -------------------------------------------------------------------------------- /lib/builtins/truncdfsf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/truncdfsf2.c - double -> single conversion ------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #define SRC_DOUBLE 11 | #define DST_SINGLE 12 | #include "fp_trunc_impl.inc" 13 | 14 | ARM_EABI_FNALIAS(d2f, truncdfsf2) 15 | 16 | COMPILER_RT_ABI float __truncdfsf2(double a) { 17 | return __truncXfYf2__(a); 18 | } 19 | -------------------------------------------------------------------------------- /test/BlocksRuntime/block-static.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | // testfilerunner CONFIG 8 | 9 | #include 10 | 11 | 12 | int main(int argc, char **argv) { 13 | static int numberOfSquesals = 5; 14 | 15 | ^{ numberOfSquesals = 6; }(); 16 | 17 | if (numberOfSquesals == 6) { 18 | printf("%s: success\n", argv[0]); 19 | return 0; 20 | } 21 | printf("**** did not update static local, rdar://6177162\n"); 22 | return 1; 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /test/BlocksRuntime/orbars.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | /* 8 | * orbars.c 9 | * testObjects 10 | * 11 | * Created by Blaine Garst on 9/17/08. 12 | * 13 | * CONFIG rdar://6276695 error: before ‘|’ token 14 | */ 15 | 16 | #include 17 | 18 | int main(int argc, char *argv[]) { 19 | int i = 10; 20 | void (^b)(void) = ^(void){ | i | printf("hello world, %d\n", ++i); }; 21 | printf("%s: success :-(\n", argv[0]); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /test/lsan/TestCases/fork.cc: -------------------------------------------------------------------------------- 1 | // Test that thread local data is handled correctly after forking without exec(). 2 | // RUN: %clangxx_lsan %s -o %t 3 | // RUN: %run %t 2>&1 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | __thread void *thread_local_var; 12 | 13 | int main() { 14 | int status = 0; 15 | thread_local_var = malloc(1337); 16 | pid_t pid = fork(); 17 | assert(pid >= 0); 18 | if (pid > 0) { 19 | waitpid(pid, &status, 0); 20 | assert(WIFEXITED(status)); 21 | return WEXITSTATUS(status); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /test/tsan/race_stress.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | #include "test.h" 3 | 4 | const int kThreads = 16; 5 | const int kIters = 1000; 6 | 7 | volatile int X = 0; 8 | 9 | void *thr(void *arg) { 10 | for (int i = 0; i < kIters; i++) 11 | X++; 12 | return 0; 13 | } 14 | 15 | int main() { 16 | pthread_t th[kThreads]; 17 | for (int i = 0; i < kThreads; i++) 18 | pthread_create(&th[i], 0, thr, 0); 19 | for (int i = 0; i < kThreads; i++) 20 | pthread_join(th[i], 0); 21 | fprintf(stderr, "DONE\n"); 22 | } 23 | 24 | // CHECK: ThreadSanitizer: data race 25 | // CHECK: DONE 26 | -------------------------------------------------------------------------------- /test/msan/backtrace.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | __attribute__((noinline)) 10 | void f() { 11 | void *buf[10]; 12 | int sz = backtrace(buf, sizeof(buf) / sizeof(*buf)); 13 | assert(sz > 0); 14 | for (int i = 0; i < sz; ++i) 15 | if (!buf[i]) 16 | exit(1); 17 | char **s = backtrace_symbols(buf, sz); 18 | assert(s > 0); 19 | for (int i = 0; i < sz; ++i) 20 | printf("%d\n", (int)strlen(s[i])); 21 | } 22 | 23 | int main(void) { 24 | f(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /test/tsan/bench_ten_mutexes.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | #include "bench.h" 5 | 6 | const int kMutex = 10; 7 | pthread_mutex_t mtx[kMutex]; 8 | 9 | void thread(int tid) { 10 | for (int i = 0; i < bench_niter; i++) { 11 | int idx = (i % kMutex); 12 | if (tid == 0) 13 | idx = kMutex - idx - 1; 14 | pthread_mutex_lock(&mtx[idx]); 15 | pthread_mutex_unlock(&mtx[idx]); 16 | } 17 | } 18 | 19 | void bench() { 20 | for (int i = 0; i < kMutex; i++) 21 | pthread_mutex_init(&mtx[i], 0); 22 | start_thread_group(2, thread); 23 | } 24 | 25 | // CHECK: DONE 26 | 27 | -------------------------------------------------------------------------------- /test/tsan/setuid2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="flush_memory_ms=1 memory_limit_mb=1" %run %t 2>&1 | FileCheck %s 2 | #include "test.h" 3 | #include 4 | #include 5 | #include 6 | 7 | // Test that setuid call works in presence of stoptheworld. 8 | 9 | int main() { 10 | struct timespec tp0, tp1; 11 | clock_gettime(CLOCK_MONOTONIC, &tp0); 12 | clock_gettime(CLOCK_MONOTONIC, &tp1); 13 | while (tp1.tv_sec - tp0.tv_sec < 3) { 14 | clock_gettime(CLOCK_MONOTONIC, &tp1); 15 | setuid(0); 16 | } 17 | fprintf(stderr, "DONE\n"); 18 | return 0; 19 | } 20 | 21 | // CHECK: DONE 22 | -------------------------------------------------------------------------------- /test/tsan/suppress_same_address.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | volatile int X; 5 | 6 | void *Thread1(void *x) { 7 | barrier_wait(&barrier); 8 | X = 42; 9 | X = 66; 10 | X = 78; 11 | return 0; 12 | } 13 | 14 | void *Thread2(void *x) { 15 | X = 11; 16 | X = 99; 17 | X = 73; 18 | barrier_wait(&barrier); 19 | return 0; 20 | } 21 | 22 | int main() { 23 | barrier_init(&barrier, 2); 24 | pthread_t t; 25 | pthread_create(&t, 0, Thread1, 0); 26 | Thread2(0); 27 | pthread_join(t, 0); 28 | } 29 | 30 | // CHECK: ThreadSanitizer: reported 1 warnings 31 | -------------------------------------------------------------------------------- /test/tsan/thread_leak5.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *x) { 5 | barrier_wait(&barrier); 6 | return 0; 7 | } 8 | 9 | int main() { 10 | volatile int N = 5; // prevent loop unrolling 11 | barrier_init(&barrier, N + 1); 12 | for (int i = 0; i < N; i++) { 13 | pthread_t t; 14 | pthread_create(&t, 0, Thread, 0); 15 | } 16 | barrier_wait(&barrier); 17 | sleep(1); // wait for the threads to finish and exit 18 | return 0; 19 | } 20 | 21 | // CHECK: WARNING: ThreadSanitizer: thread leak 22 | // CHECK: And 4 more similar thread leaks 23 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Integer/summary.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=integer %s -o %t 2 | // RUN: %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE 3 | // RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE 4 | // REQUIRES: ubsan-asan 5 | 6 | #include 7 | 8 | int main() { 9 | (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull)); 10 | // CHECK-NOTYPE: SUMMARY: AddressSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:44 11 | // CHECK-TYPE: SUMMARY: AddressSanitizer: unsigned-integer-overflow {{.*}}summary.cpp:[[@LINE-2]]:44 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /lib/builtins/arm/aeabi_drsub.c: -------------------------------------------------------------------------------- 1 | //===-- lib/arm/aeabi_drsub.c - Double-precision subtraction --------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #define DOUBLE_PRECISION 11 | #include "../fp_lib.h" 12 | 13 | COMPILER_RT_ABI fp_t 14 | __aeabi_dsub(fp_t, fp_t); 15 | 16 | COMPILER_RT_ABI fp_t 17 | __aeabi_drsub(fp_t a, fp_t b) { 18 | return __aeabi_dsub(b, a); 19 | } 20 | -------------------------------------------------------------------------------- /lib/builtins/arm/aeabi_frsub.c: -------------------------------------------------------------------------------- 1 | //===-- lib/arm/aeabi_frsub.c - Single-precision subtraction --------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #define SINGLE_PRECISION 11 | #include "../fp_lib.h" 12 | 13 | COMPILER_RT_ABI fp_t 14 | __aeabi_fsub(fp_t, fp_t); 15 | 16 | COMPILER_RT_ABI fp_t 17 | __aeabi_frsub(fp_t a, fp_t b) { 18 | return __aeabi_fsub(b, a); 19 | } 20 | -------------------------------------------------------------------------------- /lib/builtins/extendsfdf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/extendsfdf2.c - single -> double conversion -----------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | 11 | #define SRC_SINGLE 12 | #define DST_DOUBLE 13 | #include "fp_extend_impl.inc" 14 | 15 | ARM_EABI_FNALIAS(f2d, extendsfdf2) 16 | 17 | COMPILER_RT_ABI double __extendsfdf2(float a) { 18 | return __extendXfYf2__(a); 19 | } 20 | -------------------------------------------------------------------------------- /lib/profile/InstrProfilingUtil.h: -------------------------------------------------------------------------------- 1 | /*===- InstrProfilingUtil.h - Support library for PGO instrumentation -----===*\ 2 | |* 3 | |* The LLVM Compiler Infrastructure 4 | |* 5 | |* This file is distributed under the University of Illinois Open Source 6 | |* License. See LICENSE.TXT for details. 7 | |* 8 | \*===----------------------------------------------------------------------===*/ 9 | 10 | #ifndef PROFILE_INSTRPROFILINGUTIL_H 11 | #define PROFILE_INSTRPROFILINGUTIL_H 12 | 13 | /*! \brief Create a directory tree. */ 14 | void __llvm_profile_recursive_mkdir(char *Pathname); 15 | 16 | #endif /* PROFILE_INSTRPROFILINGUTIL_H */ 17 | -------------------------------------------------------------------------------- /test/BlocksRuntime/sizeof.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | /* 8 | * sizeof.c 9 | * testObjects 10 | * 11 | * Created by Blaine Garst on 2/17/09. 12 | * 13 | */ 14 | 15 | #include 16 | 17 | // CONFIG error: 18 | 19 | int main(int argc, char *argv[]) { 20 | 21 | void (^aBlock)(void) = ^{ printf("hellow world\n"); }; 22 | 23 | printf("the size of a block is %ld\n", sizeof(*aBlock)); 24 | printf("%s: success\n", argv[0]); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /test/asan/TestCases/alloca_big_alignment.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // 4 | 5 | #include 6 | 7 | __attribute__((noinline)) void foo(int index, int len) { 8 | volatile char str[len] __attribute__((aligned(128))); 9 | assert(!(reinterpret_cast(str) & 127L)); 10 | str[index] = '1'; // BOOM 11 | // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 12 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 13 | } 14 | 15 | int main(int argc, char **argv) { 16 | foo(10, 10); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/alloca_overflow_partial.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // 4 | 5 | #include 6 | 7 | __attribute__((noinline)) void foo(int index, int len) { 8 | volatile char str[len] __attribute__((aligned(32))); 9 | assert(!(reinterpret_cast(str) & 31L)); 10 | str[index] = '1'; // BOOM 11 | // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 12 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 13 | } 14 | 15 | int main(int argc, char **argv) { 16 | foo(10, 10); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/alloca_overflow_right.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // 4 | 5 | #include 6 | 7 | __attribute__((noinline)) void foo(int index, int len) { 8 | volatile char str[len] __attribute__((aligned(32))); 9 | assert(!(reinterpret_cast(str) & 31L)); 10 | str[index] = '1'; // BOOM 11 | // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 12 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 13 | } 14 | 15 | int main(int argc, char **argv) { 16 | foo(33, 10); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/alloca_underflow_left.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // 4 | 5 | #include 6 | 7 | __attribute__((noinline)) void foo(int index, int len) { 8 | volatile char str[len] __attribute__((aligned(32))); 9 | assert(!(reinterpret_cast(str) & 31L)); 10 | str[index] = '1'; // BOOM 11 | // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 12 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 13 | } 14 | 15 | int main(int argc, char **argv) { 16 | foo(-1, 10); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/tsan/bench_mutex.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | #include "bench.h" 5 | 6 | pthread_mutex_t mtx; 7 | pthread_cond_t cv; 8 | int x; 9 | 10 | void thread(int tid) { 11 | for (int i = 0; i < bench_niter; i++) { 12 | pthread_mutex_lock(&mtx); 13 | while (x != i * 2 + tid) 14 | pthread_cond_wait(&cv, &mtx); 15 | x++; 16 | pthread_cond_signal(&cv); 17 | pthread_mutex_unlock(&mtx); 18 | } 19 | } 20 | 21 | void bench() { 22 | pthread_mutex_init(&mtx, 0); 23 | pthread_cond_init(&cv, 0); 24 | start_thread_group(2, thread); 25 | } 26 | 27 | // CHECK: DONE 28 | 29 | -------------------------------------------------------------------------------- /test/tsan/sunrpc.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void *thr(void *p) { 9 | XDR xdrs; 10 | char buf[100]; 11 | xdrmem_create(&xdrs, buf, sizeof(buf), XDR_ENCODE); 12 | xdr_destroy(&xdrs); 13 | return 0; 14 | } 15 | 16 | int main(int argc, char *argv[]) { 17 | pthread_t th[2]; 18 | pthread_create(&th[0], 0, thr, 0); 19 | pthread_create(&th[1], 0, thr, 0); 20 | pthread_join(th[0], 0); 21 | pthread_join(th[1], 0); 22 | printf("DONE\n"); 23 | // CHECK: DONE 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /test/BlocksRuntime/returnfunctionptr.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | 8 | // CONFIG rdar://6339747 but wasn't 9 | 10 | #include 11 | 12 | int (*funcptr)(long); 13 | 14 | int (*(^b)(char))(long); 15 | 16 | int main(int argc, char *argv[]) { 17 | // implicit is fine 18 | b = ^(char x) { return funcptr; }; 19 | // explicit never parses 20 | b = ^int (*(char x))(long) { return funcptr; }; 21 | printf("%s: Success\n", argv[0]); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /test/asan/TestCases/stack-frame-demangle.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | 3 | #include 4 | 5 | namespace XXX { 6 | struct YYY { 7 | static int ZZZ(int x) { 8 | char array[10]; 9 | memset(array, 0, 10); 10 | return array[x]; // BOOOM 11 | // CHECK: ERROR: AddressSanitizer: stack-buffer-overflow 12 | // CHECK: READ of size 1 at 13 | // CHECK: is located in stack of thread T0 at offset 14 | // CHECK: XXX::YYY::ZZZ 15 | } 16 | }; 17 | } // namespace XXX 18 | 19 | int main(int argc, char **argv) { 20 | int res = XXX::YYY::ZZZ(argc + 10); 21 | return res; 22 | } 23 | -------------------------------------------------------------------------------- /test/dfsan/vararg.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_dfsan %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // RUN: %run %t foo 4 | // RUN: %clang_dfsan -mllvm -dfsan-args-abi %s -o %t 5 | // RUN: not %run %t 2>&1 | FileCheck %s 6 | // RUN: %run %t foo 7 | 8 | #include 9 | 10 | int do_nothing(const char *format, ...) { 11 | return 0; 12 | } 13 | 14 | int main(int argc, char **argv) { 15 | int (*fp)(const char *, ...); 16 | 17 | if (argc > 1) 18 | fp = do_nothing; 19 | else 20 | fp = printf; 21 | 22 | // CHECK: FATAL: DataFlowSanitizer: unsupported indirect call to vararg function printf 23 | fp("hello %s\n", "world"); 24 | } 25 | -------------------------------------------------------------------------------- /lib/builtins/arm/aeabi_cdcmpeq_check_nan.c: -------------------------------------------------------------------------------- 1 | //===-- lib/arm/aeabi_cdcmpeq_helper.c - Helper for cdcmpeq ---------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #include 11 | 12 | __attribute__((pcs("aapcs"))) 13 | __attribute__((visibility("hidden"))) 14 | int __aeabi_cdcmpeq_check_nan(double a, double b) { 15 | return __builtin_isnan(a) || __builtin_isnan(b); 16 | } 17 | -------------------------------------------------------------------------------- /lib/builtins/arm/aeabi_cfcmpeq_check_nan.c: -------------------------------------------------------------------------------- 1 | //===-- lib/arm/aeabi_cfcmpeq_helper.c - Helper for cdcmpeq ---------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #include 11 | 12 | __attribute__((pcs("aapcs"))) 13 | __attribute__((visibility("hidden"))) 14 | int __aeabi_cfcmpeq_check_nan(float a, float b) { 15 | return __builtin_isnan(a) || __builtin_isnan(b); 16 | } 17 | -------------------------------------------------------------------------------- /test/tsan/race_on_mutex2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread(void *x) { 5 | pthread_mutex_lock((pthread_mutex_t*)x); 6 | pthread_mutex_unlock((pthread_mutex_t*)x); 7 | barrier_wait(&barrier); 8 | return 0; 9 | } 10 | 11 | int main() { 12 | barrier_init(&barrier, 2); 13 | pthread_mutex_t Mtx; 14 | pthread_mutex_init(&Mtx, 0); 15 | pthread_t t; 16 | pthread_create(&t, 0, Thread, &Mtx); 17 | barrier_wait(&barrier); 18 | pthread_mutex_destroy(&Mtx); 19 | pthread_join(t, 0); 20 | return 0; 21 | } 22 | 23 | // CHECK: WARNING: ThreadSanitizer: data race 24 | -------------------------------------------------------------------------------- /test/tsan/static_init1.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | struct P { 7 | int x; 8 | int y; 9 | }; 10 | 11 | void *Thread(void *x) { 12 | static P p = {rand(), rand()}; 13 | if (p.x > RAND_MAX || p.y > RAND_MAX) 14 | exit(1); 15 | return 0; 16 | } 17 | 18 | int main() { 19 | pthread_t t[2]; 20 | pthread_create(&t[0], 0, Thread, 0); 21 | pthread_create(&t[1], 0, Thread, 0); 22 | pthread_join(t[0], 0); 23 | pthread_join(t[1], 0); 24 | printf("PASS\n"); 25 | } 26 | 27 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 28 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/Misc/deduplication.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=undefined %s -o %t && %run %t 2>&1 | FileCheck %s 2 | // Verify deduplication works by ensuring only one diag is emitted. 3 | #include 4 | #include 5 | 6 | void overflow() { 7 | int i = INT_MIN; 8 | --i; 9 | } 10 | 11 | int main() { 12 | // CHECK: Start 13 | fprintf(stderr, "Start\n"); 14 | fflush(stderr); 15 | 16 | // CHECK: runtime error 17 | // CHECK-NOT: runtime error 18 | // CHECK-NOT: runtime error 19 | overflow(); 20 | overflow(); 21 | overflow(); 22 | 23 | // CHECK: End 24 | fprintf(stderr, "End\n"); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /test/asan/TestCases/time_interceptor.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | 3 | // Test the time() interceptor. 4 | 5 | // There's no interceptor for time() on Windows yet. 6 | // XFAIL: win32 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int main() { 13 | time_t *tm = (time_t*)malloc(sizeof(time_t)); 14 | free(tm); 15 | time_t t = time(tm); 16 | printf("Time: %s\n", ctime(&t)); // NOLINT 17 | // CHECK: use-after-free 18 | // Regression check for 19 | // https://code.google.com/p/address-sanitizer/issues/detail?id=321 20 | // CHECK: SUMMARY 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/asan/TestCases/use-after-scope.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \ 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // RUN: %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s 4 | // XFAIL: * 5 | 6 | int main() { 7 | int *p = 0; 8 | { 9 | int x = 0; 10 | p = &x; 11 | } 12 | return *p; // BOOM 13 | // CHECK: ERROR: AddressSanitizer: stack-use-after-scope 14 | // CHECK: #0 0x{{.*}} in main {{.*}}use-after-scope.cc:[[@LINE-2]] 15 | // CHECK: Address 0x{{.*}} is located in stack of thread T{{.*}} at offset [[OFFSET:[^ ]+]] in frame 16 | // {{\[}}[[OFFSET]], {{[0-9]+}}) 'x' 17 | } 18 | -------------------------------------------------------------------------------- /test/tsan/halt_on_error.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | int X; 5 | 6 | void *Thread(void *x) { 7 | barrier_wait(&barrier); 8 | X = 42; 9 | return 0; 10 | } 11 | 12 | int main() { 13 | barrier_init(&barrier, 2); 14 | fprintf(stderr, "BEFORE\n"); 15 | pthread_t t; 16 | pthread_create(&t, 0, Thread, 0); 17 | X = 43; 18 | barrier_wait(&barrier); 19 | pthread_join(t, 0); 20 | fprintf(stderr, "AFTER\n"); 21 | return 0; 22 | } 23 | 24 | // CHECK: BEFORE 25 | // CHECK: WARNING: ThreadSanitizer: data race 26 | // CHECK-NOT: AFTER 27 | 28 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/dll_and_lib.cc: -------------------------------------------------------------------------------- 1 | // Just make sure we can link an implib into another DLL 2 | // This used to fail between r212699 and r212814. 3 | // RUN: %clang_cl_asan -DCONFIG=1 %s -c -Fo%t.1.obj 4 | // RUN: link /nologo /DLL /OUT:%t.1.dll %t.1.obj %asan_dll_thunk 5 | // RUN: %clang_cl_asan -DCONFIG=2 %s -c -Fo%t.2.obj 6 | // RUN: link /nologo /DLL /OUT:%t.2.dll %t.2.obj %t.1.lib %asan_dll_thunk 7 | // REQUIRES: asan-static-runtime 8 | 9 | #if CONFIG==1 10 | extern "C" __declspec(dllexport) int f1() { 11 | int x = 0; 12 | return 1; 13 | } 14 | #else 15 | extern "C" __declspec(dllexport) int f2() { 16 | int x = 0; 17 | return 2; 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /test/msan/vector_cvt.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 | // RUN: %clangxx_msan -DPOSITIVE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 3 | // REQUIRES: x86_64-supported-target 4 | 5 | #include 6 | 7 | int to_int(double v) { 8 | __m128d t = _mm_set_sd(v); 9 | int x = _mm_cvtsd_si32(t); 10 | return x; 11 | // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value 12 | // CHECK: #{{.*}} in to_int{{.*}}vector_cvt.cc:[[@LINE-3]] 13 | } 14 | 15 | int main() { 16 | #ifdef POSITIVE 17 | double v; 18 | #else 19 | double v = 1.1; 20 | #endif 21 | double* volatile p = &v; 22 | int x = to_int(*p); 23 | return !x; 24 | } 25 | -------------------------------------------------------------------------------- /test/profile/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PROFILE_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 2 | set(PROFILE_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) 3 | 4 | set(PROFILE_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) 5 | if(NOT COMPILER_RT_STANDALONE_BUILD) 6 | list(APPEND PROFILE_TEST_DEPS profile llvm-profdata) 7 | endif() 8 | 9 | configure_lit_site_cfg( 10 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in 11 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg 12 | ) 13 | add_lit_testsuite(check-profile "Running the profile tests" 14 | ${CMAKE_CURRENT_BINARY_DIR} 15 | DEPENDS ${PROFILE_TEST_DEPS}) 16 | set_target_properties(check-profile PROPERTIES FOLDER "Profile tests") 17 | -------------------------------------------------------------------------------- /test/profile/instrprof-override-filename-with-env.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_profgen -o %t -O3 %s 2 | // RUN: env LLVM_PROFILE_FILE=%t.good.profraw %run %t %t.bad.profraw 3 | // RUN: llvm-profdata merge -o %t.profdata %t.good.profraw 4 | // RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s 5 | 6 | void __llvm_profile_override_default_filename(const char *); 7 | int main(int argc, const char *argv[]) { 8 | // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]] 9 | if (argc < 2) 10 | return 1; 11 | __llvm_profile_override_default_filename(argv[1]); 12 | return 0; 13 | } 14 | // CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2} 15 | -------------------------------------------------------------------------------- /test/profile/instrprof-reset-counters.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_profgen -o %t -O3 %s 2 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t 3 | // RUN: llvm-profdata merge -o %t.profdata %t.profraw 4 | // RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s 5 | 6 | void __llvm_profile_reset_counters(void); 7 | void foo(int); 8 | int main(void) { 9 | foo(0); 10 | __llvm_profile_reset_counters(); 11 | foo(1); 12 | return 0; 13 | } 14 | void foo(int N) { 15 | // CHECK-LABEL: define void @foo( 16 | // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[FOO:[0-9]+]] 17 | if (N) {} 18 | } 19 | // CHECK: ![[FOO]] = !{!"branch_weights", i32 2, i32 1} 20 | -------------------------------------------------------------------------------- /test/tsan/bench_release_only.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan %s -o %t 2 | // RUN: %run %t 2>&1 | FileCheck %s 3 | 4 | #include "bench.h" 5 | 6 | int *x; 7 | const int kStride = 32; 8 | 9 | void thread(int tid) { 10 | __atomic_load_n(&x[tid * kStride], __ATOMIC_ACQUIRE); 11 | for (int i = 0; i < bench_niter; i++) 12 | __atomic_store_n(&x[tid * kStride], 0, __ATOMIC_RELEASE); 13 | } 14 | 15 | void bench() { 16 | x = (int*)malloc(bench_nthread * kStride * sizeof(x[0])); 17 | for (int i = 0; i < bench_nthread; i++) 18 | __atomic_store_n(&x[i * kStride], 0, __ATOMIC_RELEASE); 19 | start_thread_group(bench_nthread, thread); 20 | } 21 | 22 | // CHECK: DONE 23 | 24 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/shadow_mapping_failure.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | char bigchunk[1 << 30]; 7 | 8 | int main() { 9 | printf("Hello, world!\n"); 10 | scanf("%s", bigchunk); 11 | // CHECK-NOT: Hello, world! 12 | // CHECK: Shadow memory range interleaves with an existing memory mapping. 13 | // CHECK: ASan shadow was supposed to be located in the [0x2fff0000-0x{{.*}}ffff] range. 14 | // CHECK: Dumping process modules: 15 | // CHECK-DAG: 0x{{[0-9a-f]*}}-0x{{[0-9a-f]*}} {{.*}}shadow_mapping_failure 16 | // CHECK-DAG: 0x{{[0-9a-f]*}}-0x{{[0-9a-f]*}} {{.*}}ntdll.dll 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/coverage-and-lsan.cc: -------------------------------------------------------------------------------- 1 | // Make sure coverage is dumped even if there are reported leaks. 2 | // 3 | // RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t 4 | // 5 | // RUN: rm -rf %T/coverage-and-lsan 6 | // 7 | // RUN: mkdir -p %T/coverage-and-lsan/normal 8 | // RUN: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-and-lsan:verbosity=1 not %run %t 2>&1 | FileCheck %s 9 | // RUN: %sancov print %T/coverage-and-lsan/*.sancov 2>&1 10 | // 11 | // REQUIRES: leak-detection 12 | 13 | int *g = new int; 14 | int main(int argc, char **argv) { 15 | g = 0; 16 | return 0; 17 | } 18 | 19 | // CHECK: LeakSanitizer: detected memory leaks 20 | // CHECK: CovDump: 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/partial_right.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s 4 | // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | int main(int argc, char **argv) { 8 | volatile int *x = (int*)malloc(2*sizeof(int) + 2); 9 | int res = x[2]; // BOOOM 10 | // CHECK: {{READ of size 4 at 0x.* thread T0}} 11 | // CHECK: [[ADDR:0x[01-9a-fa-f]+]] is located 0 bytes to the right of {{.*}}-byte region [{{.*}},{{.*}}[[ADDR]]) 12 | return res; 13 | } 14 | -------------------------------------------------------------------------------- /test/tsan/longjmp2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | 3 | // Longjmp assembly has not been implemented for mips64 or aarch64 yet 4 | // XFAIL: mips64 5 | // XFAIL: aarch64 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int foo(sigjmp_buf env) { 12 | printf("env=%p\n", env); 13 | siglongjmp(env, 42); 14 | } 15 | 16 | int main() { 17 | sigjmp_buf env; 18 | printf("env=%p\n", env); 19 | if (sigsetjmp(env, 1) == 42) { 20 | printf("JUMPED\n"); 21 | return 0; 22 | } 23 | foo(env); 24 | printf("FAILED\n"); 25 | return 0; 26 | } 27 | 28 | // CHECK-NOT: FAILED 29 | // CHECK: JUMPED 30 | -------------------------------------------------------------------------------- /lib/builtins/fixunsdfsi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixunsdfsi.c - Implement __fixunsdfsi -----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define DOUBLE_PRECISION 12 | #include "fp_lib.h" 13 | typedef su_int fixuint_t; 14 | #include "fp_fixuint_impl.inc" 15 | 16 | ARM_EABI_FNALIAS(d2uiz, fixunsdfsi) 17 | 18 | COMPILER_RT_ABI su_int 19 | __fixunsdfsi(fp_t a) { 20 | return __fixuint(a); 21 | } 22 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/dll_null_deref.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t 2 | // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll 3 | // RUN: not %run %t %t.dll 2>&1 | FileCheck %s 4 | 5 | __attribute__((noinline)) 6 | static void NullDeref(int *ptr) { 7 | // CHECK: ERROR: AddressSanitizer: access-violation on unknown address 8 | // CHECK: {{0x0*000.. .*pc 0x.*}} 9 | ptr[10]++; // BOOM 10 | } 11 | 12 | extern "C" __declspec(dllexport) 13 | int test_function() { 14 | NullDeref((int*)0); 15 | // CHECK: {{ #1 0x.* in test_function .*\dll_null_deref.cc:}}[[@LINE-1]] 16 | // CHECK: AddressSanitizer can not provide additional info. 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/msan/no_sanitize_memory_prop.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t >%t.out 2>&1 2 | // RUN: %clangxx_msan -O1 %s -o %t && %run %t >%t.out 2>&1 3 | // RUN: %clangxx_msan -O2 %s -o %t && %run %t >%t.out 2>&1 4 | // RUN: %clangxx_msan -O3 %s -o %t && %run %t >%t.out 2>&1 5 | 6 | // Test that (no_sanitize_memory) functions DO NOT propagate shadow. 7 | 8 | #include 9 | #include 10 | 11 | __attribute__((noinline)) 12 | __attribute__((no_sanitize_memory)) 13 | int f(int x) { 14 | return x; 15 | } 16 | 17 | int main(void) { 18 | int x; 19 | int * volatile p = &x; 20 | int y = f(*p); 21 | if (y) 22 | exit(0); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /test/asan/TestCases/Darwin/objc-odr.mm: -------------------------------------------------------------------------------- 1 | // Regression test for 2 | // https://code.google.com/p/address-sanitizer/issues/detail?id=360. 3 | 4 | // RUN: %clang_asan %s -o %t -framework Foundation 5 | // RUN: %run %t 2>&1 | FileCheck %s 6 | 7 | #import 8 | 9 | void f() { 10 | int y = 7; 11 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ 12 | dispatch_sync(dispatch_get_main_queue(), ^{ 13 | printf("num = %d\n", y); 14 | }); 15 | }); 16 | } 17 | 18 | int main() { 19 | NSLog(@"Hello world"); 20 | } 21 | 22 | // CHECK-NOT: AddressSanitizer: odr-violation 23 | // CHECK: Hello world 24 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/iostream_sbo.cc: -------------------------------------------------------------------------------- 1 | // First, check this works with the default blacklist: 2 | // RUN: %clang_cl_asan -O0 %s -Fe%t 3 | // RUN: echo "42" | %run %t 2>&1 | FileCheck %s 4 | // 5 | // Then, make sure it still works when a user uses his own blacklist file: 6 | // RUN: %clang_cl_asan -O0 %s -fsanitize-blacklist=%p/../Helpers/initialization-blacklist.txt -Fe%t2 7 | // RUN: echo "42" | %run %t2 2>&1 | FileCheck %s 8 | 9 | #include 10 | 11 | int main() { 12 | int i; 13 | std::cout << "Type i: "; 14 | std::cin >> i; 15 | return 0; 16 | // CHECK: Type i: 17 | // CHECK-NOT: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 18 | } 19 | -------------------------------------------------------------------------------- /test/safestack/buffer-copy.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_safestack %s -o %t 2 | // RUN: %run %t 3 | 4 | #include "utils.h" 5 | 6 | // Test that loads/stores work correctly for variables on the unsafe stack. 7 | 8 | int main(int argc, char **argv) 9 | { 10 | int i; 11 | char buffer[128]; 12 | 13 | // check that we can write to a buffer 14 | for (i = 0; argv[0][i] && i < sizeof (buffer) - 1; ++i) 15 | buffer[i] = argv[0][i]; 16 | buffer[i] = '\0'; 17 | 18 | break_optimization(buffer); 19 | 20 | // check that we can read from a buffer 21 | for (i = 0; argv[0][i] && i < sizeof (buffer) - 1; ++i) 22 | if (buffer[i] != argv[0][i]) 23 | return 1; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /test/tsan/simple_race.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | int Global; 5 | 6 | void *Thread1(void *x) { 7 | barrier_wait(&barrier); 8 | Global = 42; 9 | return NULL; 10 | } 11 | 12 | void *Thread2(void *x) { 13 | Global = 43; 14 | barrier_wait(&barrier); 15 | return NULL; 16 | } 17 | 18 | int main() { 19 | barrier_init(&barrier, 2); 20 | pthread_t t[2]; 21 | pthread_create(&t[0], NULL, Thread1, NULL); 22 | pthread_create(&t[1], NULL, Thread2, NULL); 23 | pthread_join(t[0], NULL); 24 | pthread_join(t[1], NULL); 25 | return 0; 26 | } 27 | 28 | // CHECK: WARNING: ThreadSanitizer: data race 29 | 30 | -------------------------------------------------------------------------------- /test/asan/TestCases/Darwin/abort_on_error.cc: -------------------------------------------------------------------------------- 1 | // Check that with empty ASAN_OPTIONS, ASan reports on OS X actually crash 2 | // the process (abort_on_error=1). See also Linux/abort_on_error.cc. 3 | 4 | // RUN: %clangxx_asan %s -o %t 5 | 6 | // Intentionally don't inherit the default ASAN_OPTIONS. 7 | // RUN: ASAN_OPTIONS="" not --crash %run %t 2>&1 | FileCheck %s 8 | // When we use lit's default ASAN_OPTIONS, we shouldn't crash. 9 | // RUN: not %run %t 2>&1 | FileCheck %s 10 | 11 | #include 12 | int main() { 13 | char *x = (char*)malloc(10 * sizeof(char)); 14 | free(x); 15 | return x[5]; 16 | // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/malloc_left_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | char *buffer = (char*)malloc(42); 8 | buffer[-1] = 42; 9 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 10 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 11 | // CHECK-NEXT: {{#0 .* main .*malloc_left_oob.cc}}:[[@LINE-3]] 12 | // CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region 13 | // CHECK: allocated by thread T0 here: 14 | // CHECK-NEXT: {{#0 .* malloc }} 15 | // CHECK-NEXT: {{#1 .* main .*malloc_left_oob.cc}}:[[@LINE-8]] 16 | free(buffer); 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/thread_simple.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: %run %t 3 | 4 | #include 5 | 6 | DWORD WINAPI thread_proc(void *) { 7 | volatile char stack_buffer[42]; 8 | for (int i = 0; i < sizeof(stack_buffer); ++i) 9 | stack_buffer[i] = 42; 10 | return 0x42; 11 | } 12 | 13 | int main() { 14 | DWORD exitcode; 15 | HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL); 16 | if (thr == 0) 17 | return 1; 18 | if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE)) 19 | return 2; 20 | 21 | GetExitCodeThread(thr, &exitcode); 22 | if (exitcode != 0x42) 23 | return 3; 24 | CloseHandle(thr); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /test/lsan/TestCases/link_turned_off.cc: -------------------------------------------------------------------------------- 1 | // Test for disabling LSan at link-time. 2 | // RUN: LSAN_BASE="use_stacks=0:use_registers=0" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 5 | // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t foo 2>&1 | FileCheck %s 6 | 7 | #include 8 | 9 | int argc_copy; 10 | 11 | extern "C" { 12 | int __lsan_is_turned_off() { 13 | return (argc_copy == 1); 14 | } 15 | } 16 | 17 | int main(int argc, char *argv[]) { 18 | volatile int *x = new int; 19 | *x = 42; 20 | argc_copy = argc; 21 | return 0; 22 | } 23 | 24 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 4 byte(s) leaked in 1 allocation(s) 25 | -------------------------------------------------------------------------------- /test/tsan/suppress_same_stacks.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include 3 | 4 | volatile int N; // Prevent loop unrolling. 5 | int **data; 6 | 7 | void *Thread1(void *x) { 8 | for (int i = 0; i < N; i++) 9 | data[i][0] = 42; 10 | return 0; 11 | } 12 | 13 | int main() { 14 | N = 4; 15 | data = new int*[N]; 16 | for (int i = 0; i < N; i++) 17 | data[i] = new int; 18 | pthread_t t; 19 | pthread_create(&t, 0, Thread1, 0); 20 | Thread1(0); 21 | pthread_join(t, 0); 22 | for (int i = 0; i < N; i++) 23 | delete data[i]; 24 | delete[] data; 25 | } 26 | 27 | // CHECK: ThreadSanitizer: reported 1 warnings 28 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/malloc_right_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | char *buffer = (char*)malloc(42); 8 | buffer[42] = 42; 9 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 10 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 11 | // CHECK-NEXT: {{#0 .* main .*malloc_right_oob.cc}}:[[@LINE-3]] 12 | // CHECK: [[ADDR]] is located 0 bytes to the right of 42-byte region 13 | // CHECK: allocated by thread T0 here: 14 | // CHECK-NEXT: {{#0 .* malloc }} 15 | // CHECK-NEXT: {{#1 .* main .*malloc_right_oob.cc}}:[[@LINE-8]] 16 | free(buffer); 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/operator_new_left_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | char *buffer = new char; 8 | buffer[-1] = 42; 9 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 10 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 11 | // CHECK: {{#0 .* main .*operator_new_left_oob.cc}}:[[@LINE-3]] 12 | // CHECK: [[ADDR]] is located 1 bytes to the left of 1-byte region 13 | // CHECK: allocated by thread T0 here: 14 | // CHECK: {{#0 .* operator new}} 15 | // CHECK: {{#1 .* main .*operator_new_left_oob.cc}}:[[@LINE-8]] 16 | delete buffer; 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/use-after-poison.cc: -------------------------------------------------------------------------------- 1 | // Check that __asan_poison_memory_region works. 2 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 3 | // 4 | // Check that we can disable it 5 | // RUN: %env_asan_opts=allow_user_poisoning=0 %run %t 6 | 7 | #include 8 | 9 | extern "C" void __asan_poison_memory_region(void *, size_t); 10 | 11 | int main(int argc, char **argv) { 12 | char *x = new char[16]; 13 | x[10] = 0; 14 | __asan_poison_memory_region(x, 16); 15 | int res = x[argc * 10]; // BOOOM 16 | // CHECK: ERROR: AddressSanitizer: use-after-poison 17 | // CHECK: main{{.*}}use-after-poison.cc:[[@LINE-2]] 18 | delete [] x; 19 | return res; 20 | } 21 | -------------------------------------------------------------------------------- /lib/builtins/fixdfsi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixdfsi.c - Implement __fixdfsi -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define DOUBLE_PRECISION 12 | #include "fp_lib.h" 13 | typedef si_int fixint_t; 14 | typedef su_int fixuint_t; 15 | #include "fp_fixint_impl.inc" 16 | 17 | ARM_EABI_FNALIAS(d2iz, fixdfsi) 18 | 19 | COMPILER_RT_ABI si_int 20 | __fixdfsi(fp_t a) { 21 | return __fixint(a); 22 | } 23 | -------------------------------------------------------------------------------- /lib/builtins/fixsfsi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixsfsi.c - Implement __fixsfsi -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define SINGLE_PRECISION 12 | #include "fp_lib.h" 13 | typedef si_int fixint_t; 14 | typedef su_int fixuint_t; 15 | #include "fp_fixint_impl.inc" 16 | 17 | ARM_EABI_FNALIAS(f2iz, fixsfsi) 18 | 19 | COMPILER_RT_ABI si_int 20 | __fixsfsi(fp_t a) { 21 | return __fixint(a); 22 | } 23 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/calloc_left_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | int *buffer = (int*)calloc(42, sizeof(int)); 8 | buffer[-1] = 42; 9 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 10 | // CHECK: WRITE of size 4 at [[ADDR]] thread T0 11 | // CHECK-NEXT: {{#0 .* main .*calloc_left_oob.cc}}:[[@LINE-3]] 12 | // CHECK: [[ADDR]] is located 4 bytes to the left of 168-byte region 13 | // CHECK: allocated by thread T0 here: 14 | // CHECK-NEXT: {{#0 .* calloc }} 15 | // CHECK-NEXT: {{#1 .* main .*calloc_left_oob.cc}}:[[@LINE-8]] 16 | free(buffer); 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/operator_new_right_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | char *buffer = new char; 8 | buffer[1] = 42; 9 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 10 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 11 | // CHECK: {{#0 .* main .*operator_new_right_oob.cc}}:[[@LINE-3]] 12 | // CHECK: [[ADDR]] is located 0 bytes to the right of 1-byte region 13 | // CHECK: allocated by thread T0 here: 14 | // CHECK: {{#0 .* operator new}} 15 | // CHECK: {{#1 .* main .*operator_new_right_oob.cc}}:[[@LINE-8]] 16 | delete buffer; 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/realloc_left_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | char *buffer = (char*)realloc(0, 42); 8 | buffer[-1] = 42; 9 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 10 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 11 | // CHECK-NEXT: {{#0 .* main .*realloc_left_oob.cc}}:[[@LINE-3]] 12 | // CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region 13 | // CHECK: allocated by thread T0 here: 14 | // CHECK-NEXT: {{#0 .* realloc }} 15 | // CHECK-NEXT: {{#1 .* main .*realloc_left_oob.cc}}:[[@LINE-8]] 16 | free(buffer); 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/realloc_right_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | char *buffer = (char*)realloc(0, 42); 8 | buffer[42] = 42; 9 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 10 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 11 | // CHECK-NEXT: {{#0 .* main .*realloc_right_oob.cc}}:[[@LINE-3]] 12 | // CHECK: [[ADDR]] is located 0 bytes to the right of 42-byte region 13 | // CHECK: allocated by thread T0 here: 14 | // CHECK-NEXT: {{#0 .* realloc }} 15 | // CHECK-NEXT: {{#1 .* main .*realloc_right_oob.cc}}:[[@LINE-8]] 16 | free(buffer); 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/memcmp_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s 4 | // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s 5 | 6 | // REQUIRES: compiler-rt-optimized 7 | 8 | #include 9 | int main(int argc, char **argv) { 10 | char a1[] = {argc, 2, 3, 4}; 11 | char a2[] = {1, 2*argc, 3, 4}; 12 | int res = memcmp(a1, a2, 4 + argc); // BOOM 13 | // CHECK: AddressSanitizer: stack-buffer-overflow 14 | // CHECK: {{#0.*memcmp}} 15 | // CHECK: {{#1.*main}} 16 | return res; 17 | } 18 | -------------------------------------------------------------------------------- /test/asan/TestCases/vla_loop_overfow.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // 4 | // REQUIRES: stable-runtime 5 | 6 | #include 7 | #include 8 | 9 | void foo(int index, int len) { 10 | for (int i = 1; i < len; ++i) { 11 | char array[len]; // NOLINT 12 | assert(!(reinterpret_cast(array) & 31L)); 13 | array[index + i] = 0; 14 | // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 15 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 16 | } 17 | } 18 | 19 | int main(int argc, char **argv) { 20 | foo(9, 21); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/msan/msan_dump_shadow.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t >%t.out 2>&1 2 | // RUN: FileCheck %s < %t.out 3 | 4 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 -g %s -o %t && %run %t >%t.out 2>&1 5 | // RUN: FileCheck %s < %t.out 6 | 7 | // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O0 -g %s -o %t && %run %t >%t.out 2>&1 8 | // RUN: FileCheck %s < %t.out 9 | 10 | #include 11 | 12 | int main(void) { 13 | char *p = new char[16]; 14 | __msan_dump_shadow(p, 5); 15 | delete[] p; 16 | const char *q = "abc"; 17 | __msan_dump_shadow(q, 3); 18 | return 0; 19 | } 20 | 21 | // CHECK: ff ff ff ff ff 22 | // CHECK: 00 00 00 23 | -------------------------------------------------------------------------------- /test/sanitizer_common/Unit/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | ## Autogenerated by LLVM/Clang configuration. 2 | # Do not edit! 3 | 4 | # Load common config for all compiler-rt unit tests. 5 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured") 6 | 7 | # Setup config name. 8 | config.name = 'SanitizerCommon-Unit' 9 | 10 | # Setup test source and exec root. For unit tests, we define 11 | # it as build directory with sanitizer_common tests. 12 | # FIXME: De-hardcode this path. 13 | config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@", "lib", 14 | "sanitizer_common", "tests") 15 | config.test_source_root = config.test_exec_root 16 | -------------------------------------------------------------------------------- /test/tsan/stack_race2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread2(void *a) { 5 | barrier_wait(&barrier); 6 | *(int*)a = 43; 7 | return 0; 8 | } 9 | 10 | void *Thread(void *a) { 11 | int Var = 42; 12 | pthread_t t; 13 | pthread_create(&t, 0, Thread2, &Var); 14 | Var = 42; 15 | barrier_wait(&barrier); 16 | pthread_join(t, 0); 17 | return 0; 18 | } 19 | 20 | int main() { 21 | barrier_init(&barrier, 2); 22 | pthread_t t; 23 | pthread_create(&t, 0, Thread, 0); 24 | pthread_join(t, 0); 25 | } 26 | 27 | // CHECK: WARNING: ThreadSanitizer: data race 28 | // CHECK: Location is stack of thread T1. 29 | 30 | -------------------------------------------------------------------------------- /test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -g %s -O3 -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | // REQUIRES: cxxabi 5 | 6 | struct S { virtual int f() { return 0; } }; 7 | struct T : virtual S {}; 8 | 9 | struct Foo { virtual int f() { return 0; } }; 10 | 11 | int main(int argc, char **argv) { 12 | Foo foo; 13 | T *t = (T*)&foo; 14 | S *s = t; 15 | // CHECK: vptr-virtual-base.cpp:[[@LINE-1]]:10: runtime error: cast to virtual base of address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T' 16 | // CHECK-NEXT: [[PTR]]: note: object is of type 'Foo' 17 | return s->f(); 18 | } 19 | -------------------------------------------------------------------------------- /lib/builtins/arm/softfloat-alias.list: -------------------------------------------------------------------------------- 1 | # 2 | # These are soft float functions which can be 3 | # aliased to the *vfp functions on arm processors 4 | # that support floating point instructions. 5 | # 6 | ___adddf3vfp ___adddf3 7 | ___addsf3vfp ___addsf3 8 | ___divdf3vfp ___divdf3 9 | ___divsf3vfp ___divsf3 10 | ___extendsfdf2vfp ___extendsfdf2 11 | ___fixdfsivfp ___fixdfsi 12 | ___fixsfsivfp ___fixsfsi 13 | ___floatsidfvfp ___floatsidf 14 | ___floatsisfvfp ___floatsisf 15 | ___muldf3vfp ___muldf3 16 | ___mulsf3vfp ___mulsf3 17 | ___subdf3vfp ___subdf3 18 | ___subsf3vfp ___subsf3 19 | ___truncdfsf2vfp ___truncdfsf2 20 | ___floatunssidfvfp ___floatunsidf 21 | ___floatunssisfvfp ___floatunsisf 22 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/calloc_right_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | int *buffer = (int*)calloc(42, sizeof(int)); 8 | buffer[42] = 42; 9 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 10 | // CHECK: WRITE of size 4 at [[ADDR]] thread T0 11 | // CHECK-NEXT: {{#0 .* main .*calloc_right_oob.cc}}:[[@LINE-3]] 12 | // CHECK: [[ADDR]] is located 0 bytes to the right of 168-byte region 13 | // CHECK: allocated by thread T0 here: 14 | // CHECK-NEXT: {{#0 .* calloc }} 15 | // CHECK-NEXT: {{#1 .* main .*calloc_right_oob.cc}}:[[@LINE-8]] 16 | free(buffer); 17 | } 18 | -------------------------------------------------------------------------------- /test/tsan/global_race2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | int x; 5 | 6 | void *Thread(void *a) { 7 | barrier_wait(&barrier); 8 | x = 1; 9 | return 0; 10 | } 11 | 12 | int main() { 13 | barrier_init(&barrier, 2); 14 | fprintf(stderr, "addr2="); 15 | print_address(&x); 16 | fprintf(stderr, "\n"); 17 | pthread_t t; 18 | pthread_create(&t, 0, Thread, 0); 19 | x = 0; 20 | barrier_wait(&barrier); 21 | pthread_join(t, 0); 22 | } 23 | 24 | // CHECK: addr2=[[ADDR2:0x[0-9,a-f]+]] 25 | // CHECK: WARNING: ThreadSanitizer: data race 26 | // CHECK: Location is global 'x' of size 4 at [[ADDR2]] ({{.*}}+0x{{[0-9,a-f]+}}) 27 | 28 | -------------------------------------------------------------------------------- /lib/builtins/Darwin-excludes/README.TXT: -------------------------------------------------------------------------------- 1 | This folder contains list of symbols that should be excluded from the builtin 2 | libraries for Darwin. There are two reasons symbols are excluded: 3 | 4 | (1) They aren't supported on Darwin 5 | (2) They are contained within the OS on the minimum supported target 6 | 7 | The builtin libraries must contain all symbols not provided by the lowest 8 | supported target OS. Meaning if minimum deployment target is iOS 6, all builtins 9 | not included in the ios6-.txt files need to be included. The one catch is 10 | that this is per-architecture. Since iOS 6 doesn't support arm64, when supporting 11 | iOS 6, the minimum deployment target for arm64 binaries is iOS 7. 12 | -------------------------------------------------------------------------------- /lib/builtins/fixunstfdi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixunstfdi.c - Implement __fixunstfdi -----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define QUAD_PRECISION 12 | #include "fp_lib.h" 13 | 14 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 15 | typedef du_int fixuint_t; 16 | #include "fp_fixuint_impl.inc" 17 | 18 | COMPILER_RT_ABI du_int 19 | __fixunstfdi(fp_t a) { 20 | return __fixuint(a); 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/builtins/fixunstfsi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixunstfsi.c - Implement __fixunstfsi -----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define QUAD_PRECISION 12 | #include "fp_lib.h" 13 | 14 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 15 | typedef su_int fixuint_t; 16 | #include "fp_fixuint_impl.inc" 17 | 18 | COMPILER_RT_ABI su_int 19 | __fixunstfsi(fp_t a) { 20 | return __fixuint(a); 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/builtins/fixunstfti.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixunstfsi.c - Implement __fixunstfsi -----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define QUAD_PRECISION 12 | #include "fp_lib.h" 13 | 14 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 15 | typedef tu_int fixuint_t; 16 | #include "fp_fixuint_impl.inc" 17 | 18 | COMPILER_RT_ABI tu_int 19 | __fixunstfti(fp_t a) { 20 | return __fixuint(a); 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/profile/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/profile/Makefile.mk ------------------------------*- Makefile -*--===# 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is distributed under the University of Illinois Open Source 6 | # License. See LICENSE.TXT for details. 7 | # 8 | #===------------------------------------------------------------------------===# 9 | 10 | ModuleName := profile 11 | SubDirs := 12 | 13 | Sources := $(foreach file,$(wildcard $(Dir)/*.c $(Dir)/*.cc),$(notdir $(file))) 14 | ObjNames := $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(Sources))) 15 | Implementation := Generic 16 | 17 | # FIXME: use automatic dependencies? 18 | Dependencies := $(wildcard $(Dir)/*.h) 19 | -------------------------------------------------------------------------------- /test/asan/TestCases/describe_address.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | 3 | #include 4 | 5 | int global; 6 | 7 | int main(int argc, char *argv[]) { 8 | int stack; 9 | int *heap = new int[100]; 10 | __asan_describe_address(heap); 11 | // CHECK: {{.*}} is located 0 bytes inside of 400-byte region 12 | // CHECK: allocated by thread T{{.*}} here 13 | __asan_describe_address(&stack); 14 | // CHECK: Address {{.*}} is located in stack of thread T{{.*}} at offset {{.*}} 15 | __asan_describe_address(&global); 16 | // CHECK: {{.*}} is located 0 bytes inside of global variable 'global' 17 | delete[] heap; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/tsan/malloc_stack.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | _Atomic(int*) p; 5 | 6 | void *thr(void *a) { 7 | barrier_wait(&barrier); 8 | int *pp = __c11_atomic_load(&p, __ATOMIC_RELAXED); 9 | *pp = 42; 10 | return 0; 11 | } 12 | 13 | int main() { 14 | barrier_init(&barrier, 2); 15 | pthread_t th; 16 | pthread_create(&th, 0, thr, p); 17 | __c11_atomic_store(&p, new int, __ATOMIC_RELAXED); 18 | barrier_wait(&barrier); 19 | pthread_join(th, 0); 20 | } 21 | 22 | // CHECK: data race 23 | // CHECK: Previous write 24 | // CHECK: #0 operator new 25 | // CHECK: Location is heap block 26 | // CHECK: #0 operator new 27 | -------------------------------------------------------------------------------- /test/tsan/thread_end_with_ignore.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include 3 | #include 4 | 5 | extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l); 6 | 7 | void *Thread(void *x) { 8 | AnnotateIgnoreReadsBegin("", 0); 9 | return 0; 10 | } 11 | 12 | int main() { 13 | pthread_t t; 14 | pthread_create(&t, 0, Thread, 0); 15 | pthread_join(t, 0); 16 | } 17 | 18 | // CHECK: ThreadSanitizer: thread T1 finished with ignores enabled, created at: 19 | // CHECK: #0 pthread_create 20 | // CHECK: #1 main 21 | // CHECK: Ignore was enabled at: 22 | // CHECK: #0 AnnotateIgnoreReadsBegin 23 | // CHECK: #1 Thread 24 | 25 | -------------------------------------------------------------------------------- /test/tsan/tls_race2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | void *Thread2(void *a) { 5 | barrier_wait(&barrier); 6 | *(int*)a = 43; 7 | return 0; 8 | } 9 | 10 | void *Thread(void *a) { 11 | static __thread int Var = 42; 12 | pthread_t t; 13 | pthread_create(&t, 0, Thread2, &Var); 14 | Var = 42; 15 | barrier_wait(&barrier); 16 | pthread_join(t, 0); 17 | return 0; 18 | } 19 | 20 | int main() { 21 | barrier_init(&barrier, 2); 22 | pthread_t t; 23 | pthread_create(&t, 0, Thread, 0); 24 | pthread_join(t, 0); 25 | } 26 | 27 | // CHECK: WARNING: ThreadSanitizer: data race 28 | // CHECK: Location is TLS of thread T1. 29 | 30 | -------------------------------------------------------------------------------- /test/tsan/race_on_puts.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | char s[] = "abracadabra"; 5 | 6 | void *Thread0(void *p) { 7 | puts(s); 8 | barrier_wait(&barrier); 9 | return 0; 10 | } 11 | 12 | void *Thread1(void *p) { 13 | barrier_wait(&barrier); 14 | s[3] = 'z'; 15 | return 0; 16 | } 17 | 18 | int main() { 19 | barrier_init(&barrier, 2); 20 | pthread_t th[2]; 21 | pthread_create(&th[0], 0, Thread0, 0); 22 | pthread_create(&th[1], 0, Thread1, 0); 23 | pthread_join(th[0], 0); 24 | pthread_join(th[1], 0); 25 | fprintf(stderr, "DONE"); 26 | } 27 | 28 | // CHECK: WARNING: ThreadSanitizer: data race 29 | // CHECK: DONE 30 | 31 | -------------------------------------------------------------------------------- /test/tsan/setuid.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | #include "test.h" 3 | #include 4 | #include 5 | 6 | // Setuid call used to hang because the background tsan thread did not handle 7 | // SIGSETXID signal. Note that we don't care whether setuid call succeeds 8 | // or not. 9 | 10 | static void *thread(void *arg) { 11 | (void)arg; 12 | sleep(1); 13 | return 0; 14 | } 15 | 16 | int main() { 17 | // Create another thread just for completeness of the picture. 18 | pthread_t th; 19 | pthread_create(&th, 0, thread, 0); 20 | setuid(0); 21 | pthread_join(th, 0); 22 | fprintf(stderr, "DONE\n"); 23 | return 0; 24 | } 25 | 26 | // CHECK: DONE 27 | -------------------------------------------------------------------------------- /test/tsan/vptr_harmful_race4.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include "test.h" 3 | 4 | struct A { 5 | virtual void F() { 6 | } 7 | 8 | virtual ~A() { 9 | } 10 | }; 11 | 12 | struct B : A { 13 | virtual void F() { 14 | } 15 | }; 16 | 17 | void *Thread(void *x) { 18 | barrier_wait(&barrier); 19 | ((A*)x)->F(); 20 | return 0; 21 | } 22 | 23 | int main() { 24 | barrier_init(&barrier, 2); 25 | A *obj = new B; 26 | pthread_t t; 27 | pthread_create(&t, 0, Thread, obj); 28 | delete obj; 29 | barrier_wait(&barrier); 30 | pthread_join(t, 0); 31 | } 32 | 33 | // CHECK: WARNING: ThreadSanitizer: heap-use-after-free (virtual call vs free) 34 | 35 | -------------------------------------------------------------------------------- /cmake/Modules/CompilerRTLink.cmake: -------------------------------------------------------------------------------- 1 | # Link a shared library with COMPILER_RT_TEST_COMPILER. 2 | # clang_link_shared( 3 | # OBJECTS 4 | # LINKFLAGS 5 | # DEPS ) 6 | macro(clang_link_shared so_file) 7 | cmake_parse_arguments(SOURCE "" "" "OBJECTS;LINKFLAGS;DEPS" ${ARGN}) 8 | if(NOT COMPILER_RT_STANDALONE_BUILD) 9 | list(APPEND SOURCE_DEPS clang) 10 | endif() 11 | add_custom_command( 12 | OUTPUT ${so_file} 13 | COMMAND ${COMPILER_RT_TEST_COMPILER} -o "${so_file}" -shared 14 | ${SOURCE_LINKFLAGS} ${SOURCE_OBJECTS} 15 | DEPENDS ${SOURCE_DEPS}) 16 | endmacro() 17 | -------------------------------------------------------------------------------- /lib/asan/tests/asan_mac_test.h: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | void *CFAllocatorDefaultDoubleFree(void *unused); 3 | void CFAllocatorSystemDefaultDoubleFree(); 4 | void CFAllocatorMallocDoubleFree(); 5 | void CFAllocatorMallocZoneDoubleFree(); 6 | void CallFreeOnWorkqueue(void *mem); 7 | void TestGCDDispatchAsync(); 8 | void TestGCDDispatchSync(); 9 | void TestGCDReuseWqthreadsAsync(); 10 | void TestGCDReuseWqthreadsSync(); 11 | void TestGCDDispatchAfter(); 12 | void TestGCDInTSDDestructor(); 13 | void TestGCDSourceEvent(); 14 | void TestGCDSourceCancel(); 15 | void TestGCDGroupAsync(); 16 | void TestOOBNSObjects(); 17 | void TestNSURLDeallocation(); 18 | void TestPassCFMemoryToAnotherThread(); 19 | } 20 | -------------------------------------------------------------------------------- /lib/interception/interception_mac.cc: -------------------------------------------------------------------------------- 1 | //===-- interception_mac.cc -------------------------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file is a part of AddressSanitizer, an address sanity checker. 11 | // 12 | // Mac-specific interception methods. 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifdef __APPLE__ 16 | 17 | #include "interception.h" 18 | 19 | 20 | #endif // __APPLE__ 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/stack_array_left_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | int subscript = -1; 8 | char buffer[42]; 9 | buffer[subscript] = 42; 10 | // CHECK: AddressSanitizer: stack-buffer-underflow on address [[ADDR:0x[0-9a-f]+]] 11 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 12 | // CHECK-NEXT: {{#0 .* main .*stack_array_left_oob.cc}}:[[@LINE-3]] 13 | // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame 14 | // CHECK-NEXT: {{#0 .* main .*stack_array_left_oob.cc}} 15 | // CHECK: 'buffer' <== Memory access at offset [[OFFSET]] underflows this variable 16 | } 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/stack_array_right_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int main() { 7 | int subscript = 42; 8 | char buffer[42]; 9 | buffer[subscript] = 42; 10 | // CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 11 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 12 | // CHECK-NEXT: {{#0 .* main .*stack_array_right_oob.cc}}:[[@LINE-3]] 13 | // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame 14 | // CHECK-NEXT: {{#0 .* main .*stack_array_right_oob.cc}} 15 | // CHECK: 'buffer' <== Memory access at offset [[OFFSET]] overflows this variable 16 | } 17 | -------------------------------------------------------------------------------- /test/asan/TestCases/heap-overflow-large.cc: -------------------------------------------------------------------------------- 1 | // Regression test for 2 | // https://code.google.com/p/address-sanitizer/issues/detail?id=183 3 | 4 | // RUN: %clangxx_asan -O2 %s -o %t 5 | // RUN: not %run %t 12 2>&1 | FileCheck %s 6 | // RUN: not %run %t 100 2>&1 | FileCheck %s 7 | // RUN: not %run %t 10000 2>&1 | FileCheck %s 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main(int argc, char *argv[]) { 14 | fprintf(stderr, "main\n"); 15 | int *x = new int[5]; 16 | memset(x, 0, sizeof(x[0]) * 5); 17 | int index = atoi(argv[1]); 18 | unsigned res = x[index]; 19 | // CHECK: main 20 | // CHECK-NOT: CHECK failed 21 | delete[] x; 22 | return (res % 10) + 1; 23 | } 24 | -------------------------------------------------------------------------------- /test/asan/TestCases/strcspn-2.c: -------------------------------------------------------------------------------- 1 | // Test stopset overflow in strcspn function 2 | // RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s 3 | 4 | // Test intercept_strcspn asan option 5 | // RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main(int argc, char **argv) { 12 | size_t r; 13 | char s1[] = "ab"; 14 | char s2[4] = "abc"; 15 | __asan_poison_memory_region ((char *)&s2[2], 2); 16 | r = strcspn(s1, s2); 17 | // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable 18 | assert(r == 0); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/strpbrk-2.c: -------------------------------------------------------------------------------- 1 | // Test stopset overflow in strpbrk function 2 | // RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s 3 | 4 | // Test intercept_strpbrk asan option 5 | // RUN: %env_asan_opts=intercept_strpbrk=false %run %t 2>&1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main(int argc, char **argv) { 12 | char *r; 13 | char s1[] = "c"; 14 | char s2[4] = "bca"; 15 | __asan_poison_memory_region ((char *)&s2[2], 2); 16 | r = strpbrk(s1, s2); 17 | // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable 18 | assert(r == s1); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/strspn-1.c: -------------------------------------------------------------------------------- 1 | // Test string s1 overflow in strspn function 2 | // RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s 3 | 4 | // Test intercept_strspn asan option 5 | // RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main(int argc, char **argv) { 12 | size_t r; 13 | char s2[] = "ab"; 14 | char s1[4] = "acb"; 15 | __asan_poison_memory_region ((char *)&s1[2], 2); 16 | r = strspn(s1, s2); 17 | // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable 18 | assert(r == 1); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/strspn-2.c: -------------------------------------------------------------------------------- 1 | // Test stopset overflow in strspn function 2 | // RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s 3 | 4 | // Test intercept_strspn asan option 5 | // RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main(int argc, char **argv) { 12 | size_t r; 13 | char s1[] = "bbc"; 14 | char s2[5] = "abcd"; 15 | __asan_poison_memory_region ((char *)&s2[3], 2); 16 | r = strspn(s1, s2); 17 | // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable 18 | assert(r >= 2); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/asan/TestCases/vla_condition_overflow.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // 4 | // REQUIRES: stable-runtime 5 | 6 | #include 7 | #include 8 | 9 | __attribute__((noinline)) void foo(int index, int len) { 10 | if (index > len) { 11 | char str[len]; //NOLINT 12 | assert(!(reinterpret_cast(str) & 31L)); 13 | str[index] = '1'; // BOOM 14 | // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 15 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 16 | } 17 | } 18 | 19 | int main(int argc, char **argv) { 20 | foo(33, 10); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/safestack/buffer-copy-vla.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_safestack %s -o %t 2 | // RUN: %run %t 3 | 4 | #include "utils.h" 5 | 6 | // Test that loads/stores work correctly for VLAs on the unsafe stack. 7 | 8 | int main(int argc, char **argv) 9 | { 10 | int i = 128; 11 | break_optimization(&i); 12 | char buffer[i]; 13 | 14 | // check that we can write to a buffer 15 | for (i = 0; argv[0][i] && i < sizeof (buffer) - 1; ++i) 16 | buffer[i] = argv[0][i]; 17 | buffer[i] = '\0'; 18 | 19 | break_optimization(buffer); 20 | 21 | // check that we can read from a buffer 22 | for (i = 0; argv[0][i] && i < sizeof (buffer) - 1; ++i) 23 | if (buffer[i] != argv[0][i]) 24 | return 1; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /www/content.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | padding:0px; 3 | font-size:small; font-family:"Lucida Grande", "Lucida Sans Unicode", Arial, Verdana, Helvetica, sans-serif; background-color: #fff; color: #222; 4 | line-height:1.5; 5 | } 6 | 7 | h1, h2, h3, tt { color: #000 } 8 | 9 | h1 { padding-top:0px; margin-top:0px;} 10 | h2 { color:#333333; padding-top:0.5em; } 11 | h3 { padding-top: 0.5em; margin-bottom: -0.25em; color:#2d58b7} 12 | li { padding-bottom: 0.5em; } 13 | ul { padding-left:1.5em; } 14 | 15 | /* Slides */ 16 | IMG.img_slide { 17 | display: block; 18 | margin-left: auto; 19 | margin-right: auto 20 | } 21 | 22 | .itemTitle { color:#2d58b7 } 23 | 24 | /* Tables */ 25 | tr { vertical-align:top } 26 | -------------------------------------------------------------------------------- /lib/builtins/fixunsdfti.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixunsdfti.c - Implement __fixunsdfti -----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #include "int_lib.h" 12 | 13 | #ifdef CRT_HAS_128BIT 14 | #define DOUBLE_PRECISION 15 | #include "fp_lib.h" 16 | typedef tu_int fixuint_t; 17 | #include "fp_fixuint_impl.inc" 18 | 19 | COMPILER_RT_ABI tu_int 20 | __fixunsdfti(fp_t a) { 21 | return __fixuint(a); 22 | } 23 | #endif /* CRT_HAS_128BIT */ 24 | -------------------------------------------------------------------------------- /test/asan/TestCases/Linux/asan_preload_test-2.cc: -------------------------------------------------------------------------------- 1 | // Test that preloaded runtime works with unsanitized executables. 2 | // 3 | // RUN: %clangxx %s -o %t 4 | // RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s 5 | 6 | // REQUIRES: asan-dynamic-runtime 7 | 8 | // This way of setting LD_PRELOAD does not work with Android test runner. 9 | // REQUIRES: not-android 10 | 11 | #include 12 | 13 | extern "C" ssize_t write(int fd, const void *buf, size_t count); 14 | 15 | void do_access(void *p) { 16 | // CHECK: AddressSanitizer: heap-buffer-overflow 17 | write(1, p, 2); 18 | } 19 | 20 | int main(int argc, char **argv) { 21 | void *p = malloc(1); 22 | do_access(p); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/coverage-basic.cc: -------------------------------------------------------------------------------- 1 | // RUN: rm -rf %T/coverage-basic 2 | // RUN: mkdir %T/coverage-basic && cd %T/coverage-basic 3 | // RUN: %clangxx_asan -fsanitize-coverage=func %s -o test.exe 4 | // RUN: %env_asan_opts=coverage=1 %run ./test.exe 5 | // 6 | // RUN: %sancov print *.sancov | FileCheck %s 7 | #include 8 | 9 | void foo() { fprintf(stderr, "FOO\n"); } 10 | void bar() { fprintf(stderr, "BAR\n"); } 11 | 12 | int main(int argc, char **argv) { 13 | if (argc == 2) { 14 | foo(); 15 | bar(); 16 | } else { 17 | bar(); 18 | foo(); 19 | } 20 | } 21 | 22 | // CHECK: 0x{{[0-9a-f]*}} 23 | // CHECK: 0x{{[0-9a-f]*}} 24 | // CHECK: 0x{{[0-9a-f]*}} 25 | // CHECK-NOT: 0x{{[0-9a-f]*}} 26 | -------------------------------------------------------------------------------- /test/asan/TestCases/alloca_detect_custom_size_.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t 2 | // RUN: not %run %t 2>&1 | FileCheck %s 3 | // 4 | 5 | #include 6 | 7 | struct A { 8 | char a[3]; 9 | int b[3]; 10 | }; 11 | 12 | __attribute__((noinline)) void foo(int index, int len) { 13 | volatile struct A str[len] __attribute__((aligned(32))); 14 | assert(!(reinterpret_cast(str) & 31L)); 15 | str[index].a[0] = '1'; // BOOM 16 | // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 17 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 18 | } 19 | 20 | int main(int argc, char **argv) { 21 | foo(10, 10); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /test/asan/TestCases/sanity_check_pure_c.c: -------------------------------------------------------------------------------- 1 | // Sanity checking a test in pure C. 2 | // RUN: %clang_asan -O2 %s -o %t 3 | // RUN: not %run %t 2>&1 | FileCheck %s 4 | 5 | // Sanity checking a test in pure C with -pie. 6 | // RUN: %clang_asan -O2 %s -pie -fPIE -o %t 7 | // RUN: not %run %t 2>&1 | FileCheck %s 8 | // XFAIL: arm-linux-gnueabi 9 | // XFAIL: armv7l-unknown-linux-gnueabihf 10 | 11 | #include 12 | int main() { 13 | char *x = (char*)malloc(10 * sizeof(char)); 14 | free(x); 15 | return x[5]; 16 | // CHECK: heap-use-after-free 17 | // CHECK: free 18 | // CHECK: main{{.*}}sanity_check_pure_c.c:[[@LINE-4]] 19 | // CHECK: malloc 20 | // CHECK: main{{.*}}sanity_check_pure_c.c:[[@LINE-7]] 21 | } 22 | -------------------------------------------------------------------------------- /test/asan/TestCases/strcspn-1.c: -------------------------------------------------------------------------------- 1 | // Test string s1 overflow in strcspn function 2 | // RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s 3 | 4 | // Test intercept_strspn asan option 5 | // RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main(int argc, char **argv) { 12 | size_t r; 13 | char s2[] = "ab"; 14 | char s1[4] = "caB"; 15 | __asan_poison_memory_region ((char *)&s1[2], 2); 16 | r = strcspn(s1, s2); 17 | // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable 18 | assert(r == 1); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/msan/sigwait.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -std=c++11 -O0 -g %s -o %t && %run %t 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void test_sigwait() { 10 | sigset_t s; 11 | sigemptyset(&s); 12 | sigaddset(&s, SIGUSR1); 13 | sigprocmask(SIG_BLOCK, &s, 0); 14 | 15 | if (pid_t pid = fork()) { 16 | kill(pid, SIGUSR1); 17 | _exit(0); 18 | } else { 19 | int sig; 20 | int res = sigwait(&s, &sig); 21 | assert(!res); 22 | // The following checks that sig is initialized. 23 | assert(sig == SIGUSR1); 24 | } 25 | } 26 | 27 | int main(void) { 28 | test_sigwait(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /test/tsan/fd_close_norace2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int pipes[2]; 7 | 8 | void *Thread(void *x) { 9 | // wait for shutown signal 10 | while (read(pipes[0], &x, 1) != 1) { 11 | } 12 | close(pipes[0]); 13 | close(pipes[1]); 14 | return 0; 15 | } 16 | 17 | int main() { 18 | if (pipe(pipes)) 19 | return 1; 20 | pthread_t t; 21 | pthread_create(&t, 0, Thread, 0); 22 | // send shutdown signal 23 | while (write(pipes[1], &t, 1) != 1) { 24 | } 25 | pthread_join(t, 0); 26 | printf("OK\n"); 27 | } 28 | 29 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 30 | // CHECK: OK 31 | -------------------------------------------------------------------------------- /test/tsan/free_race2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | #include 3 | 4 | void __attribute__((noinline)) foo(int *mem) { 5 | free(mem); 6 | } 7 | 8 | void __attribute__((noinline)) bar(int *mem) { 9 | mem[0] = 42; 10 | } 11 | 12 | int main() { 13 | int *mem = (int*)malloc(100); 14 | foo(mem); 15 | bar(mem); 16 | return 0; 17 | } 18 | 19 | // CHECK: WARNING: ThreadSanitizer: heap-use-after-free 20 | // CHECK: Write of size 4 at {{.*}} by main thread: 21 | // CHECK: #0 bar 22 | // CHECK: #1 main 23 | // CHECK: Previous write of size 8 at {{.*}} by main thread: 24 | // CHECK: #0 free 25 | // CHECK: #{{1|2}} foo 26 | // CHECK: #{{2|3}} main 27 | -------------------------------------------------------------------------------- /test/tsan/mutex_bad_unlock.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 | extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw); 3 | 4 | int main() { 5 | int m = 0; 6 | AnnotateRWLockReleased(__FILE__, __LINE__, &m, 1); 7 | return 0; 8 | } 9 | 10 | // CHECK: WARNING: ThreadSanitizer: unlock of an unlocked mutex (or by a wrong thread) 11 | // CHECK: #0 AnnotateRWLockReleased 12 | // CHECK: #1 main 13 | // CHECK: Location is stack of main thread. 14 | // CHECK: Mutex {{.*}} created at: 15 | // CHECK: #0 AnnotateRWLockReleased 16 | // CHECK: #1 main 17 | // CHECK: SUMMARY: ThreadSanitizer: unlock of an unlocked mutex (or by a wrong thread) 18 | 19 | -------------------------------------------------------------------------------- /lib/builtins/arm/sync_fetch_and_and_4.S: -------------------------------------------------------------------------------- 1 | /*===-- sync_fetch_and_and_4.S - ------------------------------------------===// 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | *===----------------------------------------------------------------------===// 9 | * 10 | * This file implements the __sync_fetch_and_and_4 function for the ARM 11 | * architecture. 12 | * 13 | *===----------------------------------------------------------------------===*/ 14 | 15 | #include "sync-ops.h" 16 | 17 | #define and_4(rD, rN, rM) and rD, rN, rM 18 | 19 | SYNC_OP_4(and_4) 20 | -------------------------------------------------------------------------------- /lib/builtins/arm/sync_fetch_and_or_4.S: -------------------------------------------------------------------------------- 1 | /*===-- sync_fetch_and_or_4.S - -------------------------------------------===// 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | *===----------------------------------------------------------------------===// 9 | * 10 | * This file implements the __sync_fetch_and_or_4 function for the ARM 11 | * architecture. 12 | * 13 | *===----------------------------------------------------------------------===*/ 14 | 15 | #include "sync-ops.h" 16 | 17 | #define or_4(rD, rN, rM) orr rD, rN, rM 18 | 19 | SYNC_OP_4(or_4) 20 | 21 | -------------------------------------------------------------------------------- /lib/builtins/trunctfdf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/truncdfsf2.c - quad -> double conversion --------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #define QUAD_PRECISION 11 | #include "fp_lib.h" 12 | 13 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 14 | #define SRC_QUAD 15 | #define DST_DOUBLE 16 | #include "fp_trunc_impl.inc" 17 | 18 | COMPILER_RT_ABI double __trunctfdf2(long double a) { 19 | return __truncXfYf2__(a); 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/builtins/trunctfsf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/trunctfsf2.c - quad -> single conversion --------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #define QUAD_PRECISION 11 | #include "fp_lib.h" 12 | 13 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 14 | #define SRC_QUAD 15 | #define DST_SINGLE 16 | #include "fp_trunc_impl.inc" 17 | 18 | COMPILER_RT_ABI float __trunctfsf2(long double a) { 19 | return __truncXfYf2__(a); 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/msan/tests/msan_test_config.h: -------------------------------------------------------------------------------- 1 | //===-- msan_test_config.h ----------------------------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file is a part of MemorySanitizer. 11 | // 12 | // MemorySanitizer unit tests. 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef MSAN_TEST_CONFIG_H 16 | #define MSAN_TEST_CONFIG_H 17 | 18 | #include "gtest/gtest.h" 19 | 20 | #endif // MSAN_TEST_CONFIG_H 21 | -------------------------------------------------------------------------------- /test/BlocksRuntime/voidarg.c: -------------------------------------------------------------------------------- 1 | // 2 | // The LLVM Compiler Infrastructure 3 | // 4 | // This file is distributed under the University of Illinois Open Source 5 | // License. See LICENSE.TXT for details. 6 | 7 | /* 8 | * voidarg.c 9 | * testObjects 10 | * 11 | * Created by Blaine Garst on 2/17/09. 12 | * 13 | */ 14 | 15 | // PURPOSE should complain about missing 'void' but both GCC and clang are supporting K&R instead 16 | // CONFIG open error: 17 | 18 | #include 19 | 20 | int Global; 21 | 22 | void (^globalBlock)() = ^{ ++Global; }; // should be void (^gb)(void) = ... 23 | 24 | int main(int argc, char *argv[]) { 25 | printf("%s: success", argv[0]); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /test/asan/TestCases/strpbrk-1.c: -------------------------------------------------------------------------------- 1 | // Test string s1 overflow in strpbrk function 2 | // RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s 3 | 4 | // Test intercept_strpbrk asan option 5 | // RUN: %env_asan_opts=intercept_strpbrk=false %run %t 2>&1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main(int argc, char **argv) { 12 | char *r; 13 | char s2[] = "ab"; 14 | char s1[4] = "cab"; 15 | __asan_poison_memory_region ((char *)&s1[2], 2); 16 | r = strpbrk(s1, s2); 17 | // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable 18 | assert(r == s1 + 1); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/cfi/icall/external-call.c: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_cfi -o %t1 %s 2 | // RUN: %t1 c 1 2>&1 | FileCheck --check-prefix=CFI %s 3 | // RUN: %t1 s 2 2>&1 | FileCheck --check-prefix=CFI %s 4 | 5 | // This test uses jump tables containing PC-relative references to external 6 | // symbols, which the Mach-O object writer does not currently support. 7 | // XFAIL: darwin 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main(int argc, char **argv) { 14 | // CFI: 1 15 | fprintf(stderr, "1\n"); 16 | 17 | double (*fn)(double); 18 | if (argv[1][0] == 's') 19 | fn = sin; 20 | else 21 | fn = cos; 22 | 23 | fn(atof(argv[2])); 24 | 25 | // CFI: 2 26 | fprintf(stderr, "2\n"); 27 | } 28 | -------------------------------------------------------------------------------- /www/menu.html.incl: -------------------------------------------------------------------------------- 1 | 20 | -------------------------------------------------------------------------------- /lib/asan/tests/asan_exceptions_test.cc: -------------------------------------------------------------------------------- 1 | // See http://llvm.org/bugs/show_bug.cgi?id=11468 2 | #include 3 | #include 4 | 5 | class Action { 6 | public: 7 | Action() {} 8 | void PrintString(const std::string& msg) const { 9 | fprintf(stderr, "%s\n", msg.c_str()); 10 | } 11 | void Throw(const char& arg) const { 12 | PrintString("PrintString called!"); // this line is important 13 | throw arg; 14 | } 15 | }; 16 | 17 | int main() { 18 | const Action a; 19 | fprintf(stderr, "&a before = %p\n", &a); 20 | try { 21 | a.Throw('c'); 22 | } catch(const char&) { 23 | fprintf(stderr, "&a in catch = %p\n", &a); 24 | } 25 | fprintf(stderr, "&a final = %p\n", &a); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /lib/builtins/arm/sync_fetch_and_xor_4.S: -------------------------------------------------------------------------------- 1 | /*===-- sync_fetch_and_xor_4.S - ------------------------------------------===// 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | *===----------------------------------------------------------------------===// 9 | * 10 | * This file implements the __sync_fetch_and_xor_4 function for the ARM 11 | * architecture. 12 | * 13 | *===----------------------------------------------------------------------===*/ 14 | 15 | #include "sync-ops.h" 16 | 17 | #define xor_4(rD, rN, rM) eor rD, rN, rM 18 | 19 | SYNC_OP_4(xor_4) 20 | 21 | -------------------------------------------------------------------------------- /lib/builtins/fixtfdi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixtfdi.c - Implement __fixtfdi -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define QUAD_PRECISION 12 | #include "fp_lib.h" 13 | 14 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 15 | typedef di_int fixint_t; 16 | typedef du_int fixuint_t; 17 | #include "fp_fixint_impl.inc" 18 | 19 | COMPILER_RT_ABI di_int 20 | __fixtfdi(fp_t a) { 21 | return __fixint(a); 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/builtins/fixtfsi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixtfsi.c - Implement __fixtfsi -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define QUAD_PRECISION 12 | #include "fp_lib.h" 13 | 14 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 15 | typedef si_int fixint_t; 16 | typedef su_int fixuint_t; 17 | #include "fp_fixint_impl.inc" 18 | 19 | COMPILER_RT_ABI si_int 20 | __fixtfsi(fp_t a) { 21 | return __fixint(a); 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/builtins/fixtfti.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixtfti.c - Implement __fixtfti -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | */ 10 | 11 | #define QUAD_PRECISION 12 | #include "fp_lib.h" 13 | 14 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 15 | typedef ti_int fixint_t; 16 | typedef tu_int fixuint_t; 17 | #include "fp_fixint_impl.inc" 18 | 19 | COMPILER_RT_ABI ti_int 20 | __fixtfti(fp_t a) { 21 | return __fixint(a); 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /test/asan/TestCases/Windows/thread_suspended.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t 2 | // RUN: %run %t 3 | 4 | #include 5 | 6 | DWORD WINAPI thread_proc(void *) { 7 | volatile char stack_buffer[42]; 8 | for (int i = 0; i < sizeof(stack_buffer); ++i) 9 | stack_buffer[i] = 42; 10 | return 0x42; 11 | } 12 | 13 | int main() { 14 | DWORD exitcode; 15 | HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, CREATE_SUSPENDED, NULL); 16 | ResumeThread(thr); 17 | if (thr == 0) 18 | return 1; 19 | if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE)) 20 | return 2; 21 | 22 | GetExitCodeThread(thr, &exitcode); 23 | if (exitcode != 0x42) 24 | return 3; 25 | CloseHandle(thr); 26 | } 27 | 28 | --------------------------------------------------------------------------------