├── .arcconfig ├── .gitignore ├── BlocksRuntime ├── Block.h ├── Block_private.h ├── data.c ├── runtime.c └── tests │ ├── block-static.c │ ├── blockimport.c │ ├── byrefaccess.c │ ├── byrefcopy.c │ ├── byrefcopycopy.c │ ├── byrefcopyinner.c │ ├── byrefcopyint.c │ ├── byrefcopystack.c │ ├── byrefsanity.c │ ├── byrefstruct.c │ ├── c99.c │ ├── cast.c │ ├── constassign.c │ ├── copy-block-literal-rdar6439600.c │ ├── copyconstructor.C │ ├── copynull.c │ ├── dispatch_async.c │ ├── dispatch_call_Block_with_release.c │ ├── fail.c │ ├── flagsisa.c │ ├── globalexpression.c │ ├── goto.c │ ├── hasdescriptor.c │ ├── josh.C │ ├── k-and-r.c │ ├── large-struct.c │ ├── localisglobal.c │ ├── macro.c │ ├── makefile │ ├── modglobal.c │ ├── nestedimport.c │ ├── nullblockisa.c │ ├── objectRRGC.c │ ├── objectassign.c │ ├── orbars.c │ ├── rdar6396238.c │ ├── rdar6405500.c │ ├── rdar6414583.c │ ├── recursive-block.c │ ├── recursive-test.c │ ├── recursiveassign.c │ ├── reference.C │ ├── rettypepromotion.c │ ├── returnfunctionptr.c │ ├── shorthandexpression.c │ ├── sizeof.c │ ├── small-struct.c │ ├── structmember.c │ ├── testfilerunner.h │ ├── testfilerunner.m │ ├── varargs-bad-assign.c │ ├── varargs.c │ ├── variadic.c │ └── voidarg.c ├── CMakeLists.txt ├── CREDITS.TXT ├── LICENSE.TXT ├── Makefile ├── README.txt ├── SDKs ├── README.txt ├── darwin │ ├── README.txt │ └── usr │ │ └── include │ │ ├── errno.h │ │ ├── fcntl.h │ │ ├── inttypes.h │ │ ├── limits.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.h │ │ └── sys │ │ ├── errno.h │ │ ├── fcntl.h │ │ ├── mman.h │ │ ├── stat.h │ │ └── types.h └── linux │ ├── README.txt │ └── usr │ └── include │ ├── endian.h │ ├── fcntl.h │ ├── limits.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── sys │ ├── fcntl.h │ ├── mman.h │ ├── stat.h │ └── types.h │ └── unistd.h ├── cmake └── Modules │ ├── AddCompilerRT.cmake │ ├── CompilerRTCompile.cmake │ ├── CompilerRTLink.cmake │ ├── CompilerRTUtils.cmake │ └── SanitizerUtils.cmake ├── include ├── CMakeLists.txt └── sanitizer │ ├── asan_interface.h │ ├── common_interface_defs.h │ ├── dfsan_interface.h │ ├── linux_syscall_hooks.h │ ├── lsan_interface.h │ ├── msan_interface.h │ └── tsan_interface_atomic.h ├── lib ├── CMakeLists.txt ├── Makefile.mk ├── absvdi2.c ├── absvsi2.c ├── absvti2.c ├── adddf3.c ├── addsf3.c ├── addvdi3.c ├── addvsi3.c ├── addvti3.c ├── apple_versioning.c ├── arm │ ├── Makefile.mk │ ├── adddf3vfp.S │ ├── addsf3vfp.S │ ├── aeabi_dcmp.S │ ├── aeabi_fcmp.S │ ├── aeabi_idivmod.S │ ├── aeabi_ldivmod.S │ ├── aeabi_memcmp.S │ ├── aeabi_memcpy.S │ ├── aeabi_memmove.S │ ├── aeabi_memset.S │ ├── aeabi_uidivmod.S │ ├── aeabi_uldivmod.S │ ├── bswapdi2.S │ ├── bswapsi2.S │ ├── clzdi2.S │ ├── clzsi2.S │ ├── comparesf2.S │ ├── divdf3vfp.S │ ├── divmodsi4.S │ ├── divsf3vfp.S │ ├── divsi3.S │ ├── eqdf2vfp.S │ ├── eqsf2vfp.S │ ├── extendsfdf2vfp.S │ ├── fixdfsivfp.S │ ├── fixsfsivfp.S │ ├── fixunsdfsivfp.S │ ├── fixunssfsivfp.S │ ├── floatsidfvfp.S │ ├── floatsisfvfp.S │ ├── floatunssidfvfp.S │ ├── floatunssisfvfp.S │ ├── gedf2vfp.S │ ├── gesf2vfp.S │ ├── gtdf2vfp.S │ ├── gtsf2vfp.S │ ├── ledf2vfp.S │ ├── lesf2vfp.S │ ├── ltdf2vfp.S │ ├── ltsf2vfp.S │ ├── modsi3.S │ ├── muldf3vfp.S │ ├── mulsf3vfp.S │ ├── nedf2vfp.S │ ├── negdf2vfp.S │ ├── negsf2vfp.S │ ├── nesf2vfp.S │ ├── restore_vfp_d8_d15_regs.S │ ├── save_vfp_d8_d15_regs.S │ ├── softfloat-alias.list │ ├── subdf3vfp.S │ ├── subsf3vfp.S │ ├── switch16.S │ ├── switch32.S │ ├── switch8.S │ ├── switchu8.S │ ├── sync_synchronize.S │ ├── truncdfsf2vfp.S │ ├── udivmodsi4.S │ ├── udivsi3.S │ ├── umodsi3.S │ ├── unorddf2vfp.S │ └── unordsf2vfp.S ├── asan │ ├── CMakeLists.txt │ ├── Makefile.mk │ ├── README.txt │ ├── asan.syms.extra │ ├── asan_activation.cc │ ├── asan_activation.h │ ├── asan_allocator.h │ ├── asan_allocator2.cc │ ├── asan_blacklist.txt │ ├── asan_dll_thunk.cc │ ├── asan_fake_stack.cc │ ├── asan_fake_stack.h │ ├── asan_flags.h │ ├── asan_globals.cc │ ├── asan_interceptors.cc │ ├── asan_interceptors.h │ ├── asan_interface_internal.h │ ├── asan_internal.h │ ├── asan_linux.cc │ ├── asan_lock.h │ ├── asan_mac.cc │ ├── asan_mac.h │ ├── asan_malloc_linux.cc │ ├── asan_malloc_mac.cc │ ├── asan_malloc_win.cc │ ├── asan_mapping.h │ ├── asan_new_delete.cc │ ├── asan_poisoning.cc │ ├── asan_poisoning.h │ ├── asan_posix.cc │ ├── asan_preinit.cc │ ├── asan_report.cc │ ├── asan_report.h │ ├── asan_rtl.cc │ ├── asan_stack.cc │ ├── asan_stack.h │ ├── asan_stats.cc │ ├── asan_stats.h │ ├── asan_thread.cc │ ├── asan_thread.h │ ├── asan_win.cc │ ├── lit_tests │ │ ├── 32bitConfig │ │ │ └── lit.site.cfg.in │ │ ├── 64bitConfig │ │ │ └── lit.site.cfg.in │ │ ├── CMakeLists.txt │ │ ├── TestCases │ │ │ ├── Darwin │ │ │ │ ├── asan_gen_prefixes.cc │ │ │ │ ├── interface_symbols_darwin.c │ │ │ │ ├── lit.local.cfg │ │ │ │ ├── malloc_set_zone_name-mprotect.cc │ │ │ │ ├── malloc_zone-protected.cc │ │ │ │ ├── reexec-insert-libraries-env.cc │ │ │ │ └── unset-insert-libraries-on-exec.cc │ │ │ ├── Helpers │ │ │ │ ├── blacklist-extra.cc │ │ │ │ ├── echo-env.cc │ │ │ │ ├── init-order-atexit-extra.cc │ │ │ │ ├── init-order-pthread-create-extra.cc │ │ │ │ ├── initialization-blacklist-extra.cc │ │ │ │ ├── initialization-blacklist-extra2.cc │ │ │ │ ├── initialization-blacklist.txt │ │ │ │ ├── initialization-bug-extra.cc │ │ │ │ ├── initialization-bug-extra2.cc │ │ │ │ ├── initialization-constexpr-extra.cc │ │ │ │ ├── initialization-nobug-extra.cc │ │ │ │ └── lit.local.cfg │ │ │ ├── Linux │ │ │ │ ├── asan_prelink_test.cc │ │ │ │ ├── clone_test.cc │ │ │ │ ├── coverage.cc │ │ │ │ ├── function-sections-are-bad.cc │ │ │ │ ├── glob.cc │ │ │ │ ├── glob_test_root │ │ │ │ │ ├── aa │ │ │ │ │ ├── ab │ │ │ │ │ └── ba │ │ │ │ ├── globals-gc-sections.cc │ │ │ │ ├── heap-overflow-large.cc │ │ │ │ ├── heavy_uar_test.cc │ │ │ │ ├── initialization-bug-any-order.cc │ │ │ │ ├── interception_failure_test.cc │ │ │ │ ├── interception_malloc_test.cc │ │ │ │ ├── interception_readdir_r_test.cc │ │ │ │ ├── interception_test.cc │ │ │ │ ├── interface_symbols_linux.c │ │ │ │ ├── lit.local.cfg │ │ │ │ ├── malloc-in-qsort.cc │ │ │ │ ├── malloc_delete_mismatch.cc │ │ │ │ ├── overflow-in-qsort.cc │ │ │ │ ├── preinit_test.cc │ │ │ │ ├── ptrace.cc │ │ │ │ ├── rlimit_mmap_test.cc │ │ │ │ ├── shmctl.cc │ │ │ │ ├── stress_dtls.c │ │ │ │ ├── swapcontext_test.cc │ │ │ │ ├── syscalls.cc │ │ │ │ ├── tsd_dtor_leak.cc │ │ │ │ ├── uar_signals.cc │ │ │ │ └── unpoison_tls.cc │ │ │ ├── SharedLibs │ │ │ │ ├── darwin-dummy-shared-lib-so.cc │ │ │ │ ├── dlclose-test-so.cc │ │ │ │ ├── init-order-dlopen-so.cc │ │ │ │ ├── lit.local.cfg │ │ │ │ ├── shared-lib-test-so.cc │ │ │ │ └── start-deactivated-so.cc │ │ │ ├── allocator_returns_null.cc │ │ │ ├── allow_user_segv.cc │ │ │ ├── asan-symbolize-sanity-test.cc │ │ │ ├── assign_large_valloc_to_global.cc │ │ │ ├── atexit_stats.cc │ │ │ ├── blacklist.cc │ │ │ ├── contiguous_container.cc │ │ │ ├── contiguous_container_crash.cc │ │ │ ├── current_allocated_bytes.cc │ │ │ ├── deep_call_stack.cc │ │ │ ├── deep_stack_uaf.cc │ │ │ ├── deep_tail_call.cc │ │ │ ├── deep_thread_stack.cc │ │ │ ├── default_blacklist.cc │ │ │ ├── default_options.cc │ │ │ ├── dlclose-test.cc │ │ │ ├── double-free.cc │ │ │ ├── force_inline_opt0.cc │ │ │ ├── free_hook_realloc.cc │ │ │ ├── global-demangle.cc │ │ │ ├── global-overflow.cc │ │ │ ├── heap-overflow.cc │ │ │ ├── huge_negative_hea_oob.cc │ │ │ ├── init-order-atexit.cc │ │ │ ├── init-order-dlopen.cc │ │ │ ├── init-order-pthread-create.cc │ │ │ ├── initialization-blacklist.cc │ │ │ ├── initialization-bug.cc │ │ │ ├── initialization-constexpr.cc │ │ │ ├── initialization-nobug.cc │ │ │ ├── inline.cc │ │ │ ├── interface_test.cc │ │ │ ├── invalid-free.cc │ │ │ ├── ioctl.cc │ │ │ ├── large_allocator_unpoisons_on_free.cc │ │ │ ├── large_func_test.cc │ │ │ ├── log-path_test.cc │ │ │ ├── log_path_fork_test.cc.disabled │ │ │ ├── lsan_annotations.cc │ │ │ ├── malloc_context_size.cc │ │ │ ├── malloc_fill.cc │ │ │ ├── malloc_hook.cc │ │ │ ├── max_redzone.cc │ │ │ ├── memcmp_strict_test.cc │ │ │ ├── memcmp_test.cc │ │ │ ├── no_asan_gen_globals.c │ │ │ ├── null_deref.cc │ │ │ ├── on_error_callback.cc │ │ │ ├── partial_right.cc │ │ │ ├── poison_partial.cc │ │ │ ├── print-stack-trace.cc │ │ │ ├── print_summary.cc │ │ │ ├── printf-1.c │ │ │ ├── printf-2.c │ │ │ ├── printf-3.c │ │ │ ├── printf-4.c │ │ │ ├── printf-5.c │ │ │ ├── readv.cc │ │ │ ├── sanity_check_pure_c.c │ │ │ ├── shared-lib-test.cc │ │ │ ├── sleep_before_dying.c │ │ │ ├── stack-buffer-overflow-with-position.cc │ │ │ ├── stack-frame-demangle.cc │ │ │ ├── stack-oob-frames.cc │ │ │ ├── stack-overflow.cc │ │ │ ├── stack-use-after-return.cc │ │ │ ├── start-deactivated.cc │ │ │ ├── strdup_oob_test.cc │ │ │ ├── strerror_r_test.cc │ │ │ ├── strip_path_prefix.c │ │ │ ├── strncpy-overflow.cc │ │ │ ├── throw_call_test.cc │ │ │ ├── throw_catch.cc │ │ │ ├── throw_invoke_test.cc │ │ │ ├── time_interceptor.cc │ │ │ ├── uar_and_exceptions.cc │ │ │ ├── unaligned_loads_and_stores.cc │ │ │ ├── use-after-free-right.cc │ │ │ ├── use-after-free.cc │ │ │ ├── use-after-poison.cc │ │ │ ├── use-after-scope-dtor-order.cc │ │ │ ├── use-after-scope-inlined.cc │ │ │ ├── use-after-scope-nobug.cc │ │ │ ├── use-after-scope-temp.cc │ │ │ ├── use-after-scope.cc │ │ │ └── wait.cc │ │ ├── Unit │ │ │ └── lit.site.cfg.in │ │ └── lit.cfg │ ├── scripts │ │ ├── asan_device_setup.sh │ │ └── asan_symbolize.py │ └── tests │ │ ├── CMakeLists.txt │ │ ├── asan_benchmarks_test.cc │ │ ├── asan_exceptions_test.cc │ │ ├── asan_fake_stack_test.cc │ │ ├── asan_globals_test.cc │ │ ├── asan_interface_test.cc │ │ ├── asan_mac_test.cc │ │ ├── asan_mac_test.h │ │ ├── asan_mac_test_helpers.mm │ │ ├── asan_mem_test.cc │ │ ├── asan_noinst_test.cc │ │ ├── asan_oob_test.cc │ │ ├── asan_racy_double_free_test.cc │ │ ├── asan_str_test.cc │ │ ├── asan_test.cc │ │ ├── asan_test.ignore │ │ ├── asan_test_config.h │ │ ├── asan_test_main.cc │ │ └── asan_test_utils.h ├── ashldi3.c ├── ashlti3.c ├── ashrdi3.c ├── ashrti3.c ├── assembly.h ├── atomic.c ├── clear_cache.c ├── clzdi2.c ├── clzsi2.c ├── clzti2.c ├── cmpdi2.c ├── cmpti2.c ├── comparedf2.c ├── comparesf2.c ├── ctzdi2.c ├── ctzsi2.c ├── ctzti2.c ├── dfsan │ ├── CMakeLists.txt │ ├── Makefile.mk │ ├── dfsan.cc │ ├── dfsan.h │ ├── dfsan.syms.extra │ ├── dfsan_custom.cc │ ├── dfsan_interceptors.cc │ ├── done_abilist.txt │ ├── libc_ubuntu1204_abilist.txt │ ├── lit_tests │ │ ├── CMakeLists.txt │ │ ├── Inputs │ │ │ └── flags_abilist.txt │ │ ├── basic.c │ │ ├── custom.c │ │ ├── flags.c │ │ ├── fncall.c │ │ ├── lit.cfg │ │ ├── lit.site.cfg.in │ │ └── propagate.c │ └── scripts │ │ ├── build-libc-list.py │ │ └── check_custom_wrappers.sh ├── divdc3.c ├── divdf3.c ├── divdi3.c ├── divmoddi4.c ├── divmodsi4.c ├── divsc3.c ├── divsf3.c ├── divsi3.c ├── divti3.c ├── divxc3.c ├── enable_execute_stack.c ├── eprintf.c ├── extendsfdf2.c ├── ffsdi2.c ├── ffsti2.c ├── fixdfdi.c ├── fixdfsi.c ├── fixdfti.c ├── fixsfdi.c ├── fixsfsi.c ├── fixsfti.c ├── fixunsdfdi.c ├── fixunsdfsi.c ├── fixunsdfti.c ├── fixunssfdi.c ├── fixunssfsi.c ├── fixunssfti.c ├── fixunsxfdi.c ├── fixunsxfsi.c ├── fixunsxfti.c ├── fixxfdi.c ├── fixxfti.c ├── floatdidf.c ├── floatdisf.c ├── floatdixf.c ├── floatsidf.c ├── floatsisf.c ├── floattidf.c ├── floattisf.c ├── floattixf.c ├── floatundidf.c ├── floatundisf.c ├── floatundixf.c ├── floatunsidf.c ├── floatunsisf.c ├── floatuntidf.c ├── floatuntisf.c ├── floatuntixf.c ├── fp_lib.h ├── gcc_personality_v0.c ├── i386 │ ├── Makefile.mk │ ├── ashldi3.S │ ├── ashrdi3.S │ ├── divdi3.S │ ├── floatdidf.S │ ├── floatdisf.S │ ├── floatdixf.S │ ├── floatundidf.S │ ├── floatundisf.S │ ├── floatundixf.S │ ├── lshrdi3.S │ ├── moddi3.S │ ├── muldi3.S │ ├── udivdi3.S │ └── umoddi3.S ├── int_endianness.h ├── int_lib.h ├── int_math.h ├── int_types.h ├── int_util.c ├── int_util.h ├── interception │ ├── CMakeLists.txt │ ├── Makefile.mk │ ├── interception.h │ ├── interception_linux.cc │ ├── interception_linux.h │ ├── interception_mac.cc │ ├── interception_mac.h │ ├── interception_type_test.cc │ ├── interception_win.cc │ └── interception_win.h ├── lit.common.cfg ├── lit.common.configured.in ├── lit.common.unit.cfg ├── lit.common.unit.configured.in ├── lsan │ ├── CMakeLists.txt │ ├── Makefile.mk │ ├── lit_tests │ │ ├── AsanConfig │ │ │ ├── lit.cfg │ │ │ └── lit.site.cfg.in │ │ ├── CMakeLists.txt │ │ ├── LsanConfig │ │ │ ├── lit.cfg │ │ │ └── lit.site.cfg.in │ │ ├── TestCases │ │ │ ├── SharedLibs │ │ │ │ ├── huge_tls_lib_so.cc │ │ │ │ └── lit.local.cfg │ │ │ ├── cleanup_in_tsd_destructor.cc │ │ │ ├── disabler.cc │ │ │ ├── disabler_in_tsd_destructor.cc │ │ │ ├── do_leak_check_override.cc │ │ │ ├── fork.cc │ │ │ ├── fork_threaded.cc │ │ │ ├── high_allocator_contention.cc │ │ │ ├── ignore_object.cc │ │ │ ├── ignore_object_errors.cc │ │ │ ├── large_allocation_leak.cc │ │ │ ├── leak_check_at_exit.cc │ │ │ ├── link_turned_off.cc │ │ │ ├── new_array_with_dtor_0.cc │ │ │ ├── pointer_to_self.cc │ │ │ ├── print_suppressions.cc │ │ │ ├── register_root_region.cc │ │ │ ├── sanity_check_pure_c.c │ │ │ ├── stale_stack_leak.cc │ │ │ ├── suppressions_default.cc │ │ │ ├── suppressions_file.cc │ │ │ ├── swapcontext.cc │ │ │ ├── use_after_return.cc │ │ │ ├── use_globals_initialized.cc │ │ │ ├── use_globals_uninitialized.cc │ │ │ ├── use_poisoned_asan.cc │ │ │ ├── use_registers.cc │ │ │ ├── use_stacks.cc │ │ │ ├── use_stacks_threaded.cc │ │ │ ├── use_tls_dynamic.cc │ │ │ ├── use_tls_pthread_specific_dynamic.cc │ │ │ ├── use_tls_pthread_specific_static.cc │ │ │ ├── use_tls_static.cc │ │ │ └── use_unaligned.cc │ │ ├── Unit │ │ │ └── lit.site.cfg.in │ │ └── lit.common.cfg │ ├── lsan.cc │ ├── lsan.h │ ├── lsan_allocator.cc │ ├── lsan_allocator.h │ ├── lsan_common.cc │ ├── lsan_common.h │ ├── lsan_common_linux.cc │ ├── lsan_interceptors.cc │ ├── lsan_preinit.cc │ ├── lsan_thread.cc │ ├── lsan_thread.h │ └── tests │ │ ├── CMakeLists.txt │ │ ├── lsan_dummy_unittest.cc │ │ └── lsan_testlib.cc ├── lshrdi3.c ├── lshrti3.c ├── moddi3.c ├── modsi3.c ├── modti3.c ├── msan │ ├── CMakeLists.txt │ ├── Makefile.mk │ ├── lit_tests │ │ ├── CMakeLists.txt │ │ ├── Linux │ │ │ ├── glob.cc │ │ │ ├── glob_altdirfunc.cc │ │ │ ├── glob_nomatch.cc │ │ │ ├── glob_test_root │ │ │ │ ├── aa │ │ │ │ ├── ab │ │ │ │ └── ba │ │ │ ├── lit.local.cfg │ │ │ ├── syscalls.cc │ │ │ ├── tcgetattr.cc │ │ │ ├── xattr.cc │ │ │ └── xattr_test_root │ │ │ │ └── a │ │ ├── SharedLibs │ │ │ ├── dso-origin-so.cc │ │ │ ├── dso-origin.h │ │ │ └── lit.local.cfg │ │ ├── Unit │ │ │ └── lit.site.cfg.in │ │ ├── allocator_returns_null.cc │ │ ├── backtrace.cc │ │ ├── c-strdup.c │ │ ├── cxa_atexit.cc │ │ ├── default_blacklist.cc │ │ ├── dlerror.cc │ │ ├── dso-origin.cc │ │ ├── dtls_test.c │ │ ├── errno.cc │ │ ├── getaddrinfo-positive.cc │ │ ├── getaddrinfo.cc │ │ ├── getline.cc │ │ ├── getline_test_data │ │ ├── heap-origin.cc │ │ ├── iconv.cc │ │ ├── initgroups.cc │ │ ├── inline.cc │ │ ├── insertvalue_origin.cc │ │ ├── ioctl.cc │ │ ├── ioctl_custom.cc │ │ ├── keep-going-dso.cc │ │ ├── keep-going.cc │ │ ├── lit.cfg │ │ ├── lit.site.cfg.in │ │ ├── malloc_hook.cc │ │ ├── mmap_below_shadow.cc │ │ ├── no_sanitize_memory.cc │ │ ├── no_sanitize_memory_prop.cc │ │ ├── poison_in_free.cc │ │ ├── pthread_getattr_np_deadlock.cc │ │ ├── ptrace.cc │ │ ├── readdir64.cc │ │ ├── scandir.cc │ │ ├── scandir_null.cc │ │ ├── scandir_test_root │ │ │ ├── aaa │ │ │ ├── aab │ │ │ └── bbb │ │ ├── select.cc │ │ ├── select_origin.cc │ │ ├── setlocale.cc │ │ ├── signal_stress_test.cc │ │ ├── sigwait.cc │ │ ├── sigwaitinfo.cc │ │ ├── stack-origin.cc │ │ ├── strerror_r-non-gnu.c │ │ ├── strlen_of_shadow.cc │ │ ├── sync_lock_set_and_test.cc │ │ ├── textdomain.cc │ │ ├── times.cc │ │ ├── tls_reuse.cc │ │ ├── tzset.cc │ │ ├── unaligned_read_origin.cc │ │ ├── use-after-free.cc │ │ ├── vector_cvt.cc │ │ ├── vector_select.cc │ │ ├── wrap_indirect_calls.cc │ │ ├── wrap_indirect_calls │ │ │ ├── caller.cc │ │ │ ├── lit.local.cfg │ │ │ ├── one.cc │ │ │ ├── two.cc │ │ │ └── wrapper.cc │ │ ├── wrap_indirect_calls2.cc │ │ └── wrap_indirect_calls_in_rtl.cc │ ├── msan.cc │ ├── msan.h │ ├── msan.syms.extra │ ├── msan_allocator.cc │ ├── msan_blacklist.txt │ ├── msan_flags.h │ ├── msan_interceptors.cc │ ├── msan_interface_internal.h │ ├── msan_linux.cc │ ├── msan_new_delete.cc │ ├── msan_report.cc │ └── tests │ │ ├── CMakeLists.txt │ │ ├── msan_loadable.cc │ │ ├── msan_test.cc │ │ ├── msan_test_config.h │ │ ├── msan_test_main.cc │ │ ├── msandr_test_so.cc │ │ └── msandr_test_so.h ├── msandr │ ├── CMakeLists.txt │ ├── README.txt │ └── msandr.cc ├── muldc3.c ├── muldf3.c ├── muldi3.c ├── mulodi4.c ├── mulosi4.c ├── muloti4.c ├── mulsc3.c ├── mulsf3.c ├── multi3.c ├── mulvdi3.c ├── mulvsi3.c ├── mulvti3.c ├── mulxc3.c ├── negdf2.c ├── negdi2.c ├── negsf2.c ├── negti2.c ├── negvdi2.c ├── negvsi2.c ├── negvti2.c ├── paritydi2.c ├── paritysi2.c ├── parityti2.c ├── popcountdi2.c ├── popcountsi2.c ├── popcountti2.c ├── powidf2.c ├── powisf2.c ├── powitf2.c ├── powixf2.c ├── ppc │ ├── DD.h │ ├── Makefile.mk │ ├── divtc3.c │ ├── fixtfdi.c │ ├── fixunstfdi.c │ ├── floatditf.c │ ├── floatunditf.c │ ├── gcc_qadd.c │ ├── gcc_qdiv.c │ ├── gcc_qmul.c │ ├── gcc_qsub.c │ ├── multc3.c │ ├── restFP.S │ └── saveFP.S ├── profile │ ├── CMakeLists.txt │ ├── GCDAProfiling.c │ ├── Makefile.mk │ └── PGOProfiling.c ├── sanitizer_common │ ├── CMakeLists.txt │ ├── Makefile.mk │ ├── sanitizer_allocator.cc │ ├── sanitizer_allocator.h │ ├── sanitizer_allocator_internal.h │ ├── sanitizer_asm.h │ ├── sanitizer_atomic.h │ ├── sanitizer_atomic_clang.h │ ├── sanitizer_atomic_clang_other.h │ ├── sanitizer_atomic_clang_x86.h │ ├── sanitizer_atomic_msvc.h │ ├── sanitizer_common.cc │ ├── sanitizer_common.h │ ├── sanitizer_common_interceptors.inc │ ├── sanitizer_common_interceptors_format.inc │ ├── sanitizer_common_interceptors_ioctl.inc │ ├── sanitizer_common_libcdep.cc │ ├── sanitizer_common_syscalls.inc │ ├── sanitizer_coverage.cc │ ├── sanitizer_flags.cc │ ├── sanitizer_flags.h │ ├── sanitizer_interception.h │ ├── sanitizer_internal_defs.h │ ├── sanitizer_lfstack.h │ ├── sanitizer_libc.cc │ ├── sanitizer_libc.h │ ├── sanitizer_libignore.cc │ ├── sanitizer_libignore.h │ ├── sanitizer_linux.cc │ ├── sanitizer_linux.h │ ├── sanitizer_linux_libcdep.cc │ ├── sanitizer_list.h │ ├── sanitizer_mac.cc │ ├── sanitizer_mac.h │ ├── sanitizer_mutex.h │ ├── sanitizer_placement_new.h │ ├── sanitizer_platform.h │ ├── sanitizer_platform_interceptors.h │ ├── sanitizer_platform_limits_linux.cc │ ├── sanitizer_platform_limits_posix.cc │ ├── sanitizer_platform_limits_posix.h │ ├── sanitizer_posix.cc │ ├── sanitizer_posix_libcdep.cc │ ├── sanitizer_printf.cc │ ├── sanitizer_procmaps.h │ ├── sanitizer_procmaps_linux.cc │ ├── sanitizer_procmaps_mac.cc │ ├── sanitizer_quarantine.h │ ├── sanitizer_report_decorator.h │ ├── sanitizer_stackdepot.cc │ ├── sanitizer_stackdepot.h │ ├── sanitizer_stacktrace.cc │ ├── sanitizer_stacktrace.h │ ├── sanitizer_stacktrace_libcdep.cc │ ├── sanitizer_stoptheworld.h │ ├── sanitizer_stoptheworld_linux_libcdep.cc │ ├── sanitizer_suppressions.cc │ ├── sanitizer_suppressions.h │ ├── sanitizer_symbolizer.cc │ ├── sanitizer_symbolizer.h │ ├── sanitizer_symbolizer_libbacktrace.cc │ ├── sanitizer_symbolizer_libbacktrace.h │ ├── sanitizer_symbolizer_libcdep.cc │ ├── sanitizer_symbolizer_posix_libcdep.cc │ ├── sanitizer_symbolizer_win.cc │ ├── sanitizer_syscall_generic.inc │ ├── sanitizer_syscall_linux_x86_64.inc │ ├── sanitizer_thread_registry.cc │ ├── sanitizer_thread_registry.h │ ├── sanitizer_tls_get_addr.cc │ ├── sanitizer_tls_get_addr.h │ ├── sanitizer_win.cc │ ├── scripts │ │ ├── check_lint.sh │ │ ├── cpplint.py │ │ ├── gen_dynamic_list.py │ │ └── sancov.py │ └── tests │ │ ├── CMakeLists.txt │ │ ├── lit.site.cfg.in │ │ ├── sanitizer_allocator_test.cc │ │ ├── sanitizer_allocator_testlib.cc │ │ ├── sanitizer_atomic_test.cc │ │ ├── sanitizer_common_test.cc │ │ ├── sanitizer_flags_test.cc │ │ ├── sanitizer_format_interceptor_test.cc │ │ ├── sanitizer_ioctl_test.cc │ │ ├── sanitizer_libc_test.cc │ │ ├── sanitizer_linux_test.cc │ │ ├── sanitizer_list_test.cc │ │ ├── sanitizer_mutex_test.cc │ │ ├── sanitizer_nolibc_test.cc │ │ ├── sanitizer_nolibc_test_main.cc │ │ ├── sanitizer_posix_test.cc │ │ ├── sanitizer_printf_test.cc │ │ ├── sanitizer_procmaps_test.cc │ │ ├── sanitizer_stackdepot_test.cc │ │ ├── sanitizer_stacktrace_test.cc │ │ ├── sanitizer_stoptheworld_test.cc │ │ ├── sanitizer_stoptheworld_testlib.cc │ │ ├── sanitizer_suppressions_test.cc │ │ ├── sanitizer_test_main.cc │ │ ├── sanitizer_test_utils.h │ │ ├── sanitizer_thread_registry_test.cc │ │ └── standalone_malloc_test.cc ├── subdf3.c ├── subsf3.c ├── subvdi3.c ├── subvsi3.c ├── subvti3.c ├── trampoline_setup.c ├── truncdfsf2.c ├── tsan │ ├── CMakeLists.txt │ ├── Makefile.mk │ ├── Makefile.old │ ├── analyze_libtsan.sh │ ├── benchmarks │ │ ├── mini_bench_local.cc │ │ ├── mini_bench_shared.cc │ │ ├── start_many_threads.cc │ │ └── vts_many_threads_bench.cc │ ├── check_analyze.sh │ ├── check_cmake.sh │ ├── check_memcpy.sh │ ├── go │ │ ├── buildgo.sh │ │ ├── test.c │ │ └── tsan_go.cc │ ├── lit_tests │ │ ├── CMakeLists.txt │ │ ├── Helpers │ │ │ ├── blacklist.txt │ │ │ └── lit.local.cfg │ │ ├── SharedLibs │ │ │ ├── lit.local.cfg │ │ │ └── load_shared_lib-so.cc │ │ ├── Unit │ │ │ ├── lit.cfg │ │ │ └── lit.site.cfg.in │ │ ├── aligned_vs_unaligned_race.cc │ │ ├── allocator_returns_null.cc │ │ ├── atomic_free.cc │ │ ├── atomic_free2.cc │ │ ├── atomic_norace.cc │ │ ├── atomic_race.cc │ │ ├── atomic_stack.cc │ │ ├── benign_race.cc │ │ ├── blacklist.cc │ │ ├── cond.c │ │ ├── cond_race.cc │ │ ├── cond_version.c │ │ ├── deep_stack1.cc │ │ ├── default_options.cc │ │ ├── fd_close_norace.cc │ │ ├── fd_close_norace2.cc │ │ ├── fd_dup_norace.cc │ │ ├── fd_location.cc │ │ ├── fd_pipe_norace.cc │ │ ├── fd_pipe_race.cc │ │ ├── fd_socket_connect_norace.cc │ │ ├── fd_socket_norace.cc │ │ ├── fd_socketpair_norace.cc │ │ ├── fd_stdout_race.cc │ │ ├── fork_deadlock.cc │ │ ├── fork_multithreaded.cc │ │ ├── fork_multithreaded3.cc │ │ ├── free_race.c │ │ ├── free_race.c.supp │ │ ├── free_race2.c │ │ ├── global_race.cc │ │ ├── halt_on_error.cc │ │ ├── heap_race.cc │ │ ├── ignore_free.cc │ │ ├── ignore_lib0.cc │ │ ├── ignore_lib0.cc.supp │ │ ├── ignore_lib1.cc │ │ ├── ignore_lib1.cc.supp │ │ ├── ignore_lib2.cc │ │ ├── ignore_lib2.cc.supp │ │ ├── ignore_lib3.cc │ │ ├── ignore_lib3.cc.supp │ │ ├── ignore_lib_lib.h │ │ ├── ignore_malloc.cc │ │ ├── ignore_race.cc │ │ ├── ignore_sync.cc │ │ ├── inlined_memcpy_race.cc │ │ ├── interface_atomic_test.c │ │ ├── java.h │ │ ├── java_alloc.cc │ │ ├── java_lock.cc │ │ ├── java_lock_move.cc │ │ ├── java_lock_rec.cc │ │ ├── java_lock_rec_race.cc │ │ ├── java_race.cc │ │ ├── java_race_move.cc │ │ ├── java_rwlock.cc │ │ ├── lit.cfg │ │ ├── lit.site.cfg.in │ │ ├── load_shared_lib.cc │ │ ├── longjmp.cc │ │ ├── longjmp2.cc │ │ ├── longjmp3.cc │ │ ├── longjmp4.cc │ │ ├── malloc_hook.cc │ │ ├── malloc_overflow.cc │ │ ├── malloc_stack.cc │ │ ├── memcpy_race.cc │ │ ├── mop_with_offset.cc │ │ ├── mop_with_offset2.cc │ │ ├── mutex_destroy_locked.cc │ │ ├── mutex_robust.cc │ │ ├── mutex_robust2.cc │ │ ├── mutexset1.cc │ │ ├── mutexset2.cc │ │ ├── mutexset3.cc │ │ ├── mutexset4.cc │ │ ├── mutexset5.cc │ │ ├── mutexset6.cc │ │ ├── mutexset7.cc │ │ ├── mutexset8.cc │ │ ├── oob_race.cc │ │ ├── printf-1.c │ │ ├── race_on_barrier.c │ │ ├── race_on_barrier2.c │ │ ├── race_on_heap.cc │ │ ├── race_on_mutex.c │ │ ├── race_on_mutex2.c │ │ ├── race_on_read.cc │ │ ├── race_on_speculative_load.cc │ │ ├── race_on_write.cc │ │ ├── race_with_finished_thread.cc │ │ ├── signal_errno.cc │ │ ├── signal_malloc.cc │ │ ├── sigsuspend.cc │ │ ├── simple_race.c │ │ ├── simple_race.cc │ │ ├── simple_stack.c │ │ ├── simple_stack2.cc │ │ ├── sleep_sync.cc │ │ ├── sleep_sync2.cc │ │ ├── stack_race.cc │ │ ├── stack_race2.cc │ │ ├── static_init1.cc │ │ ├── static_init2.cc │ │ ├── static_init3.cc │ │ ├── static_init4.cc │ │ ├── static_init5.cc │ │ ├── static_init6.cc │ │ ├── suppress_same_address.cc │ │ ├── suppress_same_stacks.cc │ │ ├── suppressions_global.cc │ │ ├── suppressions_global.cc.supp │ │ ├── suppressions_race.cc │ │ ├── suppressions_race.cc.supp │ │ ├── suppressions_race2.cc │ │ ├── suppressions_race2.cc.supp │ │ ├── test_output.sh │ │ ├── thread_end_with_ignore.cc │ │ ├── thread_end_with_ignore2.cc │ │ ├── thread_end_with_ignore3.cc │ │ ├── thread_leak.c │ │ ├── thread_leak2.c │ │ ├── thread_leak3.c │ │ ├── thread_leak4.c │ │ ├── thread_leak5.c │ │ ├── thread_name.cc │ │ ├── thread_name2.cc │ │ ├── tiny_race.c │ │ ├── tls_race.cc │ │ ├── tls_race2.cc │ │ ├── tsan-vs-gvn.cc │ │ ├── unaligned_norace.cc │ │ ├── unaligned_race.cc │ │ ├── user_fopen.cc │ │ ├── user_malloc.cc │ │ ├── virtual_inheritance_compile_bug.cc │ │ ├── vptr_benign_race.cc │ │ ├── vptr_harmful_race.cc │ │ ├── vptr_harmful_race2.cc │ │ └── write_in_reader_lock.cc │ ├── rtl │ │ ├── Makefile.mk │ │ ├── Makefile.old │ │ ├── tsan.syms.extra │ │ ├── tsan_clock.cc │ │ ├── tsan_clock.h │ │ ├── tsan_defs.h │ │ ├── tsan_fd.cc │ │ ├── tsan_fd.h │ │ ├── tsan_flags.cc │ │ ├── tsan_flags.h │ │ ├── tsan_ignoreset.cc │ │ ├── tsan_ignoreset.h │ │ ├── tsan_interceptors.cc │ │ ├── tsan_interface.cc │ │ ├── tsan_interface.h │ │ ├── tsan_interface_ann.cc │ │ ├── tsan_interface_ann.h │ │ ├── tsan_interface_atomic.cc │ │ ├── tsan_interface_inl.h │ │ ├── tsan_interface_java.cc │ │ ├── tsan_interface_java.h │ │ ├── tsan_md5.cc │ │ ├── tsan_mman.cc │ │ ├── tsan_mman.h │ │ ├── tsan_mutex.cc │ │ ├── tsan_mutex.h │ │ ├── tsan_mutexset.cc │ │ ├── tsan_mutexset.h │ │ ├── tsan_platform.h │ │ ├── tsan_platform_linux.cc │ │ ├── tsan_platform_mac.cc │ │ ├── tsan_platform_windows.cc │ │ ├── tsan_report.cc │ │ ├── tsan_report.h │ │ ├── tsan_rtl.cc │ │ ├── tsan_rtl.h │ │ ├── tsan_rtl_amd64.S │ │ ├── tsan_rtl_mutex.cc │ │ ├── tsan_rtl_report.cc │ │ ├── tsan_rtl_thread.cc │ │ ├── tsan_stat.cc │ │ ├── tsan_stat.h │ │ ├── tsan_suppressions.cc │ │ ├── tsan_suppressions.h │ │ ├── tsan_symbolize.cc │ │ ├── tsan_symbolize.h │ │ ├── tsan_symbolize_addr2line_linux.cc │ │ ├── tsan_sync.cc │ │ ├── tsan_sync.h │ │ ├── tsan_trace.h │ │ ├── tsan_update_shadow_word_inl.h │ │ └── tsan_vector.h │ └── tests │ │ ├── CMakeLists.txt │ │ ├── rtl │ │ ├── CMakeLists.txt │ │ ├── tsan_bench.cc │ │ ├── tsan_mop.cc │ │ ├── tsan_mutex.cc │ │ ├── tsan_posix.cc │ │ ├── tsan_string.cc │ │ ├── tsan_test.cc │ │ ├── tsan_test_util.h │ │ ├── tsan_test_util_linux.cc │ │ └── tsan_thread.cc │ │ └── unit │ │ ├── CMakeLists.txt │ │ ├── tsan_clock_test.cc │ │ ├── tsan_flags_test.cc │ │ ├── tsan_mman_test.cc │ │ ├── tsan_mutex_test.cc │ │ ├── tsan_mutexset_test.cc │ │ ├── tsan_shadow_test.cc │ │ ├── tsan_stack_test.cc │ │ ├── tsan_sync_test.cc │ │ ├── tsan_unit_test_main.cc │ │ └── tsan_vector_test.cc ├── ubsan │ ├── CMakeLists.txt │ ├── Makefile.mk │ ├── lit_tests │ │ ├── AsanConfig │ │ │ ├── lit.cfg │ │ │ └── lit.site.cfg.in │ │ ├── CMakeLists.txt │ │ ├── TestCases │ │ │ ├── Float │ │ │ │ └── cast-overflow.cpp │ │ │ ├── Integer │ │ │ │ ├── add-overflow.cpp │ │ │ │ ├── div-overflow.cpp │ │ │ │ ├── div-zero.cpp │ │ │ │ ├── incdec-overflow.cpp │ │ │ │ ├── mul-overflow.cpp │ │ │ │ ├── negate-overflow.cpp │ │ │ │ ├── no-recover.cpp │ │ │ │ ├── shift.cpp │ │ │ │ ├── sub-overflow.cpp │ │ │ │ ├── uadd-overflow.cpp │ │ │ │ ├── uincdec-overflow.cpp │ │ │ │ ├── umul-overflow.cpp │ │ │ │ └── usub-overflow.cpp │ │ │ ├── Misc │ │ │ │ ├── bool.cpp │ │ │ │ ├── bounds.cpp │ │ │ │ ├── deduplication.cpp │ │ │ │ ├── enum.cpp │ │ │ │ ├── missing_return.cpp │ │ │ │ ├── unreachable.cpp │ │ │ │ └── vla.c │ │ │ └── TypeCheck │ │ │ │ ├── Function │ │ │ │ ├── function.cpp │ │ │ │ └── lit.local.cfg │ │ │ │ ├── misaligned.cpp │ │ │ │ ├── null.cpp │ │ │ │ └── vptr.cpp │ │ ├── UbsanConfig │ │ │ ├── lit.cfg │ │ │ └── lit.site.cfg.in │ │ └── lit.common.cfg │ ├── ubsan.syms.extra │ ├── ubsan_diag.cc │ ├── ubsan_diag.h │ ├── ubsan_handlers.cc │ ├── ubsan_handlers.h │ ├── ubsan_handlers_cxx.cc │ ├── ubsan_handlers_cxx.h │ ├── ubsan_type_hash.cc │ ├── ubsan_type_hash.h │ ├── ubsan_value.cc │ └── ubsan_value.h ├── ucmpdi2.c ├── ucmpti2.c ├── udivdi3.c ├── udivmoddi4.c ├── udivmodsi4.c ├── udivmodti4.c ├── udivsi3.c ├── udivti3.c ├── umoddi3.c ├── umodsi3.c ├── umodti3.c └── x86_64 │ ├── Makefile.mk │ ├── floatdidf.c │ ├── floatdisf.c │ ├── floatdixf.c │ ├── floatundidf.S │ ├── floatundisf.S │ └── floatundixf.S ├── make ├── AppleBI.mk ├── config.mk ├── filter-inputs ├── lib_info.mk ├── lib_platforms.mk ├── lib_util.mk ├── options.mk ├── platform │ ├── clang_darwin.mk │ ├── clang_darwin_test_input.c │ ├── clang_linux.mk │ ├── clang_linux_test_input.c │ ├── clang_macho_embedded.mk │ ├── clang_macho_embedded_test_input.c │ ├── darwin_bni.mk │ ├── darwin_fat.mk │ └── multi_arch.mk ├── subdir.mk ├── test │ └── test-util.mk └── util.mk ├── test ├── Unit │ ├── absvdi2_test.c │ ├── absvsi2_test.c │ ├── absvti2_test.c │ ├── adddf3vfp_test.c │ ├── addsf3vfp_test.c │ ├── addvdi3_test.c │ ├── addvsi3_test.c │ ├── addvti3_test.c │ ├── ashldi3_test.c │ ├── ashlti3_test.c │ ├── ashrdi3_test.c │ ├── ashrti3_test.c │ ├── bswapdi2_test.c │ ├── bswapsi2_test.c │ ├── clear_cache_test.c │ ├── clzdi2_test.c │ ├── clzsi2_test.c │ ├── clzti2_test.c │ ├── cmpdi2_test.c │ ├── cmpti2_test.c │ ├── comparedf2_test.c │ ├── comparesf2_test.c │ ├── ctzdi2_test.c │ ├── ctzsi2_test.c │ ├── ctzti2_test.c │ ├── divdc3_test.c │ ├── divdf3vfp_test.c │ ├── divdi3_test.c │ ├── divmodsi4_test.c │ ├── divsc3_test.c │ ├── divsf3vfp_test.c │ ├── divsi3_test.c │ ├── divtc3_test.c │ ├── divti3_test.c │ ├── divxc3_test.c │ ├── enable_execute_stack_test.c │ ├── endianness.h │ ├── eqdf2vfp_test.c │ ├── eqsf2vfp_test.c │ ├── extebdsfdf2vfp_test.c │ ├── ffsdi2_test.c │ ├── ffsti2_test.c │ ├── fixdfdi_test.c │ ├── fixdfsivfp_test.c │ ├── fixdfti_test.c │ ├── fixsfdi_test.c │ ├── fixsfsivfp_test.c │ ├── fixsfti_test.c │ ├── fixunsdfdi_test.c │ ├── fixunsdfsi_test.c │ ├── fixunsdfsivfp_test.c │ ├── fixunsdfti_test.c │ ├── fixunssfdi_test.c │ ├── fixunssfsi_test.c │ ├── fixunssfsivfp_test.c │ ├── fixunssfti_test.c │ ├── fixunstfdi_test.c │ ├── fixunsxfdi_test.c │ ├── fixunsxfsi_test.c │ ├── fixunsxfti_test.c │ ├── fixxfdi_test.c │ ├── fixxfti_test.c │ ├── floatdidf_test.c │ ├── floatdisf_test.c │ ├── floatdixf_test.c │ ├── floatsidfvfp_test.c │ ├── floatsisfvfp_test.c │ ├── floattidf_test.c │ ├── floattisf_test.c │ ├── floattixf_test.c │ ├── floatundidf_test.c │ ├── floatundisf_test.c │ ├── floatundixf_test.c │ ├── floatunssidfvfp_test.c │ ├── floatunssisfvfp_test.c │ ├── floatuntidf_test.c │ ├── floatuntisf_test.c │ ├── floatuntixf_test.c │ ├── gcc_personality_test.c │ ├── gcc_personality_test_helper.cxx │ ├── gedf2vfp_test.c │ ├── gesf2vfp_test.c │ ├── gtdf2vfp_test.c │ ├── gtsf2vfp_test.c │ ├── ledf2vfp_test.c │ ├── lesf2vfp_test.c │ ├── lshrdi3_test.c │ ├── lshrti3_test.c │ ├── ltdf2vfp_test.c │ ├── ltsf2vfp_test.c │ ├── moddi3_test.c │ ├── modsi3_test.c │ ├── modti3_test.c │ ├── muldc3_test.c │ ├── muldf3vfp_test.c │ ├── muldi3_test.c │ ├── mulodi4_test.c │ ├── mulosi4_test.c │ ├── muloti4_test.c │ ├── mulsc3_test.c │ ├── mulsf3vfp_test.c │ ├── multc3_test.c │ ├── multi3_test.c │ ├── mulvdi3_test.c │ ├── mulvsi3_test.c │ ├── mulvti3_test.c │ ├── mulxc3_test.c │ ├── nedf2vfp_test.c │ ├── negdf2vfp_test.c │ ├── negdi2_test.c │ ├── negsf2vfp_test.c │ ├── negti2_test.c │ ├── negvdi2_test.c │ ├── negvsi2_test.c │ ├── negvti2_test.c │ ├── nesf2vfp_test.c │ ├── paritydi2_test.c │ ├── paritysi2_test.c │ ├── parityti2_test.c │ ├── popcountdi2_test.c │ ├── popcountsi2_test.c │ ├── popcountti2_test.c │ ├── powidf2_test.c │ ├── powisf2_test.c │ ├── powitf2_test.c │ ├── powixf2_test.c │ ├── ppc │ │ ├── DD.h │ │ ├── fixtfdi_test.c │ │ ├── floatditf_test.c │ │ ├── floatditf_test.h │ │ ├── floatunditf_test.c │ │ ├── floatunditf_test.h │ │ ├── qadd_test.c │ │ ├── qdiv_test.c │ │ ├── qmul_test.c │ │ ├── qsub_test.c │ │ └── test │ ├── subdf3vfp_test.c │ ├── subsf3vfp_test.c │ ├── subvdi3_test.c │ ├── subvsi3_test.c │ ├── subvti3_test.c │ ├── test │ ├── trampoline_setup_test.c │ ├── truncdfsf2vfp_test.c │ ├── ucmpdi2_test.c │ ├── ucmpti2_test.c │ ├── udivdi3_test.c │ ├── udivmoddi4_test.c │ ├── udivmodsi4_test.c │ ├── udivmodti4_test.c │ ├── udivsi3_test.c │ ├── udivti3_test.c │ ├── umoddi3_test.c │ ├── umodsi3_test.c │ ├── umodti3_test.c │ ├── unorddf2vfp_test.c │ └── unordsf2vfp_test.c └── timing │ ├── ashldi3.c │ ├── ashrdi3.c │ ├── divdi3.c │ ├── floatdidf.c │ ├── floatdisf.c │ ├── floatdixf.c │ ├── floatundidf.c │ ├── floatundisf.c │ ├── floatundixf.c │ ├── lshrdi3.c │ ├── moddi3.c │ ├── modsi3.c │ ├── muldi3.c │ ├── negdi2.c │ ├── time │ ├── timing.h │ ├── udivdi3.c │ └── umoddi3.c └── www ├── content.css ├── index.html ├── menu.css └── menu.html.incl /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "project_id" : "compiler-rt", 3 | "conduit_uri" : "http://llvm-reviews.chandlerc.com/" 4 | } 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | darwin_fat 3 | clang_darwin 4 | multi_arch 5 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/byrefaccess.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 | // byrefaccess.m 9 | // test that byref access to locals is accurate 10 | // testObjects 11 | // 12 | // Created by Blaine Garst on 5/13/08. 13 | // 14 | // CONFIG 15 | 16 | #include 17 | 18 | 19 | void callVoidVoid(void (^closure)(void)) { 20 | closure(); 21 | } 22 | 23 | int main(int argc, char *argv[]) { 24 | __block int i = 10; 25 | 26 | callVoidVoid(^{ ++i; }); 27 | 28 | if (i != 11) { 29 | printf("*** %s didn't update i\n", argv[0]); 30 | return 1; 31 | } 32 | printf("%s: success\n", argv[0]); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/constassign.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 | // constassign.c 9 | // bocktest 10 | // 11 | // Created by Blaine Garst on 3/21/08. 12 | // 13 | // shouldn't be able to assign to a const pointer 14 | // CONFIG error: assignment of read-only 15 | 16 | #import 17 | 18 | void foo(void) { printf("I'm in foo\n"); } 19 | void bar(void) { printf("I'm in bar\n"); } 20 | 21 | int main(int argc, char *argv[]) { 22 | void (*const fptr)(void) = foo; 23 | void (^const blockA)(void) = ^ { printf("hello\n"); }; 24 | blockA = ^ { printf("world\n"); } ; 25 | fptr = bar; 26 | printf("%s: success\n", argv[0]); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/copy-block-literal-rdar6439600.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://6439600 8 | 9 | #import 10 | #import 11 | 12 | #define NUMBER_OF_BLOCKS 100 13 | int main (int argc, const char * argv[]) { 14 | int (^x[NUMBER_OF_BLOCKS])(); 15 | int i; 16 | 17 | for(i=0; i 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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/goto.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 | * goto.c 9 | * testObjects 10 | * 11 | * Created by Blaine Garst on 10/17/08. 12 | * 13 | */ 14 | 15 | // CONFIG rdar://6289031 16 | 17 | #include 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | __block int val = 0; 22 | 23 | ^{ val = 1; }(); 24 | 25 | if (val == 0) { 26 | goto out_bad; // error: local byref variable val is in the scope of this goto 27 | } 28 | 29 | printf("%s: Success!\n", argv[0]); 30 | return 0; 31 | out_bad: 32 | printf("%s: val not updated!\n", argv[0]); 33 | return 1; 34 | } 35 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/josh.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 C++ GC RR open rdar://6347910 8 | 9 | 10 | 11 | struct MyStruct { 12 | int something; 13 | }; 14 | 15 | struct TestObject { 16 | 17 | void test(void){ 18 | { 19 | MyStruct first; // works 20 | } 21 | void (^b)(void) = ^{ 22 | MyStruct inner; // fails to compile! 23 | }; 24 | } 25 | }; 26 | 27 | 28 | 29 | int main(int argc, char *argv[]) { 30 | printf("%s: Success\n", argv[0]); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/rdar6396238.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 rdar://6396238 8 | 9 | #include 10 | #include 11 | 12 | static int count = 0; 13 | 14 | void (^mkblock(void))(void) 15 | { 16 | count++; 17 | return ^{ 18 | count++; 19 | }; 20 | } 21 | 22 | int main (int argc, const char * argv[]) { 23 | mkblock()(); 24 | if (count != 2) { 25 | printf("%s: failure, 2 != %d\n", argv[0], count); 26 | exit(1); 27 | } else { 28 | printf("%s: success\n", argv[0]); 29 | exit(0); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/rdar6414583.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 rdar://6414583 8 | 9 | // a smaller case of byrefcopyint 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | int main(int argc, char *argv[]) { 16 | __block int c = 1; 17 | 18 | //printf("&c = %p - c = %i\n", &c, c); 19 | 20 | int i; 21 | for(i =0; i < 2; i++) { 22 | dispatch_block_t block = Block_copy(^{ c = i; }); 23 | 24 | block(); 25 | // printf("%i: &c = %p - c = %i\n", i, &c, c); 26 | 27 | Block_release(block); 28 | } 29 | printf("%s: success\n", argv[0]); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /BlocksRuntime/tests/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 | -------------------------------------------------------------------------------- /SDKs/README.txt: -------------------------------------------------------------------------------- 1 | It is often convenient to be able to build compiler-rt libraries for a certain 2 | platform without having a full SDK or development environment installed. 3 | 4 | This makes it easy for users to build a compiler which can target a number of 5 | different platforms, without having to actively maintain full development 6 | environments for those platforms. 7 | 8 | Since compiler-rt's libraries typically have minimal interaction with the 9 | system, we achieve this by stubbing out the SDKs of certain platforms. 10 | -------------------------------------------------------------------------------- /SDKs/darwin/README.txt: -------------------------------------------------------------------------------- 1 | The Darwin platforms are all similar enough we roll them into one SDK, and use 2 | preprocessor tricks to get the right definitions for the few things which 3 | diverge between OS X and iOS. 4 | -------------------------------------------------------------------------------- /SDKs/darwin/usr/include/errno.h: -------------------------------------------------------------------------------- 1 | /* ===-- errno.h - stub SDK header for compiler-rt --------------------------=== 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 is a stub SDK header file. This file is not part of the interface of 11 | * this library nor an official version of the appropriate SDK header. It is 12 | * intended only to stub the features of this header required by compiler-rt. 13 | * 14 | * ===-----------------------------------------------------------------------=== 15 | */ 16 | 17 | #include 18 | -------------------------------------------------------------------------------- /SDKs/darwin/usr/include/fcntl.h: -------------------------------------------------------------------------------- 1 | /* ===-- fcntl.h - stub SDK header for compiler-rt --------------------------=== 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 is a stub SDK header file. This file is not part of the interface of 11 | * this library nor an official version of the appropriate SDK header. It is 12 | * intended only to stub the features of this header required by compiler-rt. 13 | * 14 | * ===-----------------------------------------------------------------------=== 15 | */ 16 | 17 | #include 18 | -------------------------------------------------------------------------------- /SDKs/darwin/usr/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* ===-- types.h - stub SDK header for compiler-rt --------------------------=== 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 is a stub SDK header file. This file is not part of the interface of 11 | * this library nor an official version of the appropriate SDK header. It is 12 | * intended only to stub the features of this header required by compiler-rt. 13 | * 14 | * ===-----------------------------------------------------------------------=== 15 | */ 16 | 17 | #ifndef __SYS_TYPES_H__ 18 | #define __SYS_TYPES_H__ 19 | 20 | #endif /* __SYS_TYPES_H__ */ 21 | -------------------------------------------------------------------------------- /SDKs/linux/README.txt: -------------------------------------------------------------------------------- 1 | This is a stub SDK for Linux. Currently, this has only been tested on i386 and 2 | x86_64 using the Clang compiler. 3 | -------------------------------------------------------------------------------- /SDKs/linux/usr/include/fcntl.h: -------------------------------------------------------------------------------- 1 | /* ===-- fcntl.h - stub SDK header for compiler-rt --------------------------=== 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 is a stub SDK header file. This file is not part of the interface of 11 | * this library nor an official version of the appropriate SDK header. It is 12 | * intended only to stub the features of this header required by compiler-rt. 13 | * 14 | * ===-----------------------------------------------------------------------=== 15 | */ 16 | 17 | #include 18 | -------------------------------------------------------------------------------- /SDKs/linux/usr/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* ===-- stat.h - stub SDK header for compiler-rt ---------------------------=== 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 is a stub SDK header file. This file is not part of the interface of 11 | * this library nor an official version of the appropriate SDK header. It is 12 | * intended only to stub the features of this header required by compiler-rt. 13 | * 14 | * ===-----------------------------------------------------------------------=== 15 | */ 16 | 17 | #ifndef __SYS_TYPES_H__ 18 | #define __SYS_TYPES_H__ 19 | 20 | #endif /* __SYS_TYPES_H__ */ 21 | -------------------------------------------------------------------------------- /cmake/Modules/CompilerRTCompile.cmake: -------------------------------------------------------------------------------- 1 | include(LLVMParseArguments) 2 | 3 | # Compile a source into an object file with just-built Clang using 4 | # a provided compile flags and dependenices. 5 | # clang_compile( 6 | # CFLAGS 7 | # DEPS ) 8 | macro(clang_compile object_file source) 9 | parse_arguments(SOURCE "CFLAGS;DEPS" "" ${ARGN}) 10 | get_filename_component(source_rpath ${source} REALPATH) 11 | add_custom_command( 12 | OUTPUT ${object_file} 13 | COMMAND clang ${SOURCE_CFLAGS} -c -o "${object_file}" ${source_rpath} 14 | MAIN_DEPENDENCY ${source} 15 | DEPENDS clang ${SOURCE_DEPS}) 16 | endmacro() 17 | -------------------------------------------------------------------------------- /cmake/Modules/CompilerRTLink.cmake: -------------------------------------------------------------------------------- 1 | include(LLVMParseArguments) 2 | 3 | # Link a shared library with just-built Clang. 4 | # clang_link_shared( 5 | # OBJECTS 6 | # LINKFLAGS 7 | # DEPS ) 8 | macro(clang_link_shared so_file) 9 | parse_arguments(SOURCE "OBJECTS;LINKFLAGS;DEPS" "" ${ARGN}) 10 | add_custom_command( 11 | OUTPUT ${so_file} 12 | COMMAND clang -o "${so_file}" -shared ${SOURCE_LINKFLAGS} ${SOURCE_OBJECTS} 13 | DEPENDS clang ${SOURCE_DEPS}) 14 | endmacro() 15 | -------------------------------------------------------------------------------- /lib/arm/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/arm/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 := builtins 11 | SubDirs := 12 | OnlyArchs := armv5 armv6 armv7 armv7k armv7m armv7em armv7s 13 | 14 | AsmSources := $(foreach file,$(wildcard $(Dir)/*.S),$(notdir $(file))) 15 | Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file))) 16 | ObjNames := $(Sources:%.c=%.o) $(AsmSources:%.S=%.o) 17 | Implementation := Optimized 18 | 19 | # FIXME: use automatic dependencies? 20 | Dependencies := $(wildcard lib/*.h $(Dir)/*.h) 21 | -------------------------------------------------------------------------------- /lib/arm/aeabi_memcmp.S: -------------------------------------------------------------------------------- 1 | //===-- aeabi_memcmp.S - EABI memcmp implementation -----------------------===// 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 "../assembly.h" 11 | 12 | // void __aeabi_memcmp(void *dest, void *src, size_t n) { memcmp(dest, src, n); } 13 | 14 | .align 2 15 | DEFINE_COMPILERRT_FUNCTION(__aeabi_memcmp) 16 | b memcmp 17 | END_COMPILERRT_FUNCTION(__aeabi_memcmp) 18 | 19 | DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcmp4, __aeabi_memcmp) 20 | DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcmp8, __aeabi_memcmp) 21 | -------------------------------------------------------------------------------- /lib/arm/aeabi_memcpy.S: -------------------------------------------------------------------------------- 1 | //===-- aeabi_memcpy.S - EABI memcpy implementation -----------------------===// 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 "../assembly.h" 11 | 12 | // void __aeabi_memcpy(void *dest, void *src, size_t n) { memcpy(dest, src, n); } 13 | 14 | .align 2 15 | DEFINE_COMPILERRT_FUNCTION(__aeabi_memcpy) 16 | b memcpy 17 | END_COMPILERRT_FUNCTION(__aeabi_memcpy) 18 | 19 | DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcpy4, __aeabi_memcpy) 20 | DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memcpy8, __aeabi_memcpy) 21 | -------------------------------------------------------------------------------- /lib/arm/aeabi_memmove.S: -------------------------------------------------------------------------------- 1 | //===-- aeabi_memmove.S - EABI memmove implementation --------------------===// 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 "../assembly.h" 11 | 12 | // void __aeabi_memmove(void *dest, void *src, size_t n) { memmove(dest, src, n); } 13 | 14 | .align 2 15 | DEFINE_COMPILERRT_FUNCTION(__aeabi_memmove) 16 | b memmove 17 | END_COMPILERRT_FUNCTION(__aeabi_memmove) 18 | 19 | DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memmove4, __aeabi_memmove) 20 | DEFINE_AEABI_FUNCTION_ALIAS(__aeabi_memmove8, __aeabi_memmove) 21 | -------------------------------------------------------------------------------- /lib/arm/negsf2vfp.S: -------------------------------------------------------------------------------- 1 | //===-- negsf2vfp.S - Implement negsf2vfp ---------------------------------===// 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 "../assembly.h" 11 | 12 | // 13 | // extern float __negsf2vfp(float a); 14 | // 15 | // Returns the negation of a single precision floating point numbers using the 16 | // Darwin calling convention where single arguments are passsed like 32-bit ints 17 | // 18 | .syntax unified 19 | .align 2 20 | DEFINE_COMPILERRT_FUNCTION(__negsf2vfp) 21 | eor r0, r0, #-2147483648 // flip sign bit on float in r0 22 | bx lr 23 | END_COMPILERRT_FUNCTION(__negsf2vfp) 24 | -------------------------------------------------------------------------------- /lib/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 | -------------------------------------------------------------------------------- /lib/asan/asan.syms.extra: -------------------------------------------------------------------------------- 1 | __asan_* 2 | __lsan_* 3 | __ubsan_* 4 | -------------------------------------------------------------------------------- /lib/asan/asan_activation.h: -------------------------------------------------------------------------------- 1 | //===-- asan_activation.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 AddressSanitizer, an address sanity checker. 11 | // 12 | // ASan activation/deactivation logic. 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef ASAN_ACTIVATION_H 16 | #define ASAN_ACTIVATION_H 17 | 18 | namespace __asan { 19 | void AsanStartDeactivated(); 20 | void AsanActivate(); 21 | } // namespace __asan 22 | 23 | #endif // ASAN_ACTIVATION_H 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/asan/asan_lock.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/asan/asan_lock.h -------------------------------------------------------------------------------- /lib/asan/lit_tests/32bitConfig/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@/lib/lit.common.configured") 6 | 7 | # Tool-specific config options. 8 | config.asan_source_dir = "@ASAN_SOURCE_DIR@" 9 | config.bits = "32" 10 | 11 | # Load tool-specific config that would do the real work. 12 | lit_config.load_config(config, "@ASAN_SOURCE_DIR@/lit_tests/lit.cfg") 13 | 14 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/64bitConfig/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@/lib/lit.common.configured") 6 | 7 | # Tool-specific config options. 8 | config.asan_source_dir = "@ASAN_SOURCE_DIR@" 9 | config.bits = "64" 10 | 11 | # Load tool-specific config that would do the real work. 12 | lit_config.load_config(config, "@ASAN_SOURCE_DIR@/lit_tests/lit.cfg") 13 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Helpers/init-order-pthread-create-extra.cc: -------------------------------------------------------------------------------- 1 | void *bar(void *input); 2 | void *glob2 = bar((void*)0x2345); 3 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Helpers/initialization-blacklist-extra2.cc: -------------------------------------------------------------------------------- 1 | int zero_init(); 2 | int badSrcGlobal = zero_init(); 3 | int readBadSrcGlobal() { return badSrcGlobal; } 4 | 5 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Helpers/initialization-blacklist.txt: -------------------------------------------------------------------------------- 1 | global:*badGlobal*=init 2 | type:*badNamespace::BadClass*=init 3 | src:*initialization-blacklist-extra2.cc=init 4 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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/asan/lit_tests/TestCases/Helpers/initialization-constexpr-extra.cc: -------------------------------------------------------------------------------- 1 | // Constexpr: 2 | int getCoolestInteger(); 3 | static int coolest_integer = getCoolestInteger(); 4 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Linux/glob_test_root/aa: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/asan/lit_tests/TestCases/Linux/glob_test_root/aa -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Linux/glob_test_root/ab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/asan/lit_tests/TestCases/Linux/glob_test_root/ab -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Linux/glob_test_root/ba: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/asan/lit_tests/TestCases/Linux/glob_test_root/ba -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Linux/interception_failure_test.cc: -------------------------------------------------------------------------------- 1 | // If user provides his own libc functions, ASan doesn't 2 | // intercept these functions. 3 | 4 | // RUN: %clangxx_asan -O0 %s -o %t && %t 2>&1 | FileCheck %s 5 | // RUN: %clangxx_asan -O1 %s -o %t && %t 2>&1 | FileCheck %s 6 | // RUN: %clangxx_asan -O2 %s -o %t && %t 2>&1 | FileCheck %s 7 | // RUN: %clangxx_asan -O3 %s -o %t && %t 2>&1 | FileCheck %s 8 | #include 9 | #include 10 | 11 | extern "C" long strtol(const char *nptr, char **endptr, int base) { 12 | fprintf(stderr, "my_strtol_interceptor\n"); 13 | return 0; 14 | } 15 | 16 | int main() { 17 | char *x = (char*)malloc(10 * sizeof(char)); 18 | free(x); 19 | return (int)strtol(x, 0, 10); 20 | // CHECK: my_strtol_interceptor 21 | // CHECK-NOT: heap-use-after-free 22 | } 23 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Linux/rlimit_mmap_test.cc: -------------------------------------------------------------------------------- 1 | // Check that we properly report mmap failure. 2 | // RUN: %clangxx_asan %s -o %t && not %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Linux/shmctl.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O1 %s -o %t && %t 2>&1 2 | // Regression test for 3 | // https://code.google.com/p/address-sanitizer/issues/detail?id=250 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | int id = shmget(IPC_PRIVATE, 4096, 0644 | IPC_CREAT); 11 | assert(id > -1); 12 | struct shmid_ds ds; 13 | int res = shmctl(id, IPC_STAT, &ds); 14 | assert(res > -1); 15 | printf("shm_segsz: %zd\n", ds.shm_segsz); 16 | assert(ds.shm_segsz == 4096); 17 | assert(-1 != shmctl(id, IPC_RMID, 0)); 18 | 19 | struct shm_info shmInfo; 20 | res = shmctl(0, SHM_INFO, (struct shmid_ds *)&shmInfo); 21 | assert(res > -1); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/Linux/syscalls.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O3 %s -o %t && not %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | /* Test the presence of __sanitizer_syscall_ in the tool runtime, and general 13 | sanity of their behaviour. */ 14 | 15 | int main(int argc, char *argv[]) { 16 | char buf[1000]; 17 | __sanitizer_syscall_pre_recvmsg(0, buf - 1, 0); 18 | // CHECK: AddressSanitizer: stack-buffer-{{.*}}erflow 19 | // CHECK: READ of size {{.*}} at {{.*}} thread T0 20 | // CHECK: #0 {{.*}} in __sanitizer_syscall{{.*}}recvmsg 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/SharedLibs/darwin-dummy-shared-lib-so.cc: -------------------------------------------------------------------------------- 1 | //===----------- darwin-dummy-shared-lib-so.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 | //===----------------------------------------------------------------------===// 13 | void foo() {} 14 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/SharedLibs/init-order-dlopen-so.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" void inc_global(); 5 | 6 | int slow_init() { 7 | sleep(1); 8 | inc_global(); 9 | return 42; 10 | } 11 | 12 | int slowly_init_glob = slow_init(); 13 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/SharedLibs/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # Sources in this directory are compiled as shared libraries and used by 2 | # tests in parent directory. 3 | 4 | config.suffixes = [] 5 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/SharedLibs/shared-lib-test-so.cc: -------------------------------------------------------------------------------- 1 | //===----------- shared-lib-test-so.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 | //===----------------------------------------------------------------------===// 13 | #include 14 | 15 | int pad[10]; 16 | int GLOB[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 17 | 18 | extern "C" 19 | void inc(int index) { 20 | GLOB[index]++; 21 | } 22 | 23 | extern "C" 24 | void inc2(int *a, int index) { 25 | a[index]++; 26 | } 27 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/SharedLibs/start-deactivated-so.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" void do_another_bad_thing() { 5 | char *volatile p = (char *)malloc(100); 6 | printf("%hhx\n", p[105]); 7 | } 8 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/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 && %t 3 | #include 4 | #ifndef __APPLE__ 5 | #include 6 | #endif // __APPLE__ 7 | int *p = (int*)valloc(1 << 20); 8 | int main() { } 9 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/atexit_stats.cc: -------------------------------------------------------------------------------- 1 | // Make sure we report atexit stats. 2 | // RUN: %clangxx_asan -O3 %s -o %t 3 | // RUN: ASAN_OPTIONS=atexit=1:print_stats=1 %t 2>&1 | FileCheck %s 4 | #include 5 | #if !defined(__APPLE__) 6 | #include 7 | #endif 8 | int *p1 = (int*)malloc(900); 9 | int *p2 = (int*)malloc(90000); 10 | int *p3 = (int*)malloc(9000000); 11 | int main() { } 12 | 13 | // CHECK: AddressSanitizer exit stats: 14 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/deep_call_stack.cc: -------------------------------------------------------------------------------- 1 | // Check that UAR mode can handle very deep recusrion. 2 | // export ASAN_OPTIONS=detect_stack_use_after_return=1 3 | // RUN: %clangxx_asan -O2 %s -o %t && \ 4 | // RUN: %t 2>&1 | FileCheck %s 5 | // Also check that use_sigaltstack+verbosity doesn't crash. 6 | // RUN: ASAN_OPTIONS=verbosity=1:use_sigaltstack=1 %t | FileCheck %s 7 | #include 8 | 9 | __attribute__((noinline)) 10 | void RecursiveFunc(int depth, int *ptr) { 11 | if ((depth % 1000) == 0) 12 | printf("[%05d] ptr: %p\n", depth, ptr); 13 | if (depth == 0) 14 | return; 15 | int local; 16 | RecursiveFunc(depth - 1, &local); 17 | } 18 | 19 | int main(int argc, char **argv) { 20 | RecursiveFunc(40000, 0); 21 | return 0; 22 | } 23 | // CHECK: [40000] ptr: 24 | // CHECK: [20000] ptr: 25 | // CHECK: [00000] ptr 26 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/deep_stack_uaf.cc: -------------------------------------------------------------------------------- 1 | // Check that we can store lots of stack frames if asked to. 2 | 3 | // RUN: %clangxx_asan -O0 %s -o %t 2>&1 4 | // RUN: ASAN_OPTIONS=malloc_context_size=120:redzone=512 not %t 2>&1 | FileCheck %s 5 | #include 6 | #include 7 | 8 | template 9 | struct DeepFree { 10 | static void free(char *x) { 11 | DeepFree::free(x); 12 | } 13 | }; 14 | 15 | template<> 16 | struct DeepFree<0> { 17 | static void free(char *x) { 18 | ::free(x); 19 | } 20 | }; 21 | 22 | int main() { 23 | char *x = (char*)malloc(10); 24 | // deep_free(x); 25 | DeepFree<200>::free(x); 26 | return x[5]; 27 | // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} 28 | // CHECK: DeepFree<36> 29 | // CHECK: DeepFree<98> 30 | // CHECK: DeepFree<115> 31 | } 32 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/default_blacklist.cc: -------------------------------------------------------------------------------- 1 | // Test that ASan uses the default blacklist from resource directory. 2 | // RUN: %clangxx_asan -### %s 2>&1 | FileCheck %s 3 | // CHECK: fsanitize-blacklist={{.*}}asan_blacklist.txt 4 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/default_options.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O2 %s -o %t 2 | // RUN: %t 2>&1 | FileCheck %s 3 | 4 | const char *kAsanDefaultOptions="verbosity=1 foo=bar"; 5 | 6 | extern "C" 7 | __attribute__((no_sanitize_address)) 8 | const char *__asan_default_options() { 9 | // CHECK: Using the defaults from __asan_default_options: {{.*}} foo=bar 10 | return kAsanDefaultOptions; 11 | } 12 | 13 | int main() { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 && %t 4 | // RUN: %clangxx_asan -O0 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/free_hook_realloc.cc: -------------------------------------------------------------------------------- 1 | // Check that free hook doesn't conflict with Realloc. 2 | // RUN: %clangxx_asan -O2 %s -o %t 3 | // RUN: %t 2>&1 | FileCheck %s 4 | #include 5 | #include 6 | 7 | static void *glob_ptr; 8 | 9 | extern "C" { 10 | void __asan_free_hook(void *ptr) { 11 | if (ptr == glob_ptr) { 12 | *(int*)ptr = 0; 13 | write(1, "FreeHook\n", sizeof("FreeHook\n")); 14 | } 15 | } 16 | } 17 | 18 | int main() { 19 | int *x = (int*)malloc(100); 20 | x[0] = 42; 21 | glob_ptr = x; 22 | int *y = (int*)realloc(x, 200); 23 | // Verify that free hook was called and didn't spoil the memory. 24 | if (y[0] != 42) { 25 | _exit(1); 26 | } 27 | write(1, "Passed\n", sizeof("Passed\n")); 28 | free(y); 29 | // CHECK: FreeHook 30 | // CHECK: Passed 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/global-demangle.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/huge_negative_hea_oob.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan %s -o %t && not %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O %s -o %t && not %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/init-order-atexit.cc: -------------------------------------------------------------------------------- 1 | // Test for the following situation: 2 | // (1) global A is constructed. 3 | // (2) exit() is called during construction of global B. 4 | // (3) destructor of A reads uninitialized global C from another module. 5 | // We do *not* want to report init-order bug in this case. 6 | 7 | // RUN: %clangxx_asan -O0 %s %p/Helpers/init-order-atexit-extra.cc -o %t 8 | // RUN: ASAN_OPTIONS=strict_init_order=true not %t 2>&1 | FileCheck %s 9 | 10 | #include 11 | #include 12 | 13 | void AccessC(); 14 | 15 | class A { 16 | public: 17 | A() { } 18 | ~A() { AccessC(); printf("PASSED\n"); } 19 | // CHECK-NOT: AddressSanitizer 20 | // CHECK: PASSED 21 | }; 22 | 23 | A a; 24 | 25 | class B { 26 | public: 27 | B() { exit(1); } 28 | ~B() { } 29 | }; 30 | 31 | B b; 32 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/init-order-pthread-create.cc: -------------------------------------------------------------------------------- 1 | // Check that init-order checking is properly disabled if pthread_create is 2 | // called. 3 | 4 | // RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -o %t 5 | // RUN: ASAN_OPTIONS=strict_init_order=true %t 6 | 7 | #include 8 | #include 9 | 10 | void *run(void *arg) { 11 | return arg; 12 | } 13 | 14 | void *foo(void *input) { 15 | pthread_t t; 16 | pthread_create(&t, 0, run, input); 17 | void *res; 18 | pthread_join(t, &res); 19 | return res; 20 | } 21 | 22 | void *bar(void *input) { 23 | return input; 24 | } 25 | 26 | void *glob = foo((void*)0x1234); 27 | extern void *glob2; 28 | 29 | int main() { 30 | printf("%p %p\n", glob, glob2); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/inline.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O3 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/interface_test.cc: -------------------------------------------------------------------------------- 1 | // Check that user may include ASan interface header. 2 | // RUN: %clang_asan %s -o %t && %t 3 | // RUN: %clang %s -o %t && %t 4 | #include 5 | 6 | int main() { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/ioctl.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -g %s -o %t && ASAN_OPTIONS=handle_ioctl=1 not %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O3 -g %s -o %t && ASAN_OPTIONS=handle_ioctl=1 not %t 2>&1 | FileCheck %s 3 | 4 | // RUN: %clangxx_asan -O0 -g %s -o %t && %t 5 | // RUN: %clangxx_asan -O3 -g %s -o %t && %t 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | int main(int argc, char **argv) { 14 | int fd = socket(AF_INET, SOCK_DGRAM, 0); 15 | 16 | int nonblock; 17 | int res = ioctl(fd, FIONBIO, &nonblock + 1); 18 | // CHECK: AddressSanitizer: stack-buffer-overflow 19 | // CHECK: READ of size 4 at 20 | // CHECK: {{#.* in main .*ioctl.cc:}}[[@LINE-3]] 21 | assert(res == 0); 22 | close(fd); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/large_allocator_unpoisons_on_free.cc: -------------------------------------------------------------------------------- 1 | // Test that LargeAllocator unpoisons memory before releasing it to the OS. 2 | // RUN: %clangxx_asan %s -o %t 3 | // The memory is released only when the deallocated chunk leaves the quarantine, 4 | // otherwise the mmap(p, ...) call overwrites the malloc header. 5 | // RUN: ASAN_OPTIONS=quarantine_size=1 %t 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main() { 13 | const int kPageSize = 4096; 14 | void *p = NULL; 15 | posix_memalign(&p, kPageSize, 1024 * 1024); 16 | free(p); 17 | 18 | char *q = (char *)mmap(p, kPageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, 0, 0); 19 | assert(q == p); 20 | 21 | memset(q, 42, kPageSize); 22 | 23 | munmap(q, kPageSize); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/log_path_fork_test.cc.disabled: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan %s -o %t 2 | // RUN: rm -f %t.log.* 3 | // Set verbosity to 1 so that the log files are opened prior to fork(). 4 | // RUN: ASAN_OPTIONS="log_path=%t.log verbosity=1" not %t 2> %t.out 5 | // RUN: for f in %t.log.* ; do FileCheck %s < $f; done 6 | // RUN: [ `ls %t.log.* | wc -l` == 2 ] 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int main(int argc, char **argv) { 13 | void *x = malloc(10); 14 | free(x); 15 | if (fork() == -1) return 1; 16 | // There are two processes at this point, thus there should be two distinct 17 | // error logs. 18 | free(x); 19 | return 0; 20 | } 21 | 22 | // CHECK: ERROR: AddressSanitizer 23 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/lsan_annotations.cc: -------------------------------------------------------------------------------- 1 | // Check that LSan annotations work fine. 2 | // RUN: %clangxx_asan -O0 %s -o %t && %t 3 | // RUN: %clangxx_asan -O3 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/memcmp_strict_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS=strict_memcmp=0 %t 2 | // RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS=strict_memcmp=1 not %t 2>&1 | FileCheck %s 3 | // Default to strict_memcmp=1. 4 | // RUN: %clangxx_asan -O0 %s -o %t && not %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/memcmp_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx_asan -O2 %s -o %t && not %t 2>&1 | FileCheck %s 4 | // RUN: %clangxx_asan -O3 %s -o %t && not %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/no_asan_gen_globals.c: -------------------------------------------------------------------------------- 1 | // Make sure __asan_gen_* strings do not end up in the symbol table. 2 | 3 | // RUN: %clang_asan %s -o %t.exe 4 | // RUN: nm %t.exe | FileCheck %s 5 | 6 | int x, y, z; 7 | int main() { return 0; } 8 | // CHECK-NOT: __asan_gen_ 9 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/on_error_callback.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O2 %s -o %t && not %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"); 9 | } 10 | 11 | int main() { 12 | char *x = (char*)malloc(10 * sizeof(char)); 13 | free(x); 14 | return x[5]; 15 | // CHECK: __asan_on_error called 16 | } 17 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/partial_right.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx_asan -O2 %s -o %t && not %t 2>&1 | FileCheck %s 4 | // RUN: %clangxx_asan -O3 %s -o %t && not %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/poison_partial.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t 2 | // RUN: not %t 2>&1 | FileCheck %s 3 | // RUN: not %t heap 2>&1 | FileCheck %s 4 | // RUN: ASAN_OPTIONS=poison_partial=0 %t 5 | // RUN: ASAN_OPTIONS=poison_partial=0 %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/print-stack-trace.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O3 %s -o %t && %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | void FooBarBaz() { 7 | __sanitizer_print_stack_trace(); 8 | } 9 | 10 | int main() { 11 | FooBarBaz(); 12 | return 0; 13 | } 14 | // CHECK: {{ #0 0x.* in __sanitizer_print_stack_trace}} 15 | // CHECK: {{ #1 0x.* in FooBarBaz\(\) .*print-stack-trace.cc:7}} 16 | // CHECK: {{ #2 0x.* in main .*print-stack-trace.cc:11}} 17 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/print_summary.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t 2 | // RUN: not %t 2>&1 | FileCheck %s --check-prefix=YES 3 | // RUN: ASAN_OPTIONS=print_summary=false not %t 2>&1 | FileCheck %s --check-prefix=NO 4 | 5 | int main() { 6 | char *x = new char[20]; 7 | delete[] x; 8 | return x[0]; 9 | // YES: ERROR: AddressSanitizer: heap-use-after-free 10 | // YES: SUMMARY: AddressSanitizer: heap-use-after-free 11 | // NO: ERROR: AddressSanitizer: heap-use-after-free 12 | // NO-NOT: SUMMARY: AddressSanitizer: heap-use-after-free 13 | } 14 | 15 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/printf-1.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS=check_printf=1 %t 2>&1 | FileCheck %s 3 | // RUN: ASAN_OPTIONS=check_printf=0 %t 2>&1 | FileCheck %s 4 | // 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 | // Check that printf works fine under Asan. 13 | printf("%c %d %.3f %s\n", c, x, f, s); 14 | // CHECK: 0 12 1.239 34 15 | // Check that snprintf works fine under Asan. 16 | char buf[4]; 17 | snprintf(buf, 1000, "qwe"); 18 | printf("%s\n", buf); 19 | // CHECK: qwe 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/printf-2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS=check_printf=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s 3 | // RUN: ASAN_OPTIONS=check_printf=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s 4 | // RUN: %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s 5 | 6 | #include 7 | #include 8 | #include 9 | int main() { 10 | volatile char c = '0'; 11 | volatile int x = 12; 12 | volatile float f = 1.239; 13 | volatile char s[] = "34"; 14 | char *p = strdup((const char *)s); 15 | free(p); 16 | printf("%c %d %.3f %s\n", c, x, f, p); 17 | return 0; 18 | // Check that %s is sanitized. 19 | // CHECK-ON: heap-use-after-free 20 | // CHECK-ON-NOT: 0 12 1.239 34 21 | // CHECK-OFF: 0 12 1.239 22 | } 23 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/printf-3.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS=check_printf=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s 3 | // RUN: ASAN_OPTIONS=check_printf=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s 4 | // RUN: %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %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 | volatile int n[1]; 13 | printf("%c %d %.3f %s%n\n", c, x, f, s, &n[1]); 14 | return 0; 15 | // Check that %n is sanitized. 16 | // CHECK-ON: stack-buffer-overflow 17 | // CHECK-ON-NOT: 0 12 1.239 34 18 | // CHECK-OFF: 0 12 1.239 34 19 | } 20 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/printf-4.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS=check_printf=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s 3 | // RUN: ASAN_OPTIONS=check_printf=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s 4 | // RUN: %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %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 | volatile char buf[2]; 13 | sprintf((char *)buf, "%c %d %.3f %s\n", c, x, f, s); 14 | puts((const char *)buf); 15 | return 0; 16 | // Check that size of output buffer is sanitized. 17 | // CHECK-ON: stack-buffer-overflow 18 | // CHECK-ON-NOT: 0 12 1.239 34 19 | // CHECK-OFF: 0 12 1.239 34 20 | } 21 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/printf-5.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS=check_printf=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s 3 | // RUN: ASAN_OPTIONS=check_printf=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s 4 | // RUN: %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s 5 | 6 | #include 7 | #include 8 | int main() { 9 | volatile char c = '0'; 10 | volatile int x = 12; 11 | volatile float f = 1.239; 12 | volatile char s[] = "34"; 13 | volatile char fmt[2]; 14 | memcpy((char *)fmt, "%c %d %f %s\n", sizeof(fmt)); 15 | printf(fmt, c, x, f, s); 16 | return 0; 17 | // Check that format string is sanitized. 18 | // CHECK-ON: stack-buffer-overflow 19 | // CHECK-ON-NOT: 0 12 1.239 34 20 | // CHECK-OFF: 0 21 | } 22 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/readv.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && %t 2 | // RUN: %clangxx_asan -O0 %s -DPOSITIVE -o %t && not %t 2>&1 | FileCheck %s 3 | 4 | // Test the readv() interceptor. 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int main() { 15 | char buf[2011]; 16 | struct iovec iov[2]; 17 | #ifdef POSITIVE 18 | char * volatile buf_ = buf; 19 | iov[0].iov_base = buf_ - 1; 20 | #else 21 | iov[0].iov_base = buf + 1; 22 | #endif 23 | iov[0].iov_len = 5; 24 | iov[1].iov_base = buf + 10; 25 | iov[1].iov_len = 2000; 26 | int fd = open("/etc/hosts", O_RDONLY); 27 | assert(fd > 0); 28 | readv(fd, iov, 2); 29 | // CHECK: WRITE of size 5 at 30 | close(fd); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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 %t 2>&1 | FileCheck %s 4 | 5 | // Sanity checking a test in pure C with -pie. 6 | // RUN: %clang_asan -O2 %s -pie -o %t 7 | // RUN: not %t 2>&1 | FileCheck %s 8 | 9 | #include 10 | int main() { 11 | char *x = (char*)malloc(10 * sizeof(char)); 12 | free(x); 13 | return x[5]; 14 | // CHECK: heap-use-after-free 15 | // CHECK: free 16 | // CHECK: main{{.*}}sanity_check_pure_c.c:[[@LINE-4]] 17 | // CHECK: malloc 18 | // CHECK: main{{.*}}sanity_check_pure_c.c:[[@LINE-7]] 19 | } 20 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/sleep_before_dying.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS="sleep_before_dying=1" not %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/stack-frame-demangle.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %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 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/stack-overflow.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx_asan -O2 %s -o %t && not %t 2>&1 | FileCheck %s 4 | // RUN: %clangxx_asan -O3 %s -o %t && not %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | int main(int argc, char **argv) { 8 | char x[10]; 9 | memset(x, 0, 10); 10 | int res = x[argc * 10]; // BOOOM 11 | // CHECK: {{READ of size 1 at 0x.* thread T0}} 12 | // CHECK: {{ #0 0x.* in main .*stack-overflow.cc:}}[[@LINE-2]] 13 | // CHECK: {{Address 0x.* is located in stack of thread T0 at offset}} 14 | // CHECK-NEXT: in{{.*}}main{{.*}}stack-overflow.cc 15 | return res; 16 | } 17 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/strdup_oob_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_asan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx_asan -O2 %s -o %t && not %t 2>&1 | FileCheck %s 4 | // RUN: %clangxx_asan -O3 %s -o %t && not %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | 8 | char kString[] = "foo"; 9 | 10 | int main(int argc, char **argv) { 11 | char *copy = strdup(kString); 12 | int x = copy[4 + argc]; // BOOM 13 | // CHECK: AddressSanitizer: heap-buffer-overflow 14 | // CHECK: #0 {{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-2]] 15 | // CHECK: allocated by thread T{{.*}} here: 16 | // CHECK: #0 {{.*}}strdup 17 | // CHECK: strdup_oob_test.cc:[[@LINE-6]] 18 | return x; 19 | } 20 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/strerror_r_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && %t 2 | 3 | // Regression test for PR17138. 4 | 5 | #include 6 | #include 7 | 8 | int main() { 9 | char buf[1024]; 10 | char *res = (char *)strerror_r(300, buf, sizeof(buf)); 11 | assert(res != 0); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/strip_path_prefix.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_asan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS="strip_path_prefix='/'" not %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-NOT: #0 0x{{.*}} ({{[/].*}}) 12 | } 13 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/time_interceptor.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s 2 | 3 | // Test the time() interceptor. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | time_t *tm = (time_t*)malloc(sizeof(time_t)); 11 | free(tm); 12 | time_t t = time(tm); 13 | printf("Time: %s\n", ctime(&t)); // NOLINT 14 | // CHECK: use-after-free 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/use-after-poison.cc: -------------------------------------------------------------------------------- 1 | // Check that __asan_poison_memory_region works. 2 | // RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s 3 | // 4 | // Check that we can disable it 5 | // RUN: ASAN_OPTIONS=allow_user_poisoning=0 %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/asan/lit_tests/TestCases/use-after-scope-nobug.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && %t 2 | 3 | #include 4 | 5 | int main() { 6 | int *p = 0; 7 | // Variable goes in and out of scope. 8 | for (int i = 0; i < 3; i++) { 9 | int x = 0; 10 | p = &x; 11 | } 12 | printf("PASSED\n"); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/use-after-scope-temp.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \ 2 | // RUN: %t 2>&1 | FileCheck %s 3 | // 4 | // Lifetime for temporaries is not emitted yet. 5 | // XFAIL: * 6 | 7 | #include 8 | 9 | struct IntHolder { 10 | explicit IntHolder(int val) : val(val) { 11 | printf("IntHolder: %d\n", val); 12 | } 13 | int val; 14 | }; 15 | 16 | const IntHolder *saved; 17 | 18 | void save(const IntHolder &holder) { 19 | saved = &holder; 20 | } 21 | 22 | int main(int argc, char *argv[]) { 23 | save(IntHolder(10)); 24 | int x = saved->val; // BOOM 25 | // CHECK: ERROR: AddressSanitizer: stack-use-after-scope 26 | // CHECK: #0 0x{{.*}} in main {{.*}}use-after-scope-temp.cc:[[@LINE-2]] 27 | printf("saved value: %d\n", x); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/TestCases/use-after-scope.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \ 2 | // RUN: not %t 2>&1 | FileCheck %s 3 | // RUN: ASAN_OPTIONS="detect_stack_use_after_return=1" not %t 2>&1 | FileCheck %s 4 | 5 | int main() { 6 | int *p = 0; 7 | { 8 | int x = 0; 9 | p = &x; 10 | } 11 | return *p; // BOOM 12 | // CHECK: ERROR: AddressSanitizer: stack-use-after-scope 13 | // CHECK: #0 0x{{.*}} in main {{.*}}use-after-scope.cc:[[@LINE-2]] 14 | // CHECK: Address 0x{{.*}} is located in stack of thread T{{.*}} at offset [[OFFSET:[^ ]+]] in frame 15 | // {{\[}}[[OFFSET]], {{[0-9]+}}) 'x' 16 | } 17 | -------------------------------------------------------------------------------- /lib/asan/lit_tests/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@/lib/lit.common.unit.configured") 6 | 7 | # Setup config name. 8 | config.name = 'AddressSanitizer-Unit' 9 | 10 | # Setup test source and exec root. For unit tests, we define 11 | # it as build directory with ASan unit tests. 12 | config.test_exec_root = "@ASAN_BINARY_DIR@/tests" 13 | config.test_source_root = config.test_exec_root 14 | 15 | # Enable leak detection in ASan unit tests on x86_64-linux. 16 | if config.host_os == 'Linux' and config.host_arch == 'x86_64': 17 | config.environment['ASAN_OPTIONS'] = 'detect_leaks=1' 18 | -------------------------------------------------------------------------------- /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/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/asan/tests/asan_racy_double_free_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | const int N = 1000; 6 | void *x[N]; 7 | 8 | void *Thread1(void *unused) { 9 | for (int i = 0; i < N; i++) { 10 | fprintf(stderr, "%s %d\n", __FUNCTION__, i); 11 | free(x[i]); 12 | } 13 | return NULL; 14 | } 15 | 16 | void *Thread2(void *unused) { 17 | for (int i = 0; i < N; i++) { 18 | fprintf(stderr, "%s %d\n", __FUNCTION__, i); 19 | free(x[i]); 20 | } 21 | return NULL; 22 | } 23 | 24 | int main() { 25 | for (int i = 0; i < N; i++) 26 | x[i] = malloc(128); 27 | pthread_t t[2]; 28 | pthread_create(&t[0], 0, Thread1, 0); 29 | pthread_create(&t[1], 0, Thread2, 0); 30 | pthread_join(t[0], 0); 31 | pthread_join(t[1], 0); 32 | } 33 | -------------------------------------------------------------------------------- /lib/asan/tests/asan_test.ignore: -------------------------------------------------------------------------------- 1 | # blacklisted functions for instrumented ASan unit test 2 | fun:*IgnoreTest* 3 | fun:*SomeOtherFunc* 4 | -------------------------------------------------------------------------------- /lib/asan/tests/asan_test_main.cc: -------------------------------------------------------------------------------- 1 | //===-- asan_test_main.cc -------------------------------------------------===// 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 | //===----------------------------------------------------------------------===// 13 | #include "asan_test_utils.h" 14 | 15 | int main(int argc, char **argv) { 16 | testing::GTEST_FLAG(death_test_style) = "threadsafe"; 17 | testing::InitGoogleTest(&argc, argv); 18 | return RUN_ALL_TESTS(); 19 | } 20 | -------------------------------------------------------------------------------- /lib/dfsan/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/dfsan/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 := dfsan 11 | SubDirs := 12 | 13 | Sources := $(foreach file,$(wildcard $(Dir)/*.cc),$(notdir $(file))) 14 | ObjNames := $(Sources:%.cc=%.o) 15 | 16 | Implementation := Generic 17 | 18 | # FIXME: use automatic dependencies? 19 | Dependencies := $(wildcard $(Dir)/*.h) 20 | Dependencies += $(wildcard $(Dir)/../sanitizer_common/*.h) 21 | 22 | # Define a convenience variable for all the dfsan functions. 23 | DfsanFunctions := $(Sources:%.cc=%) 24 | -------------------------------------------------------------------------------- /lib/dfsan/dfsan.syms.extra: -------------------------------------------------------------------------------- 1 | dfsan_* 2 | __dfsan_* 3 | __dfsw_* 4 | -------------------------------------------------------------------------------- /lib/dfsan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/dfsan/lit_tests/basic.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_dfsan -m64 %s -o %t && %t 2 | // RUN: %clang_dfsan -mllvm -dfsan-args-abi -m64 %s -o %t && %t 3 | 4 | // Tests that labels are propagated through loads and stores. 5 | 6 | #include 7 | #include 8 | 9 | int main(void) { 10 | int i = 1; 11 | dfsan_label i_label = dfsan_create_label("i", 0); 12 | dfsan_set_label(i_label, &i, sizeof(i)); 13 | 14 | dfsan_label new_label = dfsan_get_label(i); 15 | assert(i_label == new_label); 16 | 17 | dfsan_label read_label = dfsan_read_label(&i, sizeof(i)); 18 | assert(i_label == read_label); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /lib/dfsan/lit_tests/fncall.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_dfsan -m64 %s -o %t && %t 2 | // RUN: %clang_dfsan -mllvm -dfsan-args-abi -m64 %s -o %t && %t 3 | 4 | // Tests that labels are propagated through function calls. 5 | 6 | #include 7 | #include 8 | 9 | int f(int x) { 10 | int j = 2; 11 | dfsan_label j_label = dfsan_create_label("j", 0); 12 | dfsan_set_label(j_label, &j, sizeof(j)); 13 | return x + j; 14 | } 15 | 16 | int main(void) { 17 | int i = 1; 18 | dfsan_label i_label = dfsan_create_label("i", 0); 19 | dfsan_set_label(i_label, &i, sizeof(i)); 20 | 21 | dfsan_label ij_label = dfsan_get_label(f(i)); 22 | assert(dfsan_has_label(ij_label, i_label)); 23 | assert(dfsan_has_label_with_desc(ij_label, "j")); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /lib/dfsan/lit_tests/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured") 3 | 4 | # Load tool-specific config that would do the real work. 5 | lit_config.load_config(config, "@DFSAN_SOURCE_DIR@/lit_tests/lit.cfg") 6 | -------------------------------------------------------------------------------- /lib/i386/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/i386/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 := builtins 11 | SubDirs := 12 | OnlyArchs := i386 13 | 14 | AsmSources := $(foreach file,$(wildcard $(Dir)/*.S),$(notdir $(file))) 15 | Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file))) 16 | ObjNames := $(Sources:%.c=%.o) $(AsmSources:%.S=%.o) 17 | Implementation := Optimized 18 | 19 | # FIXME: use automatic dependencies? 20 | Dependencies := $(wildcard lib/*.h $(Dir)/*.h) 21 | -------------------------------------------------------------------------------- /lib/i386/muldi3.S: -------------------------------------------------------------------------------- 1 | // This file is dual licensed under the MIT and the University of Illinois Open 2 | // Source Licenses. See LICENSE.TXT for details. 3 | 4 | #include "../assembly.h" 5 | 6 | // di_int __muldi3(di_int a, di_int b); 7 | 8 | #ifdef __i386__ 9 | 10 | .text 11 | .align 4 12 | DEFINE_COMPILERRT_FUNCTION(__muldi3) 13 | pushl %ebx 14 | movl 16(%esp), %eax // b.lo 15 | movl 12(%esp), %ecx // a.hi 16 | imull %eax, %ecx // b.lo * a.hi 17 | 18 | movl 8(%esp), %edx // a.lo 19 | movl 20(%esp), %ebx // b.hi 20 | imull %edx, %ebx // a.lo * b.hi 21 | 22 | mull %edx // EDX:EAX = a.lo * b.lo 23 | addl %ecx, %ebx // EBX = (a.lo*b.hi + a.hi*b.lo) 24 | addl %ebx, %edx 25 | 26 | popl %ebx 27 | retl 28 | END_COMPILERRT_FUNCTION(__muldi3) 29 | 30 | #endif // __i386__ 31 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/AsanConfig/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured") 3 | 4 | # Tool-specific config options. 5 | config.lsan_lit_src_root = "@LSAN_LIT_SOURCE_DIR@" 6 | 7 | # Load tool-specific config that would do the real work. 8 | lit_config.load_config(config, "@LSAN_LIT_SOURCE_DIR@/AsanConfig/lit.cfg") 9 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/LsanConfig/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured") 3 | 4 | # Tool-specific config options. 5 | config.lsan_lit_src_root = "@LSAN_LIT_SOURCE_DIR@" 6 | 7 | # Load tool-specific config that would do the real work. 8 | lit_config.load_config(config, "@LSAN_LIT_SOURCE_DIR@/LsanConfig/lit.cfg") 9 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/SharedLibs/huge_tls_lib_so.cc: -------------------------------------------------------------------------------- 1 | // A loadable module with a large thread local section, which would require 2 | // allocation of a new TLS storage chunk when loaded with dlopen(). We use it 3 | // to test the reachability of such chunks in LSan tests. 4 | 5 | // This must be large enough that it doesn't fit into preallocated static TLS 6 | // space (see STATIC_TLS_SURPLUS in glibc). 7 | __thread void *huge_thread_local_array[(1 << 20) / sizeof(void *)]; // NOLINT 8 | 9 | extern "C" void **StoreToTLS(void *p) { 10 | huge_thread_local_array[0] = p; 11 | return &huge_thread_local_array[0]; 12 | } 13 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/SharedLibs/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # Sources in this directory are compiled as shared libraries and used by 2 | # tests in parent directory. 3 | 4 | config.suffixes = [] 5 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/disabler.cc: -------------------------------------------------------------------------------- 1 | // Test for ScopedDisabler. 2 | // RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | #include 8 | 9 | #include "sanitizer/lsan_interface.h" 10 | 11 | int main() { 12 | void **p; 13 | { 14 | __lsan::ScopedDisabler d; 15 | p = new void *; 16 | } 17 | *reinterpret_cast(p) = malloc(666); 18 | void *q = malloc(1337); 19 | // Break optimization. 20 | fprintf(stderr, "Test alloc: %p.\n", q); 21 | return 0; 22 | } 23 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) 24 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/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: %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 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/ignore_object_errors.cc: -------------------------------------------------------------------------------- 1 | // Test for incorrect use of __lsan_ignore_object(). 2 | // RUN: LSAN_BASE="verbosity=2" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | #include 8 | 9 | #include "sanitizer/lsan_interface.h" 10 | 11 | int main() { 12 | void *p = malloc(1337); 13 | fprintf(stderr, "Test alloc: %p.\n", p); 14 | __lsan_ignore_object(p); 15 | __lsan_ignore_object(p); 16 | free(p); 17 | __lsan_ignore_object(p); 18 | return 0; 19 | } 20 | // CHECK: Test alloc: [[ADDR:.*]]. 21 | // CHECK: heap object at [[ADDR]] is already being ignored 22 | // CHECK: no heap object found at [[ADDR]] 23 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/large_allocation_leak.cc: -------------------------------------------------------------------------------- 1 | // Test that LargeMmapAllocator's chunks aren't reachable via some internal data structure. 2 | // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | #include 8 | 9 | int main() { 10 | // maxsize in primary allocator is always less than this (1 << 25). 11 | void *large_alloc = malloc(33554432); 12 | fprintf(stderr, "Test alloc: %p.\n", large_alloc); 13 | return 0; 14 | } 15 | // CHECK: Test alloc: [[ADDR:.*]]. 16 | // CHECK: LeakSanitizer: detected memory leaks 17 | // CHECK: [[ADDR]] (33554432 bytes) 18 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 19 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/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 %t 5 | // RUN: LSAN_OPTIONS=$LSAN_BASE not %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 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/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 && %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 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/pointer_to_self.cc: -------------------------------------------------------------------------------- 1 | // Regression test: pointers to self should not confuse LSan into thinking the 2 | // object is indirectly leaked. Only external pointers count. 3 | // RUN: LSAN_BASE="report_objects=1:use_registers=0" 4 | // RUN: %clangxx_lsan %s -o %t 5 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %t 2>&1 | FileCheck %s 6 | 7 | #include 8 | #include 9 | 10 | int main() { 11 | void *p = malloc(1337); 12 | *reinterpret_cast(p) = p; 13 | fprintf(stderr, "Test alloc: %p.\n", p); 14 | } 15 | // CHECK: Test alloc: [[ADDR:.*]]. 16 | // CHECK: LeakSanitizer: detected memory leaks 17 | // CHECK: [[ADDR]] (1337 bytes) 18 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 19 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/suppressions_default.cc: -------------------------------------------------------------------------------- 1 | // RUN: LSAN_BASE="use_registers=0:use_stacks=0" 2 | // RUN: %clangxx_lsan %s -o %t 3 | // RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s 4 | 5 | #include 6 | #include 7 | 8 | #include "sanitizer/lsan_interface.h" 9 | 10 | extern "C" 11 | const char *__lsan_default_suppressions() { 12 | return "leak:*LSanTestLeakingFunc*"; 13 | } 14 | 15 | void LSanTestLeakingFunc() { 16 | void *p = malloc(666); 17 | fprintf(stderr, "Test alloc: %p.\n", p); 18 | } 19 | 20 | int main() { 21 | LSanTestLeakingFunc(); 22 | void *q = malloc(1337); 23 | fprintf(stderr, "Test alloc: %p.\n", q); 24 | return 0; 25 | } 26 | // CHECK: Suppressions used: 27 | // CHECK: 1 666 *LSanTestLeakingFunc* 28 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) 29 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/use_globals_initialized.cc: -------------------------------------------------------------------------------- 1 | // Test that initialized globals are included in the root set. 2 | // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=0" not %t 2>&1 | FileCheck %s 5 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=1" %t 2>&1 6 | // RUN: LSAN_OPTIONS="" %t 2>&1 7 | 8 | #include 9 | #include 10 | 11 | void *data_var = (void *)1; 12 | 13 | int main() { 14 | data_var = malloc(1337); 15 | fprintf(stderr, "Test alloc: %p.\n", data_var); 16 | return 0; 17 | } 18 | // CHECK: Test alloc: [[ADDR:.*]]. 19 | // CHECK: LeakSanitizer: detected memory leaks 20 | // CHECK: [[ADDR]] (1337 bytes) 21 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 22 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/use_globals_uninitialized.cc: -------------------------------------------------------------------------------- 1 | // Test that uninitialized globals are included in the root set. 2 | // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=0" not %t 2>&1 | FileCheck %s 5 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=1" %t 2>&1 6 | // RUN: LSAN_OPTIONS="" %t 2>&1 7 | 8 | #include 9 | #include 10 | 11 | void *bss_var; 12 | 13 | int main() { 14 | bss_var = malloc(1337); 15 | fprintf(stderr, "Test alloc: %p.\n", bss_var); 16 | return 0; 17 | } 18 | // CHECK: Test alloc: [[ADDR:.*]]. 19 | // CHECK: LeakSanitizer: detected memory leaks 20 | // CHECK: [[ADDR]] (1337 bytes) 21 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 22 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/use_stacks.cc: -------------------------------------------------------------------------------- 1 | // Test that stack of main thread is included in the root set. 2 | // RUN: LSAN_BASE="report_objects=1:use_registers=0" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %t 2>&1 | FileCheck %s 5 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %t 2>&1 6 | // RUN: LSAN_OPTIONS="" %t 2>&1 7 | 8 | #include 9 | #include 10 | 11 | int main() { 12 | void *stack_var = malloc(1337); 13 | fprintf(stderr, "Test alloc: %p.\n", stack_var); 14 | // Do not return from main to prevent the pointer from going out of scope. 15 | exit(0); 16 | } 17 | // CHECK: Test alloc: [[ADDR:.*]]. 18 | // CHECK: LeakSanitizer: detected memory leaks 19 | // CHECK: [[ADDR]] (1337 bytes) 20 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 21 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/use_tls_static.cc: -------------------------------------------------------------------------------- 1 | // Test that statically allocated TLS space is included in the root set. 2 | // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %t 2>&1 | FileCheck %s 5 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %t 2>&1 6 | // RUN: LSAN_OPTIONS="" %t 2>&1 7 | 8 | #include 9 | #include 10 | 11 | __thread void *tls_var; 12 | 13 | int main() { 14 | tls_var = malloc(1337); 15 | fprintf(stderr, "Test alloc: %p.\n", tls_var); 16 | return 0; 17 | } 18 | // CHECK: Test alloc: [[ADDR:.*]]. 19 | // CHECK: LeakSanitizer: detected memory leaks 20 | // CHECK: [[ADDR]] (1337 bytes) 21 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 22 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/TestCases/use_unaligned.cc: -------------------------------------------------------------------------------- 1 | // Test that unaligned pointers are detected correctly. 2 | // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" 3 | // RUN: %clangxx_lsan %s -o %t 4 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_unaligned=0" not %t 2>&1 | FileCheck %s 5 | // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_unaligned=1" %t 2>&1 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | void *arr[2]; 12 | 13 | int main() { 14 | void *p = malloc(1337); 15 | fprintf(stderr, "Test alloc: %p.\n", p); 16 | char *char_arr = (char *)arr; 17 | memcpy(char_arr + 1, &p, sizeof(p)); 18 | return 0; 19 | } 20 | // CHECK: Test alloc: [[ADDR:.*]]. 21 | // CHECK: LeakSanitizer: detected memory leaks 22 | // CHECK: [[ADDR]] (1337 bytes) 23 | // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 24 | -------------------------------------------------------------------------------- /lib/lsan/lit_tests/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@/lib/lit.common.unit.configured") 6 | 7 | # Setup config name. 8 | config.name = 'LeakSanitizer-Unit' 9 | # Setup test source and exec root. For unit tests, we define 10 | # it as build directory with LSan unit tests. 11 | config.test_exec_root = "@LSAN_BINARY_DIR@/tests" 12 | config.test_source_root = config.test_exec_root 13 | -------------------------------------------------------------------------------- /lib/lsan/tests/lsan_dummy_unittest.cc: -------------------------------------------------------------------------------- 1 | //===-- lsan_dummy_unittest.cc --------------------------------------------===// 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 LeakSanitizer runtime. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | #include "gtest/gtest.h" 14 | 15 | TEST(LeakSanitizer, EmptyTest) { 16 | // Empty test to suppress LIT warnings about lack of tests. 17 | } 18 | 19 | int main(int argc, char **argv) { 20 | ::testing::InitGoogleTest(&argc, argv); 21 | return RUN_ALL_TESTS(); 22 | } 23 | -------------------------------------------------------------------------------- /lib/modsi3.c: -------------------------------------------------------------------------------- 1 | /* ===-- modsi3.c - Implement __modsi3 -------------------------------------=== 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 __modsi3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | su_int COMPILER_RT_ABI __divsi3(si_int a, si_int b); 18 | 19 | /* Returns: a % b */ 20 | 21 | COMPILER_RT_ABI si_int 22 | __modsi3(si_int a, si_int b) 23 | { 24 | return a - __divsi3(a, b) * b; 25 | } 26 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/Linux/glob_nomatch.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %t %p 2 | // RUN: %clangxx_msan -m64 -O3 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/Linux/glob_test_root/aa: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/msan/lit_tests/Linux/glob_test_root/aa -------------------------------------------------------------------------------- /lib/msan/lit_tests/Linux/glob_test_root/ab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/msan/lit_tests/Linux/glob_test_root/ab -------------------------------------------------------------------------------- /lib/msan/lit_tests/Linux/glob_test_root/ba: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/msan/lit_tests/Linux/glob_test_root/ba -------------------------------------------------------------------------------- /lib/msan/lit_tests/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/msan/lit_tests/Linux/tcgetattr.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/Linux/xattr_test_root/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/msan/lit_tests/Linux/xattr_test_root/a -------------------------------------------------------------------------------- /lib/msan/lit_tests/SharedLibs/dso-origin-so.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "dso-origin.h" 4 | 5 | void my_access(int *p) { 6 | volatile int tmp; 7 | // Force initialize-ness check. 8 | if (*p) 9 | tmp = 1; 10 | } 11 | 12 | void *my_alloc(unsigned sz) { 13 | return malloc(sz); 14 | } 15 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/SharedLibs/dso-origin.h: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | void my_access(int *p); 3 | void *my_alloc(unsigned sz); 4 | } 5 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/SharedLibs/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # Sources in this directory are compiled as shared libraries and used by 2 | # tests in parent directory. 3 | 4 | config.suffixes = [] 5 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/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@/lib/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 | config.test_exec_root = "@MSAN_BINARY_DIR@/tests" 13 | config.test_source_root = config.test_exec_root 14 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/backtrace.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %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", strlen(s[i])); 21 | } 22 | 23 | int main(void) { 24 | f(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/c-strdup.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_msan -m64 -O0 %s -o %t && %t >%t.out 2>&1 2 | // RUN: %clang_msan -m64 -O1 %s -o %t && %t >%t.out 2>&1 3 | // RUN: %clang_msan -m64 -O2 %s -o %t && %t >%t.out 2>&1 4 | // RUN: %clang_msan -m64 -O3 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/cxa_atexit.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/dlerror.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %t 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) { 9 | void *p = dlopen("/bad/file/name", RTLD_NOW); 10 | assert(!p); 11 | char *s = dlerror(); 12 | printf("%s, %zu\n", s, strlen(s)); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/errno.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/getaddrinfo-positive.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && not %t >%t.out 2>&1 2 | // RUN: FileCheck %s < %t.out 3 | // RUN: %clangxx_msan -m64 -O3 %s -o %t && not %t >%t.out 2>&1 4 | // RUN: FileCheck %s < %t.out 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | volatile int z; 12 | 13 | int main(void) { 14 | struct addrinfo *ai; 15 | struct addrinfo hint; 16 | int res = getaddrinfo("localhost", NULL, NULL, &ai); 17 | if (ai) z = 1; // OK 18 | res = getaddrinfo("localhost", NULL, &hint, &ai); 19 | // CHECK: UMR in __interceptor_getaddrinfo at offset 0 inside 20 | // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value 21 | // CHECK: #0 {{.*}} in main {{.*}}getaddrinfo-positive.cc:[[@LINE-3]] 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/getaddrinfo.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %t 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void poison_stack_ahead() { 9 | char buf[100000]; 10 | // With -O0 this poisons a large chunk of stack. 11 | } 12 | 13 | int main(void) { 14 | poison_stack_ahead(); 15 | 16 | struct addrinfo *ai; 17 | 18 | // This should trigger loading of libnss_dns and friends. 19 | // Those libraries are typically uninstrumented.They will call strlen() on a 20 | // stack-allocated buffer, which is very likely to be poisoned. Test that we 21 | // don't report this as an UMR. 22 | int res = getaddrinfo("not-in-etc-hosts", NULL, NULL, &ai); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/getline.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && %t %p 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char **argv) { 9 | assert(argc == 2); 10 | char buf[1024]; 11 | snprintf(buf, sizeof(buf), "%s/%s", argv[1], "getline_test_data"); 12 | 13 | FILE *fp = fopen(buf, "r"); 14 | assert(fp); 15 | 16 | char *line = 0; 17 | size_t len = 0; 18 | int n = getline(&line, &len, fp); 19 | assert(n == 6); 20 | assert(strcmp(line, "abcde\n") == 0); 21 | 22 | n = getline(&line, &len, fp); 23 | assert(n == 6); 24 | assert(strcmp(line, "12345\n") == 0); 25 | 26 | free(line); 27 | fclose(fp); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/getline_test_data: -------------------------------------------------------------------------------- 1 | abcde 2 | 12345 3 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/initgroups.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %t 2 | 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | initgroups("root", 0); 8 | // The above fails unless you are root. Does not matter, MSan false positive 9 | // (which we are testing for) happens anyway. 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/inline.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O3 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/ioctl.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %t 2 | // RUN: %clangxx_msan -m64 -O3 -g %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured") 3 | 4 | # Load tool-specific config that would do the real work. 5 | lit_config.load_config(config, "@MSAN_SOURCE_DIR@/lit_tests/lit.cfg") 6 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/mmap_below_shadow.cc: -------------------------------------------------------------------------------- 1 | // Test mmap behavior when map address is below shadow range. 2 | // With MAP_FIXED, we crash. 3 | // Without MAP_FIXED, we ignore the address hint and map somewhere in 4 | // application range. 5 | 6 | // RUN: %clangxx_msan -m64 -O0 -DFIXED=0 %s -o %t && %t 7 | // RUN: %clangxx_msan -m64 -O0 -DFIXED=1 %s -o %t && not %t 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main(void) { 14 | // Hint address just below shadow. 15 | uintptr_t hint = 0x1f0000000000ULL; 16 | const uintptr_t app_start = 0x600000000000ULL; 17 | uintptr_t p = (uintptr_t)mmap( 18 | (void *)hint, 4096, PROT_READ | PROT_WRITE, 19 | MAP_PRIVATE | MAP_ANONYMOUS | (FIXED ? MAP_FIXED : 0), 0, 0); 20 | assert(p >= app_start); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/poison_in_free.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -O0 %s -o %t && not %t >%t.out 2>&1 2 | // FileCheck %s <%t.out 3 | // RUN: %clangxx_msan -O0 %s -o %t && MSAN_OPTIONS=poison_in_free=0 %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/pthread_getattr_np_deadlock.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -fsanitize-memory-track-origins -O0 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/scandir_test_root/aaa: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/msan/lit_tests/scandir_test_root/aaa -------------------------------------------------------------------------------- /lib/msan/lit_tests/scandir_test_root/aab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/msan/lit_tests/scandir_test_root/aab -------------------------------------------------------------------------------- /lib/msan/lit_tests/scandir_test_root/bbb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/lib/msan/lit_tests/scandir_test_root/bbb -------------------------------------------------------------------------------- /lib/msan/lit_tests/select.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && not %t >%t.out 2>&1 2 | // RUN: FileCheck %s < %t.out 3 | // RUN: %clangxx_msan -m64 -O1 %s -o %t && not %t >%t.out 2>&1 4 | // RUN: FileCheck %s < %t.out 5 | // RUN: %clangxx_msan -m64 -O2 %s -o %t && not %t >%t.out 2>&1 6 | // RUN: FileCheck %s < %t.out 7 | // RUN: %clangxx_msan -m64 -O3 %s -o %t && not %t >%t.out 2>&1 8 | // RUN: FileCheck %s < %t.out 9 | 10 | #include 11 | int main(int argc, char **argv) { 12 | int x; 13 | int *volatile p = &x; 14 | int z = *p ? 1 : 0; 15 | if (z) 16 | exit(0); 17 | // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value 18 | // CHECK: {{#0 0x.* in main .*select.cc:}}[[@LINE-3]] 19 | 20 | // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*select.cc:.* main}} 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/select_origin.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && not %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -O1 %s -o %t && not %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -O2 %s -o %t && not %t 2>&1 | FileCheck %s 4 | 5 | // Test condition origin propagation through "select" IR instruction. 6 | 7 | #include 8 | #include 9 | 10 | __attribute__((noinline)) 11 | int *max_by_ptr(int *a, int *b) { 12 | return *a < *b ? b : a; 13 | } 14 | 15 | int main(void) { 16 | int x; 17 | int *volatile px = &x; 18 | int y = 43; 19 | int *p = max_by_ptr(px, &y); 20 | // CHECK: Uninitialized value was created by an allocation of 'x' in the stack frame of function 'main' 21 | return *p; 22 | } 23 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/setlocale.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %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/msan/lit_tests/sigwait.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -std=c++11 -O0 -g %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/sigwaitinfo.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -std=c++11 -O0 -g %s -o %t && %t 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void test_sigwaitinfo() { 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 | siginfo_t info; 20 | int res = sigwaitinfo(&s, &info); 21 | assert(!res); 22 | // The following checks that sig is initialized. 23 | assert(info.si_signo == SIGUSR1); 24 | assert(-1 == __msan_test_shadow(&info, sizeof(info))); 25 | } 26 | } 27 | 28 | int main(void) { 29 | test_sigwaitinfo(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/strerror_r-non-gnu.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_msan -std=c99 -O0 -g %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/strlen_of_shadow.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %t 2 | 3 | // Check that strlen() and similar intercepted functions can be called on shadow 4 | // memory. 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | const char *mem_to_shadow(const char *p) { 12 | return (char *)((uintptr_t)p & ~0x400000000000ULL); 13 | } 14 | 15 | int main(void) { 16 | const char *s = "abcdef"; 17 | assert(strlen(s) == 6); 18 | assert(strlen(mem_to_shadow(s)) == 0); 19 | 20 | char *t = new char[42]; 21 | t[41] = 0; 22 | assert(strlen(mem_to_shadow(t)) == 41); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/sync_lock_set_and_test.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %t 2 | 3 | int main(void) { 4 | int i; 5 | __sync_lock_test_and_set(&i, 0); 6 | return i; 7 | } 8 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/textdomain.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %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/msan/lit_tests/times.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/tls_reuse.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/tzset.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %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/msan/lit_tests/unaligned_read_origin.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -o %t && not %t >%t.out 2>&1 2 | // RUN: FileCheck %s < %t.out && FileCheck %s < %t.out 3 | // RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O3 %s -o %t && not %t >%t.out 2>&1 4 | // RUN: FileCheck %s < %t.out && FileCheck %s < %t.out 5 | 6 | #include 7 | 8 | int main(int argc, char **argv) { 9 | int x; 10 | int *volatile p = &x; 11 | return __sanitizer_unaligned_load32(p); 12 | // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value 13 | // CHECK: {{#0 0x.* in main .*unaligned_read_origin.cc:}}[[@LINE-2]] 14 | // CHECK: Uninitialized value was created by an allocation of 'x' in the stack frame of function 'main' 15 | // CHECK: {{#0 0x.* in main .*unaligned_read_origin.cc:}}[[@LINE-7]] 16 | } 17 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/vector_cvt.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -o %t && %t 2 | // RUN: %clangxx_msan -DPOSITIVE -m64 -O0 %s -o %t && not %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | int to_int(double v) { 7 | __m128d t = _mm_set_sd(v); 8 | int x = _mm_cvtsd_si32(t); 9 | return x; 10 | // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value 11 | // CHECK: #{{.*}} in to_int{{.*}}vector_cvt.cc:[[@LINE-4]] 12 | } 13 | 14 | int main() { 15 | #ifdef POSITIVE 16 | double v; 17 | #else 18 | double v = 1.1; 19 | #endif 20 | double* volatile p = &v; 21 | int x = to_int(*p); 22 | return !x; 23 | } 24 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/vector_select.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_msan -m64 -O0 %s -c -o %t 2 | // RUN: %clangxx_msan -m64 -O3 %s -c -o %t 3 | 4 | // Regression test for MemorySanitizer instrumentation of a select instruction 5 | // with vector arguments. 6 | 7 | #include 8 | 9 | __m128d select(bool b, __m128d c, __m128d d) 10 | { 11 | return b ? c : d; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/wrap_indirect_calls/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # Sources in this directory are used by tests in parent directory. 2 | 3 | config.suffixes = [] 4 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/wrap_indirect_calls/one.cc: -------------------------------------------------------------------------------- 1 | int f_other_object(int x, int y) { 2 | return x * y; 3 | } 4 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/wrap_indirect_calls/two.cc: -------------------------------------------------------------------------------- 1 | int f_dso(int x, int y) { 2 | return 2 * x + y; 3 | } 4 | 5 | int f_replaced(int x, int y) { 6 | return x + y + 5; 7 | } 8 | 9 | int f_replacement(int x, int y) { 10 | return x + y + 6; 11 | } 12 | -------------------------------------------------------------------------------- /lib/msan/lit_tests/wrap_indirect_calls/wrapper.cc: -------------------------------------------------------------------------------- 1 | int f_replaced(int x, int y); 2 | int f_replacement(int x, int y); 3 | 4 | int cnt; 5 | 6 | extern "C" void *wrapper(void *p) { 7 | ++cnt; 8 | if (p == (void *)f_replaced) 9 | return (void *)f_replacement; 10 | return p; 11 | } 12 | -------------------------------------------------------------------------------- /lib/msan/msan.syms.extra: -------------------------------------------------------------------------------- 1 | __msan_* 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/msan/tests/msan_test_main.cc: -------------------------------------------------------------------------------- 1 | //===-- msan_test_main.cc -------------------------------------------------===// 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 | //===----------------------------------------------------------------------===// 13 | #ifndef MSAN_EXTERNAL_TEST_CONFIG 14 | #include "msan_test_config.h" 15 | #endif // MSAN_EXTERNAL_TEST_CONFIG 16 | 17 | int main(int argc, char **argv) { 18 | testing::GTEST_FLAG(death_test_style) = "threadsafe"; 19 | testing::InitGoogleTest(&argc, argv); 20 | return RUN_ALL_TESTS(); 21 | } 22 | -------------------------------------------------------------------------------- /lib/negdf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/negdf2.c - double-precision negation ------------------*- 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 | // This file implements double-precision soft-float negation. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #define DOUBLE_PRECISION 15 | #include "fp_lib.h" 16 | 17 | ARM_EABI_FNALIAS(dneg, negdf2) 18 | 19 | fp_t __negdf2(fp_t a) { 20 | return fromRep(toRep(a) ^ signBit); 21 | } 22 | -------------------------------------------------------------------------------- /lib/negdi2.c: -------------------------------------------------------------------------------- 1 | /* ===-- negdi2.c - Implement __negdi2 -------------------------------------=== 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 __negdi2 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: -a */ 18 | 19 | di_int 20 | __negdi2(di_int a) 21 | { 22 | /* Note: this routine is here for API compatibility; any sane compiler 23 | * should expand it inline. 24 | */ 25 | return -a; 26 | } 27 | -------------------------------------------------------------------------------- /lib/negsf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/negsf2.c - single-precision negation ------------------*- 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 | // This file implements single-precision soft-float negation. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #define SINGLE_PRECISION 15 | #include "fp_lib.h" 16 | 17 | ARM_EABI_FNALIAS(fneg, negsf2) 18 | 19 | COMPILER_RT_ABI fp_t 20 | __negsf2(fp_t a) { 21 | return fromRep(toRep(a) ^ signBit); 22 | } 23 | -------------------------------------------------------------------------------- /lib/negti2.c: -------------------------------------------------------------------------------- 1 | /* ===-- negti2.c - Implement __negti2 -------------------------------------=== 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 __negti2 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | #if __x86_64 18 | 19 | /* Returns: -a */ 20 | 21 | ti_int 22 | __negti2(ti_int a) 23 | { 24 | /* Note: this routine is here for API compatibility; any sane compiler 25 | * should expand it inline. 26 | */ 27 | return -a; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/ppc/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/ppc/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 := builtins 11 | SubDirs := 12 | OnlyArchs := ppc 13 | 14 | AsmSources := $(foreach file,$(wildcard $(Dir)/*.S),$(notdir $(file))) 15 | Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file))) 16 | ObjNames := $(Sources:%.c=%.o) $(AsmSources:%.S=%.o) 17 | Implementation := Optimized 18 | 19 | # FIXME: use automatic dependencies? 20 | Dependencies := $(wildcard lib/*.h $(Dir)/*.h) 21 | -------------------------------------------------------------------------------- /lib/profile/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PROFILE_SOURCES 2 | GCDAProfiling.c 3 | PGOProfiling.c) 4 | 5 | filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 arm) 6 | 7 | if(APPLE) 8 | add_compiler_rt_osx_static_runtime(clang_rt.profile_osx 9 | ARCH ${PROFILE_SUPPORTED_ARCH} 10 | SOURCES ${PROFILE_SOURCES}) 11 | else() 12 | foreach(arch ${PROFILE_SUPPORTED_ARCH}) 13 | add_compiler_rt_static_runtime(clang_rt.profile-${arch} 14 | ${arch} 15 | SOURCES ${PROFILE_SOURCES}) 16 | endforeach() 17 | endif() 18 | -------------------------------------------------------------------------------- /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),$(notdir $(file))) 14 | ObjNames := $(Sources:%.c=%.o) 15 | Implementation := Generic 16 | 17 | # FIXME: use automatic dependencies? 18 | Dependencies := $(wildcard $(Dir)/*.h) 19 | -------------------------------------------------------------------------------- /lib/sanitizer_common/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/sanitizer_common/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 := sanitizer_common 11 | SubDirs := 12 | 13 | Sources := $(foreach file,$(wildcard $(Dir)/*.cc),$(notdir $(file))) 14 | ObjNames := $(Sources:%.cc=%.o) 15 | 16 | Implementation := Generic 17 | 18 | # FIXME: use automatic dependencies? 19 | Dependencies := $(wildcard $(Dir)/*.h) 20 | 21 | # Define a convenience variable for all the sanitizer_common functions. 22 | SanitizerCommonFunctions := $(Sources:%.cc=%) 23 | -------------------------------------------------------------------------------- /lib/sanitizer_common/sanitizer_syscall_generic.inc: -------------------------------------------------------------------------------- 1 | //===-- sanitizer_syscall_generic.inc ---------------------------*- 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 | // Generic implementations of internal_syscall and internal_iserror. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #define internal_syscall syscall 15 | 16 | bool internal_iserror(uptr retval, int *rverrno) { 17 | if (retval == (uptr)-1) { 18 | if (rverrno) 19 | *rverrno = errno; 20 | return true; 21 | } else { 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/sanitizer_common/tests/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@/lib/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 | config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@", "lib", 13 | "sanitizer_common", "tests") 14 | config.test_source_root = config.test_exec_root 15 | -------------------------------------------------------------------------------- /lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc: -------------------------------------------------------------------------------- 1 | //===-- sanitizer_nolibc_test_main.cc -------------------------------------===// 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 ThreadSanitizer/AddressSanitizer runtime. 11 | // Tests for libc independence of sanitizer_common. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #include "sanitizer_common/sanitizer_libc.h" 16 | 17 | extern "C" void _start() { 18 | internal__exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /lib/sanitizer_common/tests/sanitizer_test_main.cc: -------------------------------------------------------------------------------- 1 | //===-- sanitizer_test_main.cc --------------------------------------------===// 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 ThreadSanitizer/AddressSanitizer runtime. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | #include "gtest/gtest.h" 14 | 15 | const char *argv0; 16 | 17 | int main(int argc, char **argv) { 18 | argv0 = argv[0]; 19 | testing::GTEST_FLAG(death_test_style) = "threadsafe"; 20 | testing::InitGoogleTest(&argc, argv); 21 | return RUN_ALL_TESTS(); 22 | } 23 | -------------------------------------------------------------------------------- /lib/tsan/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/tsan/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 := tsan 11 | SubDirs := rtl 12 | Sources := 13 | ObjNames := 14 | Dependencies := 15 | 16 | Implementation := Generic 17 | 18 | TsanFunctions := 19 | -------------------------------------------------------------------------------- /lib/tsan/check_analyze.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -u 3 | 4 | RES=$(./analyze_libtsan.sh) 5 | PrintRes() { 6 | printf "%s\n" "$RES" 7 | } 8 | 9 | PrintRes 10 | 11 | mops="write1 \ 12 | write2 \ 13 | write4 \ 14 | write8 \ 15 | read1 \ 16 | read2 \ 17 | read4 \ 18 | read8" 19 | func="func_entry \ 20 | func_exit" 21 | 22 | check() { 23 | res=$(PrintRes | egrep "$1 .* $2 $3; ") 24 | if [ "$res" == "" ]; then 25 | echo FAILED $1 must contain $2 $3 26 | exit 1 27 | fi 28 | } 29 | 30 | for f in $mops; do 31 | check $f rsp 1 # To read caller pc. 32 | check $f push 0 33 | check $f pop 0 34 | done 35 | 36 | for f in $func; do 37 | check $f rsp 0 38 | check $f push 0 39 | check $f pop 0 40 | check $f call 1 # TraceSwitch() 41 | done 42 | 43 | echo LGTM 44 | -------------------------------------------------------------------------------- /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/build" ]; then 7 | cd $ROOT/build 8 | else 9 | mkdir -p $ROOT/build 10 | cd $ROOT/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 | -------------------------------------------------------------------------------- /lib/tsan/check_memcpy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Ensure that tsan runtime does not contain compiler-emitted memcpy and memset calls. 4 | 5 | set -eu 6 | 7 | ROOTDIR=$(dirname $0) 8 | 9 | : ${CXX:=clang++} 10 | CFLAGS="-fsanitize=thread -fPIE -O1 -g" 11 | LDFLAGS="-pie -lpthread -ldl -lrt -lm -Wl,--whole-archive $ROOTDIR/rtl/libtsan.a -Wl,--no-whole-archive" 12 | 13 | SRC=$ROOTDIR/lit_tests/simple_race.cc 14 | OBJ=$SRC.o 15 | EXE=$SRC.exe 16 | $CXX $SRC $CFLAGS -c -o $OBJ 17 | $CXX $OBJ $LDFLAGS -o $EXE 18 | 19 | NCALL=$(objdump -d $EXE | egrep "callq .*__interceptor_mem(cpy|set)" | wc -l) 20 | if [ "$NCALL" != "0" ]; then 21 | echo FAIL: found $NCALL memcpy/memset calls 22 | exit 1 23 | fi 24 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/Helpers/blacklist.txt: -------------------------------------------------------------------------------- 1 | fun:*Blacklisted_Thread2* 2 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/Helpers/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # Files in this directory are helper files for other output tests. 2 | config.suffixes = [] 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/SharedLibs/lit.local.cfg: -------------------------------------------------------------------------------- 1 | # Sources in this directory are compiled as shared libraries and used by 2 | # tests in parent directory. 3 | 4 | config.suffixes = [] 5 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/SharedLibs/load_shared_lib-so.cc: -------------------------------------------------------------------------------- 1 | //===----------- load_shared_lib-so.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 ThreadSanitizer (TSan), a race detector. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include 15 | 16 | int GLOB_SHARED = 0; 17 | 18 | extern "C" 19 | void *write_from_so(void *unused) { 20 | GLOB_SHARED++; 21 | return NULL; 22 | } 23 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/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@/lib/lit.common.unit.configured") 6 | 7 | # Load tool-specific config that would do the real work. 8 | lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/Unit/lit.cfg") 9 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/atomic_free.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | void *Thread(void *a) { 6 | __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST); 7 | return 0; 8 | } 9 | 10 | int main() { 11 | int *a = new int(0); 12 | pthread_t t; 13 | pthread_create(&t, 0, Thread, a); 14 | sleep(1); 15 | delete a; 16 | pthread_join(t, 0); 17 | } 18 | 19 | // CHECK: WARNING: ThreadSanitizer: data race 20 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/atomic_free2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | void *Thread(void *a) { 6 | sleep(1); 7 | __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST); 8 | return 0; 9 | } 10 | 11 | int main() { 12 | int *a = new int(0); 13 | pthread_t t; 14 | pthread_create(&t, 0, Thread, a); 15 | delete a; 16 | pthread_join(t, 0); 17 | } 18 | 19 | // CHECK: WARNING: ThreadSanitizer: heap-use-after-free 20 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/atomic_stack.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int Global; 6 | 7 | void *Thread1(void *x) { 8 | sleep(1); 9 | __atomic_fetch_add(&Global, 1, __ATOMIC_RELAXED); 10 | return NULL; 11 | } 12 | 13 | void *Thread2(void *x) { 14 | Global++; 15 | return NULL; 16 | } 17 | 18 | int main() { 19 | pthread_t t[2]; 20 | pthread_create(&t[0], NULL, Thread1, NULL); 21 | pthread_create(&t[1], NULL, Thread2, NULL); 22 | pthread_join(t[0], NULL); 23 | pthread_join(t[1], NULL); 24 | } 25 | 26 | // CHECK: WARNING: ThreadSanitizer: data race 27 | // CHECK: Atomic write of size 4 28 | // CHECK: #0 __tsan_atomic32_fetch_add 29 | // CHECK: #1 Thread1 30 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/blacklist.cc: -------------------------------------------------------------------------------- 1 | // Test blacklist functionality for TSan. 2 | 3 | // RUN: %clangxx_tsan -O1 %s \ 4 | // RUN: -fsanitize-blacklist=%p/Helpers/blacklist.txt \ 5 | // RUN: -o %t && %t 2>&1 | FileCheck %s 6 | #include 7 | #include 8 | 9 | int Global; 10 | 11 | void *Thread1(void *x) { 12 | Global++; 13 | return NULL; 14 | } 15 | 16 | void *Blacklisted_Thread2(void *x) { 17 | Global--; 18 | return NULL; 19 | } 20 | 21 | int main() { 22 | pthread_t t[2]; 23 | pthread_create(&t[0], NULL, Thread1, NULL); 24 | pthread_create(&t[1], NULL, Blacklisted_Thread2, NULL); 25 | pthread_join(t[0], NULL); 26 | pthread_join(t[1], NULL); 27 | printf("PASS\n"); 28 | return 0; 29 | } 30 | 31 | // CHECK-NOT: ThreadSanitizer: data race 32 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/default_options.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | extern "C" const char *__tsan_default_options() { 6 | return "report_bugs=0"; 7 | } 8 | 9 | int Global; 10 | 11 | void *Thread1(void *x) { 12 | Global = 42; 13 | return NULL; 14 | } 15 | 16 | void *Thread2(void *x) { 17 | Global = 43; 18 | return NULL; 19 | } 20 | 21 | int main() { 22 | pthread_t t[2]; 23 | pthread_create(&t[0], NULL, Thread1, NULL); 24 | pthread_create(&t[1], NULL, Thread2, NULL); 25 | pthread_join(t[0], NULL); 26 | pthread_join(t[1], NULL); 27 | fprintf(stderr, "DONE\n"); 28 | return 0; 29 | } 30 | 31 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 32 | // CHECK: DONE 33 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/fd_close_norace.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void *Thread1(void *x) { 10 | int f = open("/dev/random", O_RDONLY); 11 | close(f); 12 | return NULL; 13 | } 14 | 15 | void *Thread2(void *x) { 16 | sleep(1); 17 | int f = open("/dev/random", O_RDONLY); 18 | close(f); 19 | return NULL; 20 | } 21 | 22 | int main() { 23 | pthread_t t[2]; 24 | pthread_create(&t[0], NULL, Thread1, NULL); 25 | pthread_create(&t[1], NULL, Thread2, NULL); 26 | pthread_join(t[0], NULL); 27 | pthread_join(t[1], NULL); 28 | printf("OK\n"); 29 | } 30 | 31 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 32 | 33 | 34 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/fd_close_norace2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/fd_dup_norace.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int fds[2]; 10 | 11 | void *Thread1(void *x) { 12 | char buf; 13 | read(fds[0], &buf, 1); 14 | close(fds[0]); 15 | return 0; 16 | } 17 | 18 | void *Thread2(void *x) { 19 | close(fds[1]); 20 | return 0; 21 | } 22 | 23 | int main() { 24 | fds[0] = open("/dev/random", O_RDONLY); 25 | fds[1] = dup2(fds[0], 100); 26 | pthread_t t[2]; 27 | pthread_create(&t[0], NULL, Thread1, NULL); 28 | pthread_create(&t[1], NULL, Thread2, NULL); 29 | pthread_join(t[0], NULL); 30 | pthread_join(t[1], NULL); 31 | printf("OK\n"); 32 | } 33 | 34 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 35 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/fd_location.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int fds[2]; 7 | 8 | void *Thread1(void *x) { 9 | write(fds[1], "a", 1); 10 | return NULL; 11 | } 12 | 13 | void *Thread2(void *x) { 14 | sleep(1); 15 | close(fds[0]); 16 | close(fds[1]); 17 | return NULL; 18 | } 19 | 20 | int main() { 21 | pipe(fds); 22 | pthread_t t[2]; 23 | pthread_create(&t[0], NULL, Thread1, NULL); 24 | pthread_create(&t[1], NULL, Thread2, NULL); 25 | pthread_join(t[0], NULL); 26 | pthread_join(t[1], NULL); 27 | } 28 | 29 | // CHECK: WARNING: ThreadSanitizer: data race 30 | // CHECK: Location is file descriptor {{[0-9]+}} created by main thread at: 31 | // CHECK: #0 pipe 32 | // CHECK: #1 main 33 | 34 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/fd_pipe_norace.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int fds[2]; 7 | int X; 8 | 9 | void *Thread1(void *x) { 10 | X = 42; 11 | write(fds[1], "a", 1); 12 | return NULL; 13 | } 14 | 15 | void *Thread2(void *x) { 16 | char buf; 17 | while (read(fds[0], &buf, 1) != 1) { 18 | } 19 | X = 43; 20 | return NULL; 21 | } 22 | 23 | int main() { 24 | pipe(fds); 25 | pthread_t t[2]; 26 | pthread_create(&t[0], NULL, Thread1, NULL); 27 | pthread_create(&t[1], NULL, Thread2, NULL); 28 | pthread_join(t[0], NULL); 29 | pthread_join(t[1], NULL); 30 | printf("OK\n"); 31 | } 32 | 33 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 34 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/free_race.c.supp: -------------------------------------------------------------------------------- 1 | # Suppression for a use-after-free in free_race.c 2 | race:^Thread2$ 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/free_race2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | 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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/halt_on_error.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int X; 6 | 7 | void *Thread(void *x) { 8 | X = 42; 9 | return 0; 10 | } 11 | 12 | int main() { 13 | fprintf(stderr, "BEFORE\n"); 14 | pthread_t t; 15 | pthread_create(&t, 0, Thread, 0); 16 | X = 43; 17 | pthread_join(t, 0); 18 | fprintf(stderr, "AFTER\n"); 19 | return 0; 20 | } 21 | 22 | // CHECK: BEFORE 23 | // CHECK: WARNING: ThreadSanitizer: data race 24 | // CHECK-NOT: AFTER 25 | 26 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/heap_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | void *Thread(void *a) { 7 | ((int*)a)[0]++; 8 | return NULL; 9 | } 10 | 11 | int main() { 12 | int *p = new int(42); 13 | pthread_t t; 14 | pthread_create(&t, NULL, Thread, p); 15 | p[0]++; 16 | pthread_join(t, NULL); 17 | delete p; 18 | } 19 | 20 | // CHECK: WARNING: ThreadSanitizer: data race 21 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/ignore_lib0.cc.supp: -------------------------------------------------------------------------------- 1 | called_from_lib:/libignore_lib0.so 2 | 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/ignore_lib1.cc.supp: -------------------------------------------------------------------------------- 1 | called_from_lib:/libignore_lib1.so$ 2 | 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/ignore_lib2.cc.supp: -------------------------------------------------------------------------------- 1 | called_from_lib:ignore_lib2 2 | 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/ignore_lib3.cc.supp: -------------------------------------------------------------------------------- 1 | called_from_lib:ignore_lib3.so 2 | 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/ignore_sync.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | extern "C" void AnnotateIgnoreSyncBegin(const char*, int); 6 | extern "C" void AnnotateIgnoreSyncEnd(const char*, int); 7 | 8 | int Global; 9 | pthread_mutex_t Mutex = PTHREAD_MUTEX_INITIALIZER; 10 | 11 | void *Thread(void *x) { 12 | AnnotateIgnoreSyncBegin(0, 0); 13 | pthread_mutex_lock(&Mutex); 14 | Global++; 15 | pthread_mutex_unlock(&Mutex); 16 | AnnotateIgnoreSyncEnd(0, 0); 17 | return 0; 18 | } 19 | 20 | int main() { 21 | pthread_t t; 22 | pthread_create(&t, 0, Thread, 0); 23 | pthread_mutex_lock(&Mutex); 24 | Global++; 25 | pthread_mutex_unlock(&Mutex); 26 | pthread_join(t, 0); 27 | } 28 | 29 | // CHECK: WARNING: ThreadSanitizer: data race 30 | 31 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/interface_atomic_test.c: -------------------------------------------------------------------------------- 1 | // Test that we can include header with TSan atomic interface. 2 | // RUN: %clang_tsan %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/java.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | extern "C" { 7 | typedef unsigned long jptr; // NOLINT 8 | void __tsan_java_preinit(const char *libjvm_path); 9 | void __tsan_java_init(jptr heap_begin, jptr heap_size); 10 | int __tsan_java_fini(); 11 | void __tsan_java_alloc(jptr ptr, jptr size); 12 | void __tsan_java_free(jptr ptr, jptr size); 13 | void __tsan_java_move(jptr src, jptr dst, jptr size); 14 | void __tsan_java_mutex_lock(jptr addr); 15 | void __tsan_java_mutex_unlock(jptr addr); 16 | void __tsan_java_mutex_read_lock(jptr addr); 17 | void __tsan_java_mutex_read_unlock(jptr addr); 18 | void __tsan_java_mutex_lock_rec(jptr addr, int rec); 19 | int __tsan_java_mutex_unlock_rec(jptr addr); 20 | } 21 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/java_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include "java.h" 3 | 4 | void *Thread(void *p) { 5 | *(int*)p = 42; 6 | return 0; 7 | } 8 | 9 | int main() { 10 | int const kHeapSize = 1024 * 1024; 11 | void *jheap = malloc(kHeapSize); 12 | __tsan_java_init((jptr)jheap, kHeapSize); 13 | const int kBlockSize = 16; 14 | __tsan_java_alloc((jptr)jheap, kBlockSize); 15 | pthread_t th; 16 | pthread_create(&th, 0, Thread, jheap); 17 | *(int*)jheap = 43; 18 | pthread_join(th, 0); 19 | __tsan_java_free((jptr)jheap, kBlockSize); 20 | return __tsan_java_fini(); 21 | } 22 | 23 | // CHECK: WARNING: ThreadSanitizer: data race 24 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/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@/lib/lit.common.configured") 6 | 7 | # Load tool-specific config that would do the real work. 8 | lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg") 9 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/longjmp.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int foo(jmp_buf env) { 7 | longjmp(env, 42); 8 | } 9 | 10 | int main() { 11 | jmp_buf env; 12 | if (setjmp(env) == 42) { 13 | printf("JUMPED\n"); 14 | return 0; 15 | } 16 | foo(env); 17 | printf("FAILED\n"); 18 | return 0; 19 | } 20 | 21 | // CHECK-NOT: FAILED 22 | // CHECK: JUMPED 23 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/longjmp2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int foo(sigjmp_buf env) { 7 | printf("env=%p\n", env); 8 | siglongjmp(env, 42); 9 | } 10 | 11 | int main() { 12 | sigjmp_buf env; 13 | printf("env=%p\n", env); 14 | if (sigsetjmp(env, 1) == 42) { 15 | printf("JUMPED\n"); 16 | return 0; 17 | } 18 | foo(env); 19 | printf("FAILED\n"); 20 | return 0; 21 | } 22 | 23 | // CHECK-NOT: FAILED 24 | // CHECK: JUMPED 25 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/malloc_overflow.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t 2 | // RUN: TSAN_OPTIONS=allocator_may_return_null=1 %t 2>&1 | FileCheck %s 3 | #include 4 | #include 5 | 6 | int main() { 7 | void *p = malloc((size_t)-1); 8 | if (p != 0) 9 | printf("FAIL malloc(-1) = %p\n", p); 10 | p = malloc((size_t)-1 / 2); 11 | if (p != 0) 12 | printf("FAIL malloc(-1/2) = %p\n", p); 13 | p = calloc((size_t)-1, (size_t)-1); 14 | if (p != 0) 15 | printf("FAIL calloc(-1, -1) = %p\n", p); 16 | p = calloc((size_t)-1 / 2, (size_t)-1 / 2); 17 | if (p != 0) 18 | printf("FAIL calloc(-1/2, -1/2) = %p\n", p); 19 | printf("OK\n"); 20 | } 21 | 22 | // CHECK-NOT: FAIL 23 | // CHECK-NOT: failed to allocate 24 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/malloc_stack.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | _Atomic(int*) p; 6 | 7 | void *thr(void *a) { 8 | sleep(1); 9 | int *pp = __c11_atomic_load(&p, __ATOMIC_RELAXED); 10 | *pp = 42; 11 | return 0; 12 | } 13 | 14 | int main() { 15 | pthread_t th; 16 | pthread_create(&th, 0, thr, p); 17 | __c11_atomic_store(&p, new int, __ATOMIC_RELAXED); 18 | pthread_join(th, 0); 19 | } 20 | 21 | // CHECK: data race 22 | // CHECK: Previous write 23 | // CHECK: #0 operator new 24 | // CHECK: Location is heap block 25 | // CHECK: #0 operator new 26 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/mutex_destroy_locked.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int main() { 6 | pthread_mutex_t m; 7 | pthread_mutex_init(&m, 0); 8 | pthread_mutex_lock(&m); 9 | pthread_mutex_destroy(&m); 10 | return 0; 11 | } 12 | 13 | // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex 14 | // CHECK: #0 pthread_mutex_destroy 15 | // CHECK: #1 main 16 | // CHECK: and: 17 | // CHECK: #0 pthread_mutex_lock 18 | // CHECK: #1 main 19 | // CHECK: Mutex {{.*}} created at: 20 | // CHECK: #0 pthread_mutex_init 21 | // CHECK: #1 main 22 | // CHECK: SUMMARY: ThreadSanitizer: destroy of a locked mutex{{.*}}main 23 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/oob_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | const long kOffset = 64*1024; 7 | 8 | void *Thread(void *p) { 9 | sleep(1); 10 | ((char*)p)[-kOffset] = 43; 11 | return 0; 12 | } 13 | 14 | int main() { 15 | char *volatile p0 = new char[16]; 16 | delete[] p0; 17 | char *p = new char[32]; 18 | pthread_t th; 19 | pthread_create(&th, 0, Thread, p); 20 | p[-kOffset] = 42; 21 | pthread_join(th, 0); 22 | } 23 | 24 | // Used to crash with CHECK failed. 25 | // CHECK: WARNING: ThreadSanitizer: data race 26 | 27 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/printf-1.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O2 %s -o %t 2 | // RUN: ASAN_OPTIONS=check_printf=1 %t 2>&1 | FileCheck %s 3 | // RUN: ASAN_OPTIONS=check_printf=0 %t 2>&1 | FileCheck %s 4 | // 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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/race_on_barrier.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | pthread_barrier_t B; 8 | int Global; 9 | 10 | void *Thread1(void *x) { 11 | pthread_barrier_init(&B, 0, 2); 12 | pthread_barrier_wait(&B); 13 | return NULL; 14 | } 15 | 16 | void *Thread2(void *x) { 17 | sleep(1); 18 | pthread_barrier_wait(&B); 19 | return NULL; 20 | } 21 | 22 | int main() { 23 | pthread_t t; 24 | pthread_create(&t, NULL, Thread1, NULL); 25 | Thread2(0); 26 | pthread_join(t, NULL); 27 | pthread_barrier_destroy(&B); 28 | return 0; 29 | } 30 | 31 | // CHECK: WARNING: ThreadSanitizer: data race 32 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/race_on_barrier2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | pthread_barrier_t B; 8 | int Global; 9 | 10 | void *Thread1(void *x) { 11 | if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD) 12 | pthread_barrier_destroy(&B); 13 | return NULL; 14 | } 15 | 16 | void *Thread2(void *x) { 17 | if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD) 18 | pthread_barrier_destroy(&B); 19 | return NULL; 20 | } 21 | 22 | int main() { 23 | pthread_barrier_init(&B, 0, 2); 24 | pthread_t t; 25 | pthread_create(&t, NULL, Thread1, NULL); 26 | Thread2(0); 27 | pthread_join(t, NULL); 28 | return 0; 29 | } 30 | 31 | // CHECK: WARNING: ThreadSanitizer: data race 32 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/race_on_mutex2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void *Thread(void *x) { 8 | pthread_mutex_lock((pthread_mutex_t*)x); 9 | pthread_mutex_unlock((pthread_mutex_t*)x); 10 | return 0; 11 | } 12 | 13 | int main() { 14 | pthread_mutex_t Mtx; 15 | pthread_mutex_init(&Mtx, 0); 16 | pthread_t t; 17 | pthread_create(&t, 0, Thread, &Mtx); 18 | sleep(1); 19 | pthread_mutex_destroy(&Mtx); 20 | pthread_join(t, 0); 21 | return 0; 22 | } 23 | 24 | // CHECK: WARNING: ThreadSanitizer: data race 25 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/race_on_speculative_load.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %t | FileCheck %s 2 | // Regtest for https://code.google.com/p/thread-sanitizer/issues/detail?id=40 3 | // This is a correct program and tsan should not report a race. 4 | #include 5 | #include 6 | #include 7 | int g; 8 | __attribute__((noinline)) 9 | int foo(int cond) { 10 | if (cond) 11 | return g; 12 | return 0; 13 | } 14 | void *Thread1(void *p) { 15 | long res = foo((long)p); 16 | sleep(1); 17 | return (void*) res; 18 | } 19 | 20 | int main() { 21 | pthread_t t; 22 | pthread_create(&t, 0, Thread1, 0); 23 | g = 1; 24 | pthread_join(t, 0); 25 | printf("PASS\n"); 26 | // CHECK: PASS 27 | } 28 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/simple_race.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int Global; 6 | 7 | void *Thread1(void *x) { 8 | Global = 42; 9 | return NULL; 10 | } 11 | 12 | void *Thread2(void *x) { 13 | Global = 43; 14 | return NULL; 15 | } 16 | 17 | int main() { 18 | pthread_t t[2]; 19 | pthread_create(&t[0], NULL, Thread1, NULL); 20 | pthread_create(&t[1], NULL, Thread2, NULL); 21 | pthread_join(t[0], NULL); 22 | pthread_join(t[1], NULL); 23 | return 0; 24 | } 25 | 26 | // CHECK: WARNING: ThreadSanitizer: data race 27 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/simple_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int Global; 6 | 7 | void *Thread1(void *x) { 8 | Global++; 9 | return NULL; 10 | } 11 | 12 | void *Thread2(void *x) { 13 | Global--; 14 | return NULL; 15 | } 16 | 17 | int main() { 18 | pthread_t t[2]; 19 | pthread_create(&t[0], NULL, Thread1, NULL); 20 | pthread_create(&t[1], NULL, Thread2, NULL); 21 | pthread_join(t[0], NULL); 22 | pthread_join(t[1], NULL); 23 | } 24 | 25 | // CHECK: WARNING: ThreadSanitizer: data race 26 | // CHECK: SUMMARY: ThreadSanitizer: data race{{.*}}Thread 27 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/sleep_sync.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int X = 0; 6 | 7 | void MySleep() { 8 | sleep(1); 9 | } 10 | 11 | void *Thread(void *p) { 12 | MySleep(); // Assume the main thread has done the write. 13 | X = 42; 14 | return 0; 15 | } 16 | 17 | int main() { 18 | pthread_t t; 19 | pthread_create(&t, 0, Thread, 0); 20 | X = 43; 21 | pthread_join(t, 0); 22 | return 0; 23 | } 24 | 25 | // CHECK: WARNING: ThreadSanitizer: data race 26 | // ... 27 | // CHECK: As if synchronized via sleep: 28 | // CHECK-NEXT: #0 sleep 29 | // CHECK-NEXT: #1 MySleep 30 | // CHECK-NEXT: #2 Thread 31 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/sleep_sync2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int X = 0; 6 | 7 | void *Thread(void *p) { 8 | X = 42; 9 | return 0; 10 | } 11 | 12 | int main() { 13 | pthread_t t; 14 | sleep(1); 15 | pthread_create(&t, 0, Thread, 0); 16 | X = 43; 17 | pthread_join(t, 0); 18 | return 0; 19 | } 20 | 21 | // CHECK: WARNING: ThreadSanitizer: data race 22 | // CHECK-NOT: As if synchronized via sleep 23 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/stack_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | void *Thread(void *a) { 7 | sleep(1); 8 | *(int*)a = 43; 9 | return 0; 10 | } 11 | 12 | int main() { 13 | int Var = 42; 14 | pthread_t t; 15 | pthread_create(&t, 0, Thread, &Var); 16 | Var = 43; 17 | pthread_join(t, 0); 18 | } 19 | 20 | // CHECK: WARNING: ThreadSanitizer: data race 21 | // CHECK: Location is stack of main thread. 22 | 23 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/stack_race2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | void *Thread2(void *a) { 7 | sleep(1); 8 | *(int*)a = 43; 9 | return 0; 10 | } 11 | 12 | void *Thread(void *a) { 13 | int Var = 42; 14 | pthread_t t; 15 | pthread_create(&t, 0, Thread2, &Var); 16 | Var = 42; 17 | pthread_join(t, 0); 18 | return 0; 19 | } 20 | 21 | int main() { 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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/static_init1.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/static_init2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | struct Cache { 7 | int x; 8 | explicit Cache(int x) 9 | : x(x) { 10 | } 11 | }; 12 | 13 | void foo(Cache *my) { 14 | static Cache *c = my ? my : new Cache(rand()); 15 | if (c->x >= RAND_MAX) 16 | exit(1); 17 | } 18 | 19 | void *Thread(void *x) { 20 | foo(new Cache(rand())); 21 | return 0; 22 | } 23 | 24 | int main() { 25 | pthread_t t[2]; 26 | pthread_create(&t[0], 0, Thread, 0); 27 | pthread_create(&t[1], 0, Thread, 0); 28 | pthread_join(t[0], 0); 29 | pthread_join(t[1], 0); 30 | printf("PASS\n"); 31 | } 32 | 33 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 34 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/static_init4.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | struct Cache { 8 | int x; 9 | explicit Cache(int x) 10 | : x(x) { 11 | } 12 | }; 13 | 14 | int g_other; 15 | 16 | Cache *CreateCache() { 17 | g_other = rand(); 18 | return new Cache(rand()); 19 | } 20 | 21 | void *Thread1(void *x) { 22 | static Cache *c = CreateCache(); 23 | if (c->x == g_other) 24 | exit(1); 25 | return 0; 26 | } 27 | 28 | int main() { 29 | pthread_t t[2]; 30 | pthread_create(&t[0], 0, Thread1, 0); 31 | pthread_create(&t[1], 0, Thread1, 0); 32 | pthread_join(t[0], 0); 33 | pthread_join(t[1], 0); 34 | printf("PASS\n"); 35 | } 36 | 37 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 38 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/suppress_same_address.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | volatile int X; 6 | 7 | void *Thread1(void *x) { 8 | sleep(1); 9 | X = 42; 10 | X = 66; 11 | X = 78; 12 | return 0; 13 | } 14 | 15 | void *Thread2(void *x) { 16 | X = 11; 17 | X = 99; 18 | X = 73; 19 | return 0; 20 | } 21 | 22 | int main() { 23 | pthread_t t; 24 | pthread_create(&t, 0, Thread1, 0); 25 | Thread2(0); 26 | pthread_join(t, 0); 27 | } 28 | 29 | // CHECK: ThreadSanitizer: reported 1 warnings 30 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/suppress_same_stacks.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | 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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/suppressions_global.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int RacyGlobal; 6 | 7 | void *Thread1(void *x) { 8 | RacyGlobal = 42; 9 | return NULL; 10 | } 11 | 12 | void *Thread2(void *x) { 13 | RacyGlobal = 43; 14 | return NULL; 15 | } 16 | 17 | int main() { 18 | pthread_t t[2]; 19 | pthread_create(&t[0], NULL, Thread1, NULL); 20 | pthread_create(&t[1], NULL, Thread2, NULL); 21 | pthread_join(t[0], NULL); 22 | pthread_join(t[1], NULL); 23 | printf("OK\n"); 24 | return 0; 25 | } 26 | 27 | // CHECK-NOT: failed to open suppressions file 28 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 29 | 30 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/suppressions_global.cc.supp: -------------------------------------------------------------------------------- 1 | race:RacyGlobal 2 | 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/suppressions_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int Global; 7 | 8 | void *Thread1(void *x) { 9 | sleep(1); 10 | Global = 42; 11 | return NULL; 12 | } 13 | 14 | void *Thread2(void *x) { 15 | Global = 43; 16 | return NULL; 17 | } 18 | 19 | int main() { 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 | printf("OK\n"); 26 | return 0; 27 | } 28 | 29 | // CHECK-NOT: failed to open suppressions file 30 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 31 | 32 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/suppressions_race.cc.supp: -------------------------------------------------------------------------------- 1 | race:Thread1 2 | 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/suppressions_race2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int Global; 7 | 8 | void *Thread1(void *x) { 9 | Global = 42; 10 | return NULL; 11 | } 12 | 13 | void *Thread2(void *x) { 14 | sleep(1); 15 | Global = 43; 16 | return NULL; 17 | } 18 | 19 | int main() { 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 | printf("OK\n"); 26 | return 0; 27 | } 28 | 29 | // CHECK-NOT: failed to open suppressions file 30 | // CHECK-NOT: WARNING: ThreadSanitizer: data race 31 | 32 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/suppressions_race2.cc.supp: -------------------------------------------------------------------------------- 1 | race:Thread2 2 | 3 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/thread_end_with_ignore.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | 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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/thread_end_with_ignore2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | 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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/thread_leak.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/thread_leak2.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/thread_leak3.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %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 | sleep(1); 13 | return 0; 14 | } 15 | 16 | // CHECK: WARNING: ThreadSanitizer: thread leak 17 | // CHECK: SUMMARY: ThreadSanitizer: thread leak{{.*}}main 18 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/thread_leak4.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | void *Thread(void *x) { 7 | sleep(10); 8 | return 0; 9 | } 10 | 11 | int main() { 12 | pthread_t t; 13 | pthread_create(&t, 0, Thread, 0); 14 | printf("OK\n"); 15 | return 0; 16 | } 17 | 18 | // CHECK-NOT: WARNING: ThreadSanitizer: thread leak 19 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/thread_leak5.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | void *Thread(void *x) { 6 | return 0; 7 | } 8 | 9 | int main() { 10 | volatile int N = 5; // prevent loop unrolling 11 | for (int i = 0; i < N; i++) { 12 | pthread_t t; 13 | pthread_create(&t, 0, Thread, 0); 14 | } 15 | sleep(1); 16 | return 0; 17 | } 18 | 19 | // CHECK: WARNING: ThreadSanitizer: thread leak 20 | // CHECK: And 4 more similar thread leaks 21 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/thread_name2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | int Global; 7 | 8 | void *Thread1(void *x) { 9 | sleep(1); 10 | Global++; 11 | return 0; 12 | } 13 | 14 | void *Thread2(void *x) { 15 | pthread_setname_np(pthread_self(), "foobar2"); 16 | Global--; 17 | return 0; 18 | } 19 | 20 | int main() { 21 | pthread_t t[2]; 22 | pthread_create(&t[0], 0, Thread1, 0); 23 | pthread_create(&t[1], 0, Thread2, 0); 24 | pthread_setname_np(t[0], "foobar1"); 25 | pthread_join(t[0], NULL); 26 | pthread_join(t[1], NULL); 27 | } 28 | 29 | // CHECK: WARNING: ThreadSanitizer: data race 30 | // CHECK: Thread T1 'foobar1' 31 | // CHECK: Thread T2 'foobar2' 32 | 33 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/tiny_race.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | 5 | int Global; 6 | 7 | void *Thread1(void *x) { 8 | sleep(1); 9 | Global = 42; 10 | return x; 11 | } 12 | 13 | int main() { 14 | pthread_t t; 15 | pthread_create(&t, 0, Thread1, 0); 16 | Global = 43; 17 | pthread_join(t, 0); 18 | return Global; 19 | } 20 | 21 | // CHECK: WARNING: ThreadSanitizer: data race 22 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/tls_race.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | void *Thread(void *a) { 7 | sleep(1); 8 | *(int*)a = 43; 9 | return 0; 10 | } 11 | 12 | int main() { 13 | static __thread int Var = 42; 14 | pthread_t t; 15 | pthread_create(&t, 0, Thread, &Var); 16 | Var = 43; 17 | pthread_join(t, 0); 18 | } 19 | 20 | // CHECK: WARNING: ThreadSanitizer: data race 21 | // CHECK: Location is TLS of main thread. 22 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/tls_race2.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 | #include 3 | #include 4 | #include 5 | 6 | void *Thread2(void *a) { 7 | sleep(1); 8 | *(int*)a = 43; 9 | return 0; 10 | } 11 | 12 | void *Thread(void *a) { 13 | static __thread int Var = 42; 14 | pthread_t t; 15 | pthread_create(&t, 0, Thread2, &Var); 16 | Var = 42; 17 | pthread_join(t, 0); 18 | return 0; 19 | } 20 | 21 | int main() { 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 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/user_malloc.cc: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 | #include 3 | 4 | // defined by tsan. 5 | extern "C" void *__interceptor_malloc(unsigned long size); 6 | extern "C" void __interceptor_free(void *p); 7 | 8 | extern "C" void *malloc(unsigned long size) { 9 | static int first = 0; 10 | if (__sync_lock_test_and_set(&first, 1) == 0) 11 | printf("user malloc\n"); 12 | return __interceptor_malloc(size); 13 | } 14 | 15 | extern "C" void free(void *p) { 16 | __interceptor_free(p); 17 | } 18 | 19 | int main() { 20 | volatile char *p = (char*)malloc(10); 21 | p[0] = 0; 22 | free((void*)p); 23 | } 24 | 25 | // CHECK: user malloc 26 | // CHECK-NOT: ThreadSanitizer 27 | 28 | -------------------------------------------------------------------------------- /lib/tsan/lit_tests/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 && %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 | -------------------------------------------------------------------------------- /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 | Annotate* 12 | WTFAnnotate* 13 | RunningOnValgrind 14 | ValgrindSlowdown 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/tsan/tests/unit/tsan_unit_test_main.cc: -------------------------------------------------------------------------------- 1 | //===-- tsan_unit_test_main.cc --------------------------------------------===// 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 ThreadSanitizer (TSan), a race detector. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | #include "gtest/gtest.h" 14 | 15 | int main(int argc, char **argv) { 16 | testing::GTEST_FLAG(death_test_style) = "threadsafe"; 17 | testing::InitGoogleTest(&argc, argv); 18 | return RUN_ALL_TESTS(); 19 | } 20 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/AsanConfig/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured") 3 | 4 | # Tool-specific config options. 5 | config.ubsan_lit_tests_dir = "@UBSAN_LIT_TESTS_DIR@" 6 | 7 | # Load tool-specific config that would do the real work. 8 | print config.ubsan_lit_tests_dir 9 | lit_config.load_config(config, "@UBSAN_LIT_TESTS_DIR@/AsanConfig/lit.cfg") 10 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Integer/div-overflow.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Integer/div-zero.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND=0 %s -o %t && %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND=1U %s -o %t && %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx -fsanitize=float-divide-by-zero -DDIVIDEND=1.5 %s -o %t && %t 2>&1 | FileCheck %s 4 | // RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND='intmax(123)' %s -o %t && %t 2>&1 | FileCheck %s 5 | 6 | #ifdef __SIZEOF_INT128__ 7 | typedef __int128 intmax; 8 | #else 9 | typedef long long intmax; 10 | #endif 11 | 12 | int main() { 13 | // CHECK: div-zero.cpp:[[@LINE+1]]:12: runtime error: division by zero 14 | DIVIDEND / 0; 15 | } 16 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Integer/incdec-overflow.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -DOP=n++ -fsanitize=signed-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s 2 | // RUN: %clangxx -DOP=++n -fsanitize=signed-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s 3 | // RUN: %clangxx -DOP=m-- -fsanitize=signed-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s 4 | // RUN: %clangxx -DOP=--m -fsanitize=signed-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s 5 | 6 | #include 7 | 8 | int main() { 9 | int n = 0x7ffffffd; 10 | n++; 11 | n++; 12 | int m = -n - 1; 13 | // CHECK: incdec-overflow.cpp:15:3: runtime error: signed integer overflow: [[MINUS:-?]]214748364 14 | // CHECK: + [[MINUS]]1 cannot be represented in type 'int' 15 | OP; 16 | } 17 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Integer/mul-overflow.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %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 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Integer/negate-overflow.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECKS 2 | // RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECKU 3 | 4 | int main() { 5 | // CHECKS-NOT: runtime error 6 | // CHECKU: negate-overflow.cpp:[[@LINE+2]]:3: runtime error: negation of 2147483648 cannot be represented in type 'unsigned int' 7 | // CHECKU-NOT: cast to an unsigned 8 | -unsigned(-0x7fffffff - 1); // ok 9 | // CHECKS: negate-overflow.cpp:[[@LINE+2]]:10: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself 10 | // CHECKU-NOT: runtime error 11 | return -(-0x7fffffff - 1); 12 | } 13 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Integer/umul-overflow.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %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 | // Not an unsigned overflow 13 | (void)(uint16_t(0xffff) * uint16_t(0x8001)); 14 | 15 | (void)(uint32_t(0xffffffff) * uint32_t(0x2)); 16 | // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int' 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Misc/bool.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=bool %s -O3 -o %T/bool.exe && %T/bool.exe 2>&1 | FileCheck %s 2 | 3 | unsigned char NotABool = 123; 4 | 5 | int main(int argc, char **argv) { 6 | bool *p = (bool*)&NotABool; 7 | 8 | // CHECK: bool.cpp:9:10: runtime error: load of value 123, which is not a valid value for type 'bool' 9 | return *p; 10 | } 11 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Misc/bounds.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=bounds %s -O3 -o %T/bounds.exe 2 | // RUN: %T/bounds.exe 0 0 0 3 | // RUN: %T/bounds.exe 1 2 3 4 | // RUN: %T/bounds.exe 2 0 0 2>&1 | FileCheck %s --check-prefix=CHECK-A-2 5 | // RUN: %T/bounds.exe 0 3 0 2>&1 | FileCheck %s --check-prefix=CHECK-B-3 6 | // RUN: %T/bounds.exe 0 0 4 2>&1 | FileCheck %s --check-prefix=CHECK-C-4 7 | 8 | int main(int argc, char **argv) { 9 | int arr[2][3][4] = {}; 10 | 11 | return arr[argv[1][0] - '0'][argv[2][0] - '0'][argv[3][0] - '0']; 12 | // CHECK-A-2: bounds.cpp:11:10: runtime error: index 2 out of bounds for type 'int [2][3][4]' 13 | // CHECK-B-3: bounds.cpp:11:10: runtime error: index 3 out of bounds for type 'int [3][4]' 14 | // CHECK-C-4: bounds.cpp:11:10: runtime error: index 4 out of bounds for type 'int [4]' 15 | } 16 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Misc/deduplication.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=undefined %s -o %t && %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 | 15 | // CHECK: runtime error 16 | // CHECK-NOT: runtime error 17 | // CHECK-NOT: runtime error 18 | overflow(); 19 | overflow(); 20 | overflow(); 21 | 22 | // CHECK: End 23 | fprintf(stderr, "End\n"); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Misc/missing_return.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=return %s -O3 -o %t && %t 2>&1 | FileCheck %s 2 | 3 | // CHECK: missing_return.cpp:4:5: runtime error: execution reached the end of a value-returning function without returning a value 4 | int f() { 5 | } 6 | 7 | int main(int, char **argv) { 8 | return f(); 9 | } 10 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Misc/unreachable.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=unreachable %s -O3 -o %t && %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 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/Misc/vla.c: -------------------------------------------------------------------------------- 1 | // RUN: %clang -fsanitize=vla-bound %s -O3 -o %t 2 | // RUN: %t 2>&1 | FileCheck %s --check-prefix=CHECK-MINUS-ONE 3 | // RUN: %t a 2>&1 | FileCheck %s --check-prefix=CHECK-ZERO 4 | // 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 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/TestCases/TypeCheck/Function/function.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %clangxx -fsanitize=function %s -O3 -g -o %t 2 | // RUN: %t 2>&1 | FileCheck %s 3 | 4 | #include 5 | 6 | void f() {} 7 | 8 | void g(int x) {} 9 | 10 | int main(void) { 11 | // CHECK: runtime error: call to function f() through pointer to incorrect function type 'void (*)(int)' 12 | // CHECK-NEXT: function.cpp:6: note: f() defined here 13 | reinterpret_cast(reinterpret_cast(f))(42); 14 | 15 | // CHECK-NOT: runtime error: call to function g 16 | reinterpret_cast(reinterpret_cast(g))(42); 17 | } 18 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/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 | -------------------------------------------------------------------------------- /lib/ubsan/lit_tests/UbsanConfig/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | # Load common config for all compiler-rt lit tests. 2 | lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/lib/lit.common.configured") 3 | 4 | # Tool-specific config options. 5 | config.ubsan_lit_tests_dir = "@UBSAN_LIT_TESTS_DIR@" 6 | 7 | # Load tool-specific config that would do the real work. 8 | lit_config.load_config(config, "@UBSAN_LIT_TESTS_DIR@/UbsanConfig/lit.cfg") 9 | -------------------------------------------------------------------------------- /lib/ubsan/ubsan.syms.extra: -------------------------------------------------------------------------------- 1 | __ubsan_* 2 | -------------------------------------------------------------------------------- /lib/udivdi3.c: -------------------------------------------------------------------------------- 1 | /* ===-- udivdi3.c - Implement __udivdi3 -----------------------------------=== 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 __udivdi3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | du_int COMPILER_RT_ABI __udivmoddi4(du_int a, du_int b, du_int* rem); 18 | 19 | /* Returns: a / b */ 20 | 21 | COMPILER_RT_ABI du_int 22 | __udivdi3(du_int a, du_int b) 23 | { 24 | return __udivmoddi4(a, b, 0); 25 | } 26 | -------------------------------------------------------------------------------- /lib/udivti3.c: -------------------------------------------------------------------------------- 1 | /* ===-- udivti3.c - Implement __udivti3 -----------------------------------=== 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 __udivti3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | #if __x86_64 18 | 19 | tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); 20 | 21 | /* Returns: a / b */ 22 | 23 | tu_int 24 | __udivti3(tu_int a, tu_int b) 25 | { 26 | return __udivmodti4(a, b, 0); 27 | } 28 | 29 | #endif /* __x86_64 */ 30 | -------------------------------------------------------------------------------- /lib/umoddi3.c: -------------------------------------------------------------------------------- 1 | /* ===-- umoddi3.c - Implement __umoddi3 -----------------------------------=== 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 __umoddi3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | du_int COMPILER_RT_ABI __udivmoddi4(du_int a, du_int b, du_int* rem); 18 | 19 | /* Returns: a % b */ 20 | 21 | COMPILER_RT_ABI du_int 22 | __umoddi3(du_int a, du_int b) 23 | { 24 | du_int r; 25 | __udivmoddi4(a, b, &r); 26 | return r; 27 | } 28 | -------------------------------------------------------------------------------- /lib/umodsi3.c: -------------------------------------------------------------------------------- 1 | /* ===-- umodsi3.c - Implement __umodsi3 -----------------------------------=== 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 __umodsi3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: a % b */ 18 | 19 | su_int COMPILER_RT_ABI __udivsi3(su_int a, su_int b); 20 | 21 | COMPILER_RT_ABI su_int 22 | __umodsi3(su_int a, su_int b) 23 | { 24 | return a - __udivsi3(a, b) * b; 25 | } 26 | -------------------------------------------------------------------------------- /lib/x86_64/Makefile.mk: -------------------------------------------------------------------------------- 1 | #===- lib/x86_64/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 := builtins 11 | SubDirs := 12 | OnlyArchs := x86_64 x86_64h 13 | 14 | AsmSources := $(foreach file,$(wildcard $(Dir)/*.S),$(notdir $(file))) 15 | Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file))) 16 | ObjNames := $(Sources:%.c=%.o) $(AsmSources:%.S=%.o) 17 | Implementation := Optimized 18 | 19 | # FIXME: use automatic dependencies? 20 | Dependencies := $(wildcard lib/*.h $(Dir)/*.h) 21 | -------------------------------------------------------------------------------- /lib/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/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 | -------------------------------------------------------------------------------- /lib/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 | -------------------------------------------------------------------------------- /lib/x86_64/floatundisf.S: -------------------------------------------------------------------------------- 1 | // This file is dual licensed under the MIT and the University of Illinois Open 2 | // Source Licenses. See LICENSE.TXT for details. 3 | 4 | #include "../assembly.h" 5 | 6 | // float __floatundisf(du_int a); 7 | 8 | #ifdef __x86_64__ 9 | 10 | #ifndef __ELF__ 11 | .literal4 12 | #endif 13 | two: .single 2.0 14 | 15 | #define REL_ADDR(_a) (_a)(%rip) 16 | 17 | .text 18 | .align 4 19 | DEFINE_COMPILERRT_FUNCTION(__floatundisf) 20 | movq $1, %rsi 21 | testq %rdi, %rdi 22 | js 1f 23 | cvtsi2ssq %rdi, %xmm0 24 | ret 25 | 26 | 1: andq %rdi, %rsi 27 | shrq %rdi 28 | orq %rsi, %rdi 29 | cvtsi2ssq %rdi, %xmm0 30 | mulss REL_ADDR(two), %xmm0 31 | ret 32 | END_COMPILERRT_FUNCTION(__floatundisf) 33 | 34 | #endif // __x86_64__ 35 | -------------------------------------------------------------------------------- /make/filter-inputs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #===- make/filter-inputs ---------------------------------------------------===# 4 | # 5 | # The LLVM Compiler Infrastructure 6 | # 7 | # This file is distributed under the University of Illinois Open Source 8 | # License. See LICENSE.TXT for details. 9 | # 10 | #===------------------------------------------------------------------------===# 11 | 12 | # Given a list of files, return a new list of files taking only the 13 | # first file for any particular filename. 14 | def main(): 15 | import os,sys 16 | 17 | seen = set() 18 | for file in sys.argv[1:]: 19 | base = os.path.basename(file) 20 | if base not in seen: 21 | seen.add(base) 22 | print file 23 | 24 | if __name__ == '__main__': 25 | main() 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /make/platform/clang_macho_embedded_test_input.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rust-lang/compiler-rt/46081ede32546303dedf23dcb5f4c5ba429582d0/make/platform/clang_macho_embedded_test_input.c -------------------------------------------------------------------------------- /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/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/Unit/ppc/floatditf_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | long double __floatditf(int64_t); 5 | 6 | #include "floatunditf_test.h" 7 | #include "DD.h" 8 | 9 | int main(int argc, char *argv[]) { 10 | int i; 11 | 12 | DD expected; 13 | DD computed; 14 | 15 | for (i=0; i 2 | #include 3 | 4 | long double __floatunditf(uint64_t); 5 | 6 | #include "floatunditf_test.h" 7 | #include "DD.h" 8 | 9 | int main(int argc, char *argv[]) { 10 | int i; 11 | 12 | DD expected; 13 | DD computed; 14 | 15 | for (i=0; i 2 | #include 3 | #include 4 | 5 | double intervalInCycles( uint64_t startTime, uint64_t endTime ) 6 | { 7 | uint64_t rawTime = endTime - startTime; 8 | static double conversion = 0.0; 9 | 10 | if( 0.0 == conversion ) 11 | { 12 | mach_timebase_info_data_t info; 13 | kern_return_t err = mach_timebase_info( &info ); 14 | if( 0 != err ) 15 | return 0; 16 | 17 | uint64_t freq = 0; 18 | size_t freqSize = sizeof( freq ); 19 | int err2 = sysctlbyname( "hw.cpufrequency", &freq, &freqSize, NULL, 0L ); 20 | if( 0 != err2 ) 21 | return 0; 22 | 23 | conversion = (double) freq * (1e-9 * (double) info.numer / (double) info.denom); 24 | } 25 | 26 | return (double) rawTime * conversion; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /www/menu.css: -------------------------------------------------------------------------------- 1 | /***************/ 2 | /* page layout */ 3 | /***************/ 4 | 5 | [id=menu] { 6 | position:fixed; 7 | width:25ex; 8 | } 9 | [id=content] { 10 | /* ***** EDIT THIS VALUE IF CONTENT OVERLAPS MENU ***** */ 11 | position:absolute; 12 | left:29ex; 13 | padding-right:4ex; 14 | } 15 | 16 | /**************/ 17 | /* menu style */ 18 | /**************/ 19 | 20 | #menu .submenu { 21 | padding-top:1em; 22 | display:block; 23 | } 24 | 25 | #menu label { 26 | display:block; 27 | font-weight: bold; 28 | text-align: center; 29 | background-color: rgb(192,192,192); 30 | } 31 | #menu a { 32 | padding:0 .2em; 33 | display:block; 34 | text-align: center; 35 | background-color: rgb(235,235,235); 36 | } 37 | #menu a:visited { 38 | color:rgb(100,50,100); 39 | } -------------------------------------------------------------------------------- /www/menu.html.incl: -------------------------------------------------------------------------------- 1 | 20 | --------------------------------------------------------------------------------