Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,19 @@
// Check that sanitizers on OS X crash the process by default (i.e.
// abort_on_error=1). See also Linux/abort_on_error.cc.
// RUN: %clangxx %s -o %t
// Intentionally don't inherit the default options.
// RUN: env %tool_options='' not --crash %run %t 2>&1
// When we use lit's default options, we shouldn't crash.
// RUN: not %run %t 2>&1
int global;
int main() {
volatile int *a = new int[100];
delete[] a;
global = a[0]; // use-after-free: triggers ASan report.
return 0;
}

View File

@@ -0,0 +1,9 @@
def getRoot(config):
if not config.parent:
return config
return getRoot(config.parent)
root = getRoot(config)
if root.host_os not in ['Darwin']:
config.unsupported = True

View File

@@ -0,0 +1,19 @@
// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s
// RUN: %env_tool_opts=stack_trace_format='"frame:%n lineno:%l"' %run %t 2>&1 | FileCheck %s --check-prefix=CUSTOM
#include <sanitizer/common_interface_defs.h>
static inline void FooBarBaz() {
__sanitizer_print_stack_trace();
}
int main() {
FooBarBaz();
return 0;
}
// CHECK: {{ #0 0x.* in __sanitizer_print_stack_trace}}
// CHECK: {{ #1 0x.* in FooBarBaz(\(\))? .*}}print-stack-trace.cc:[[@LINE-8]]
// CHECK: {{ #2 0x.* in main.*}}print-stack-trace.cc:[[@LINE-5]]
// CUSTOM: frame:1 lineno:[[@LINE-11]]
// CUSTOM: frame:2 lineno:[[@LINE-8]]

View File

@@ -0,0 +1,23 @@
// Check that sanitizers call _exit() on Linux by default (i.e.
// abort_on_error=0). See also Darwin/abort_on_error.cc.
// RUN: %clangxx %s -o %t
// Intentionally don't inherit the default options.
// RUN: env %tool_options='' not %run %t 2>&1
// When we use lit's default options, we shouldn't crash either. On Linux
// lit doesn't set options anyway.
// RUN: not %run %t 2>&1
// Android needs abort_on_error=0
// UNSUPPORTED: android
namespace __sanitizer {
void Die();
}
int main() {
__sanitizer::Die();
return 0;
}

View File

@@ -0,0 +1,8 @@
// RUN: %clang -std=c11 -O0 %s -o %t && %run %t
#include <stdlib.h>
extern void *aligned_alloc (size_t alignment, size_t size);
int main() {
volatile void *p = aligned_alloc(128, 1024);
free((void*)p);
return 0;
}

View File

@@ -0,0 +1,90 @@
// Regression test for
// https://code.google.com/p/address-sanitizer/issues/detail?id=180
// clang-format off
// RUN: %clangxx -O0 %s -o %t
// RUN: %env_tool_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
// RUN: %env_tool_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
// RUN: %env_tool_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
// RUN: %env_tool_opts=handle_segv=0:allow_user_segv_handler=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
// RUN: %env_tool_opts=handle_segv=1:allow_user_segv_handler=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
// RUN: %env_tool_opts=handle_segv=2:allow_user_segv_handler=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
// RUN: %env_tool_opts=handle_segv=0:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
// RUN: %env_tool_opts=handle_segv=1:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
// RUN: %env_tool_opts=handle_segv=2:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
// clang-format on
// Flaky errors in debuggerd with "waitpid returned unexpected pid (0)" in logcat.
// UNSUPPORTED: android && i386-target-arch
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
struct sigaction original_sigaction_sigbus;
struct sigaction original_sigaction_sigsegv;
void User_OnSIGSEGV(int signum, siginfo_t *siginfo, void *context) {
fprintf(stderr, "User sigaction called\n");
struct sigaction original_sigaction = {};
if (signum == SIGBUS)
original_sigaction = original_sigaction_sigbus;
else if (signum == SIGSEGV)
original_sigaction = original_sigaction_sigsegv;
else {
printf("Invalid signum");
exit(1);
}
if (original_sigaction.sa_flags | SA_SIGINFO) {
if (original_sigaction.sa_sigaction)
original_sigaction.sa_sigaction(signum, siginfo, context);
} else {
if (original_sigaction.sa_handler)
original_sigaction.sa_handler(signum);
}
exit(1);
}
int DoSEGV() {
volatile int *x = 0;
return *x;
}
bool InstallHandler(int signum, struct sigaction *original_sigaction) {
struct sigaction user_sigaction = {};
user_sigaction.sa_sigaction = User_OnSIGSEGV;
user_sigaction.sa_flags = SA_SIGINFO;
if (sigaction(signum, &user_sigaction, original_sigaction)) {
perror("sigaction");
return false;
}
return true;
}
int main() {
// Let's install handlers for both SIGSEGV and SIGBUS, since pre-Yosemite
// 32-bit Darwin triggers SIGBUS instead.
if (InstallHandler(SIGSEGV, &original_sigaction_sigsegv) &&
InstallHandler(SIGBUS, &original_sigaction_sigbus)) {
fprintf(stderr, "User sigaction installed\n");
}
return DoSEGV();
}
// CHECK0-NOT: Sanitizer:DEADLYSIGNAL
// CHECK0-NOT: Sanitizer: SEGV on unknown address
// CHECK0: User sigaction installed
// CHECK0-NEXT: User sigaction called
// CHECK1: User sigaction installed
// CHECK1-NEXT: User sigaction called
// CHECK1-NEXT: Sanitizer:DEADLYSIGNAL
// CHECK1: Sanitizer: SEGV on unknown address
// CHECK2-NOT: User sigaction called
// CHECK2: User sigaction installed
// CHECK2-NEXT: Sanitizer:DEADLYSIGNAL
// CHECK2: Sanitizer: SEGV on unknown address

