2016-08-21 01:22:36 +08:00
|
|
|
// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
|
2015-05-28 15:49:05 +08:00
|
|
|
// RUN: %run %t 2>&1
|
|
|
|
//
|
2015-05-28 22:29:12 +08:00
|
|
|
// REQUIRES: stable-runtime
|
2015-05-28 15:49:05 +08:00
|
|
|
|
|
|
|
// This testcase checks that allocas and VLAs inside loop are correctly unpoisoned.
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
2015-08-01 07:57:06 +08:00
|
|
|
#include <stdlib.h>
|
2015-05-28 15:49:05 +08:00
|
|
|
#include "sanitizer/asan_interface.h"
|
|
|
|
|
2015-08-15 01:39:48 +08:00
|
|
|
// MSVC provides _alloca instead of alloca.
|
|
|
|
#if defined(_MSC_VER) && !defined(alloca)
|
|
|
|
# define alloca _alloca
|
|
|
|
#endif
|
|
|
|
|
[Sanitizers, test] Fix sanitizer tests on Solaris (PR 33274)
Summary:
This patch (on top of the previous two (https://reviews.llvm.org/D40898 and
https://reviews.llvm.org/D40899) complete the compiler-rt side of the the Solaris
sanitizer port.
It contains the following sets of changes:
* For the time being, the port is for 32-bit x86 only, so reject the various tests on
x86_64.
* When compiling as C++, <setjmp.h> resp. <iso/setjmp_iso.h> only declares
_setjmp and _longjmp inside namespace std.
* MAP_FILE is a Windows feature. While e.g. Linux <sys/mman.h> provides a
no-op compat define, Solaris does not.
* test/asan/TestCases/Posix/coverage.cc was initially failing like this:
/vol/gcc/src/llvm/llvm/local/projects/compiler-rt/lib/sanitizer_common/scripts/sancov.py: 4 files merged; 2 PCs total
rm: cannot remove '/var/gcc/llvm/local/projects/compiler-rt/test/asan/I386SunOSConfig/TestCases/Posix/Output/coverage': Invalid argument
Further digging revealed that the rm was trying to remove the running test's working
directory which failed as observed. cd'ing out of the dir before let the test pass.
* Two tests needed a declaration of alloca. I've now copied the existing code from
test/asan/TestCases/alloca_constant_size.cc, but it may be more profitable and
maintainable to have a common testsuite header where such code is collected.
* Similarly, Solaris' printf %p format doesn't include the leading 0x.
* In test/asan/TestCases/malloc-no-intercept.c, I had to undef __EXTENSIONS__
(predefined by clang for no apparent reason) to avoid conflicting declarations
for memalign.
* test/ubsan/TestCases/Float/cast-overflow.cpp has different platform dependent
ways to define BYTE_ORDER and friends. Why not just use __BYTE_ORDER__ and
friends as predefined by clang and gcc?
Patch by Rainer Orth.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, kubamracek, mgorny, krytarowski, fedor.sergeev, JDevlieghere, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40900
llvm-svn: 322635
2018-01-17 20:26:04 +08:00
|
|
|
#if defined(__sun__) && defined(__svr4__)
|
|
|
|
#include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
2015-05-28 15:49:05 +08:00
|
|
|
void *top, *bot;
|
|
|
|
|
|
|
|
__attribute__((noinline)) void foo(int len) {
|
|
|
|
char x;
|
|
|
|
top = &x;
|
|
|
|
char array[len]; // NOLINT
|
|
|
|
assert(!(reinterpret_cast<uintptr_t>(array) & 31L));
|
|
|
|
alloca(len);
|
|
|
|
for (int i = 0; i < 32; ++i) {
|
|
|
|
char array[i]; // NOLINT
|
|
|
|
bot = alloca(i);
|
|
|
|
assert(!(reinterpret_cast<uintptr_t>(bot) & 31L));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
foo(32);
|
|
|
|
void *q = __asan_region_is_poisoned(bot, (char *)top - (char *)bot);
|
|
|
|
assert(!q);
|
|
|
|
return 0;
|
|
|
|
}
|