[MSan] Switch to common aligned allocs tests.

Summary:
Switch to aligned_alloc and posix_memalign tests in sanitizer_common
and delete the MSan-specific ones.

Reviewers: vitalybuka

Subscribers: srhines, kubamracek, delcypher, #sanitizers, llvm-commits

Differential Revision: https://reviews.llvm.org/D47968

llvm-svn: 334340
This commit is contained in:
Alex Shlyapnikov 2018-06-09 00:47:37 +00:00
parent 7c89d046ea
commit b24e6a9905
5 changed files with 8 additions and 53 deletions

View File

@ -1,26 +0,0 @@
// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 -g %s -o %t
// RUN: MSAN_OPTIONS=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
// RUN: MSAN_OPTIONS=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
// UNSUPPORTED: android
// REQUIRES: stable-runtime
#include <stdio.h>
#include <stdlib.h>
extern void *aligned_alloc(size_t alignment, size_t size);
int main() {
void *p = aligned_alloc(17, 100);
// CHECK: ERROR: MemorySanitizer: invalid alignment requested in aligned_alloc: 17
// Check just the top frame since mips is forced to use store_context_size==1
// and also handle a case when aligned_alloc is aliased by memalign.
// CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}}
// CHECK: SUMMARY: MemorySanitizer: invalid-aligned-alloc-alignment
printf("pointer after failed aligned_alloc: %zd\n", (size_t)p);
// CHECK-NULL: pointer after failed aligned_alloc: 0
return 0;
}

View File

@ -1,22 +0,0 @@
// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 -g %s -o %t
// RUN: MSAN_OPTIONS=$MSAN_OPTIONS:allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
// RUN: MSAN_OPTIONS=$MSAN_OPTIONS:allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
// REQUIRES: stable-runtime
#include <stdio.h>
#include <stdlib.h>
int main() {
void *p = reinterpret_cast<void*>(42);
int res = posix_memalign(&p, 17, 100);
// CHECK: ERROR: MemorySanitizer: invalid alignment requested in posix_memalign: 17
// Check just the top frame since mips is forced to use store_context_size==1
// CHECK: {{#0 0x.* in .*posix_memalign}}
// CHECK: SUMMARY: MemorySanitizer: invalid-posix-memalign-alignment
printf("pointer after failed posix_memalign: %zd\n", (size_t)p);
// CHECK-NULL: pointer after failed posix_memalign: 42
return 0;
}

View File

@ -1,13 +1,13 @@
// RUN: %clangxx -O0 %s -o %t
// RUN: %clangxx %collect_stack_traces -O0 %s -o %t
// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 17 2>&1 | FileCheck %s
// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 0 2>&1 | FileCheck %s
// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 17 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
// UNSUPPORTED: android, msan, tsan, ubsan
// REQUIRES: stable-runtime
// UNSUPPORTED: android, tsan, ubsan
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,4 +1,4 @@
// RUN: %clangxx -O0 %s -o %t
// RUN: %clangxx %collect_stack_traces -O0 %s -o %t
// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 17 2>&1 | FileCheck %s
// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 0 2>&1 | FileCheck %s
// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 17 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
@ -6,7 +6,7 @@
// REQUIRES: stable-runtime
// UNSUPPORTED: msan, tsan, ubsan
// UNSUPPORTED: tsan, ubsan
#include <assert.h>
#include <stdio.h>

View File

@ -6,6 +6,7 @@ config.test_source_root = os.path.join(os.path.dirname(__file__), "TestCases")
config.name = "SanitizerCommon-" + config.name_suffix
default_tool_options = []
collect_stack_traces = ""
if config.tool_name == "asan":
tool_cflags = ["-fsanitize=address"]
tool_options = "ASAN_OPTIONS"
@ -15,6 +16,7 @@ elif config.tool_name == "tsan":
elif config.tool_name == "msan":
tool_cflags = ["-fsanitize=memory"]
tool_options = "MSAN_OPTIONS"
collect_stack_traces = "-fsanitize-memory-track-origins"
elif config.tool_name == "lsan":
tool_cflags = ["-fsanitize=leak"]
tool_options = "LSAN_OPTIONS"
@ -52,6 +54,7 @@ def build_invocation(compile_flags):
config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )
config.substitutions.append( ("%collect_stack_traces", collect_stack_traces) )
config.substitutions.append( ("%tool_name", config.tool_name) )
config.substitutions.append( ("%tool_options", tool_options) )
config.substitutions.append( ('%env_tool_opts=',