View File

@@ -0,0 +1,27 @@
// Test the handle_abort option.
// clang-format off
// RUN: %clangxx %s -o %t
// RUN: not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s
// RUN: %env_tool_opts=handle_abort=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s
// RUN: %env_tool_opts=handle_abort=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s
// clang-format on
#include <assert.h>
#include <stdio.h>
#include <sanitizer/asan_interface.h>
void death() {
fprintf(stderr, "DEATH CALLBACK\n");
}
int main(int argc, char **argv) {
__sanitizer_set_death_callback(death);
assert(argc == 100);
}
// CHECK0-NOT: Sanitizer:DEADLYSIGNAL
// CHECK1: ERROR: {{.*}}Sanitizer: ABRT
// CHECK1: {{ #0 }}
// CHECK1: DEATH CALLBACK
// CHECK0-NOT: Sanitizer

View File

@@ -0,0 +1,11 @@
// RUN: %clang %s -Wl,-as-needed -o %t && %run %t
// Regression test for PR15823
// (http://llvm.org/bugs/show_bug.cgi?id=15823).
#include <stdio.h>
#include <time.h>
int main() {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return 0;
}

View File

@@ -0,0 +1,5 @@
// Check that closedir(NULL) is ok.
// RUN: %clang -O2 %s -o %t && %run %t
#include <sys/types.h>
#include <dirent.h>
int main() { closedir(0); }

View File

@@ -0,0 +1,65 @@
// RUN: %clangxx -g %s -o %t
// RUN: %env_tool_opts=decorate_proc_maps=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%tool_name
// REQUIRES: stable-runtime
// XFAIL: android && asan
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
bool CopyFdToFd(int in_fd, int out_fd) {
const size_t kBufSize = 0x10000;
static char buf[kBufSize];
while (true) {
ssize_t got = read(in_fd, buf, kBufSize);
if (got > 0) {
write(out_fd, buf, got);
} else if (got == 0) {
break;
} else if (errno != EAGAIN || errno != EWOULDBLOCK || errno != EINTR) {
fprintf(stderr, "error reading file, errno %d\n", errno);
return false;
}
}
return true;
}
void *ThreadFn(void *arg) {
(void)arg;
int fd = open("/proc/self/maps", O_RDONLY);
bool res = CopyFdToFd(fd, 2);
close(fd);
return (void *)!res;
}
int main(void) {
pthread_t t;
void *res;
pthread_create(&t, 0, ThreadFn, 0);
pthread_join(t, &res);
return (int)(size_t)res;
}
// CHECK-asan: rw-p {{.*}} [low shadow]
// CHECK-asan: ---p {{.*}} [shadow gap]
// CHECK-asan: rw-p {{.*}} [high shadow]
// CHECK-msan: ---p {{.*}} [invalid]
// CHECK-msan: rw-p {{.*}} [shadow{{.*}}]
// CHECK-msan: ---p {{.*}} [origin{{.*}}]
// CHECK-tsan: rw-p {{.*}} [shadow]
// CHECK-tsan: rw-p {{.*}} [meta shadow]
// CHECK-tsan: rw-p {{.*}} [trace 0]
// CHECK-tsan: rw-p {{.*}} [trace header 0]
// CHECK-tsan: rw-p {{.*}} [trace 1]
// CHECK-tsan: rw-p {{.*}} [trace header 1]
// Nothing interesting with standalone LSan and UBSan.
// CHECK-lsan: decorate_proc_maps
// CHECK-ubsan: decorate_proc_maps

View File

@@ -0,0 +1,12 @@
// RUN: %clangxx %s -o %t && %run not %t 1 2>&1 | FileCheck %s
// UNSUPPORTED: lsan,ubsan,android
#include <dlfcn.h>
#include <stdio.h>
#include <string>
int main (int argc, char *argv[]) {
// CHECK: You are trying to dlopen a <arbitrary path> shared library with RTLD_DEEPBIND flag
void *lib = dlopen("<arbitrary path>", RTLD_NOW | RTLD_DEEPBIND);
return 0;
}

View File

@@ -0,0 +1,20 @@
// Regression test for a crash in getpwnam_r and similar interceptors.
// RUN: %clangxx -O0 -g %s -o %t && %run %t
#include <assert.h>
#include <errno.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(void) {
struct passwd pwd;
struct passwd *pwdres;
char buf[10000];
int res = getpwnam_r("no-such-user", &pwd, buf, sizeof(buf), &pwdres);
assert(res == 0 || res == ENOENT);
assert(pwdres == 0);
return 0;
}

View File

@@ -0,0 +1,41 @@
// Check hard_rss_limit_mb. Not all sanitizers implement it yet.
// RUN: %clangxx -O2 %s -o %t
//
// Run with limit should fail:
// RUN: %env_tool_opts=hard_rss_limit_mb=100 not %run %t 2>&1 | FileCheck %s
// This run uses getrusage:
// RUN: %env_tool_opts=hard_rss_limit_mb=100:can_use_proc_maps_statm=0 not %run %t 2>&1 | FileCheck %s
//
// Run w/o limit or with a large enough limit should pass:
// RUN: %env_tool_opts=hard_rss_limit_mb=1000 %run %t
// RUN: %run %t
//
// FIXME: make it work for other sanitizers.
// XFAIL: lsan
// XFAIL: tsan
// XFAIL: msan
// XFAIL: ubsan
#include <string.h>
#include <stdio.h>
#include <unistd.h>
const int kNumAllocs = 200 * 1000;
const int kAllocSize = 1000;
volatile char *sink[kNumAllocs];
int main(int argc, char **argv) {
for (int i = 0; i < kNumAllocs; i++) {
if ((i % 1000) == 0) {
// Don't write to stderr! Doing that triggers a kernel race condition
// between this thread and the rss-limit thread, and may lose part of the
// output. See https://lkml.org/lkml/2014/2/17/324.
printf("[%d]\n", i);
}
char *x = new char[kAllocSize];
memset(x, 0, kAllocSize);
sink[i] = x;
}
sleep(1); // Make sure the background thread has time to kill the process.
// CHECK: hard rss limit exhausted
}

View File

@@ -0,0 +1,31 @@
// RUN: %clang %s -o %t && %run %t
// Verify that even if iconv returned -1
// we still treat the initialized part of outbuf as properly initialized.
// UNSUPPORTED: android
#include <iconv.h>
#include <assert.h>
#include <stdio.h>
int main() {
iconv_t cd = iconv_open("UTF-8", "no");
assert(cd != (iconv_t)-1);
char in[11] = {0x7e, 0x7e, 0x5f, 0x53, 0x55, 0x3e,
0x99, 0x3c, 0x7e, 0x7e, 0x7e};
fprintf(stderr, "cd: %p\n", (void*)cd);
char out[100];
char *inbuf = &in[0];
size_t inbytesleft = 11;
char *outbuf = &out[0];
size_t outbytesleft = 100;
int ret = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
assert(ret == -1);
assert(outbuf - &out[0] == 10);
for (int i = 0; i < 10; i++) {
if (out[i] == 0x77) return 1;
fprintf(stderr, "OUT%d 0x%x -- OK\n", i, (unsigned char)out[i]);
}
iconv_close(cd);
}

View File

@@ -0,0 +1,29 @@
// Test the handle_sigill option.
// clang-format off
// RUN: %clangxx %s -o %t -O1
// RUN: not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s
// RUN: %env_tool_opts=handle_sigill=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s
// RUN: %env_tool_opts=handle_sigill=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s
// clang-format on
// FIXME: seems to fail on ARM
// REQUIRES: x86_64-target-arch
#include <assert.h>
#include <stdio.h>
#include <sanitizer/asan_interface.h>
void death() {
fprintf(stderr, "DEATH CALLBACK\n");
}
int main(int argc, char **argv) {
__sanitizer_set_death_callback(death);
__builtin_trap();
}
// CHECK0-NOT: Sanitizer:DEADLYSIGNAL
// CHECK1: ERROR: {{.*}}Sanitizer: ILL
// CHECK1: {{#[0-9]+.* main .*ill\.cc:[0-9]+}}
// CHECK1: DEATH CALLBACK
// CHECK0-NOT: Sanitizer

View File

@@ -0,0 +1,9 @@
def getRoot(config):
if not config.parent:
return config
return getRoot(config.parent)
root = getRoot(config)
if root.host_os not in ['Linux']:
config.unsupported = True

View File

@@ -0,0 +1,13 @@
// RUN: %clang %s -o %t && %run %t
// XFAIL: ubsan,lsan
#include <assert.h>
#include <sys/mman.h>
int main() {
assert(0 == mlockall(MCL_CURRENT));
assert(0 == mlock((void *)0x12345, 0x5678));
assert(0 == munlockall());
assert(0 == munlock((void *)0x987, 0x654));
}

View File

@@ -0,0 +1,42 @@
// RUN: %clangxx %s -o %t && %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: android, ubsan
#include <stdio.h>
#include <stdlib.h>
#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 2)
#include <mcheck.h>
#else
#define MCHECK_OK 0
extern "C" int mcheck(void (*abortfunc)(int mstatus));
extern "C" int mcheck_pedantic(void (*abortfunc)(int mstatus));
extern "C" int mprobe(void *ptr);
#endif
void check_heap() {
void *p = malloc(1000);
int res = mprobe(p);
if (res == MCHECK_OK)
printf("Success!\n");
free(p);
}
int main(int argc, char *argv[]) {
void *p;
if (mcheck(NULL) != 0) {
fprintf(stderr, "mcheck() failed\n");
exit(EXIT_FAILURE);
}
check_heap();
// CHECK: Success!
if (mcheck_pedantic(NULL) != 0) {
fprintf(stderr, "mcheck_pedantic() failed\n");
exit(EXIT_FAILURE);
}
check_heap();
// CHECK: Success!
return 0;
}

View File

@@ -0,0 +1,80 @@
// RUN: %clangxx -std=c++1z -faligned-allocation -O0 %s -o %t && %run %t
// RUN: %clangxx -std=c++1z -faligned-allocation -fsized-deallocation -O0 %s -o %t && %run %t
// ubsan does not intercept new/delete.
// UNSUPPORTED: ubsan
// Check that all new/delete variants are defined and work with supported
// sanitizers. Sanitizer-specific failure modes tests are supposed to go to
// the particular sanitizier's test suites.
#include <cstddef>
// Define all new/delete to do not depend on the version provided by the
// platform. The implementation is provided by the sanitizer anyway.
namespace std {
struct nothrow_t {};
static const nothrow_t nothrow;
enum class align_val_t : size_t {};
} // namespace std
void *operator new(size_t);
void *operator new[](size_t);
void *operator new(size_t, std::nothrow_t const&);
void *operator new[](size_t, std::nothrow_t const&);
void *operator new(size_t, std::align_val_t);
void *operator new[](size_t, std::align_val_t);
void *operator new(size_t, std::align_val_t, std::nothrow_t const&);
void *operator new[](size_t, std::align_val_t, std::nothrow_t const&);
void operator delete(void*) throw();
void operator delete[](void*) throw();
void operator delete(void*, std::nothrow_t const&);
void operator delete[](void*, std::nothrow_t const&);
void operator delete(void*, size_t) throw();
void operator delete[](void*, size_t) throw();
void operator delete(void*, std::align_val_t) throw();
void operator delete[](void*, std::align_val_t) throw();
void operator delete(void*, std::align_val_t, std::nothrow_t const&);
void operator delete[](void*, std::align_val_t, std::nothrow_t const&);
void operator delete(void*, size_t, std::align_val_t) throw();
void operator delete[](void*, size_t, std::align_val_t) throw();
template<typename T>
inline T* break_optimization(T *arg) {
__asm__ __volatile__("" : : "r" (arg) : "memory");
return arg;
}
struct S12 { int a, b, c; };
struct alignas(128) S12_128 { int a, b, c; };
struct alignas(256) S12_256 { int a, b, c; };
struct alignas(512) S1024_512 { char a[1024]; };
struct alignas(1024) S1024_1024 { char a[1024]; };
int main(int argc, char **argv) {
delete break_optimization(new S12);
operator delete(break_optimization(new S12), std::nothrow);
delete [] break_optimization(new S12[100]);
operator delete[](break_optimization(new S12[100]), std::nothrow);
delete break_optimization(new S12_128);
operator delete(break_optimization(new S12_128),
std::align_val_t(alignof(S12_128)));
operator delete(break_optimization(new S12_128),
std::align_val_t(alignof(S12_128)), std::nothrow);
operator delete(break_optimization(new S12_128), sizeof(S12_128),
std::align_val_t(alignof(S12_128)));
delete [] break_optimization(new S12_128[100]);
operator delete[](break_optimization(new S12_128[100]),
std::align_val_t(alignof(S12_128)));
operator delete[](break_optimization(new S12_128[100]),
std::align_val_t(alignof(S12_128)), std::nothrow);
operator delete[](break_optimization(new S12_128[100]), sizeof(S12_128[100]),
std::align_val_t(alignof(S12_128)));
}

View File

@@ -0,0 +1,70 @@
// RUN: %clangxx -m64 -O0 -g -xc++ %s -o %t && %run %t
// RUN: %clangxx -m64 -O3 -g -xc++ %s -o %t && %run %t
// REQUIRES: x86_64-target-arch
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __has_feature
#define __has_feature(x) 0
#endif
#if __has_feature(memory_sanitizer)
#include <sanitizer/msan_interface.h>
static void check_mem_is_good(void *p, size_t s) {
__msan_check_mem_is_initialized(p, s);
}
#elif __has_feature(address_sanitizer)
#include <sanitizer/asan_interface.h>
static void check_mem_is_good(void *p, size_t s) {
assert(__asan_region_is_poisoned(p, s) == 0);
}
#else
static void check_mem_is_good(void *p, size_t s) {}
#endif
static void run(bool flush) {
char *buf;
size_t buf_len;
fprintf(stderr, " &buf %p, &buf_len %p\n", &buf, &buf_len);
FILE *fp = open_memstream(&buf, &buf_len);
fprintf(fp, "hello");
if (flush) {
fflush(fp);
check_mem_is_good(&buf, sizeof(buf));
check_mem_is_good(&buf_len, sizeof(buf_len));
check_mem_is_good(buf, buf_len);
}
char *p = new char[1024];
memset(p, 'a', 1023);
p[1023] = 0;
for (int i = 0; i < 100; ++i)
fprintf(fp, "%s", p);
delete[] p;
if (flush) {
fflush(fp);
fprintf(stderr, " %p addr %p, len %zu\n", &buf, buf, buf_len);
check_mem_is_good(&buf, sizeof(buf));
check_mem_is_good(&buf_len, sizeof(buf_len));
check_mem_is_good(buf, buf_len);\
}
fclose(fp);
check_mem_is_good(&buf, sizeof(buf));
check_mem_is_good(&buf_len, sizeof(buf_len));
check_mem_is_good(buf, buf_len);
free(buf);
}
int main(void) {
for (int i = 0; i < 100; ++i)
run(false);
for (int i = 0; i < 100; ++i)
run(true);
return 0;
}

Some files were not shown because too many files have changed in this diff Show More