diff options
Diffstat (limited to 'compiler-rt/test/fuzzer')
| -rw-r--r-- | compiler-rt/test/fuzzer/AlignmentAssumptionTest.cpp | 27 | ||||
| -rw-r--r-- | compiler-rt/test/fuzzer/fuzzer-alignment-assumption.test | 7 |
2 files changed, 34 insertions, 0 deletions
diff --git a/compiler-rt/test/fuzzer/AlignmentAssumptionTest.cpp b/compiler-rt/test/fuzzer/AlignmentAssumptionTest.cpp new file mode 100644 index 00000000000..be51d37e8fe --- /dev/null +++ b/compiler-rt/test/fuzzer/AlignmentAssumptionTest.cpp @@ -0,0 +1,27 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. + +// Test for alignment assumption failure. + +#include <assert.h> +#include <climits> +#include <cstddef> +#include <cstdint> +#include <cstdlib> +#include <iostream> + +static volatile int32_t Sink; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + assert(Data); + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + __builtin_assume_aligned(Data + 1, 0x8000); + } + } + } + return 0; +} diff --git a/compiler-rt/test/fuzzer/fuzzer-alignment-assumption.test b/compiler-rt/test/fuzzer/fuzzer-alignment-assumption.test new file mode 100644 index 00000000000..6a71ac6c566 --- /dev/null +++ b/compiler-rt/test/fuzzer/fuzzer-alignment-assumption.test @@ -0,0 +1,7 @@ +RUN: rm -f %t-AlignmentAssumptionTest-Ubsan +RUN: %cpp_compiler -fsanitize=alignment -fno-sanitize-recover=all %S/AlignmentAssumptionTest.cpp -o %t-AlignmentAssumptionTest-Ubsan +RUN: not %run %t-AlignmentAssumptionTest-Ubsan 2>&1 | FileCheck %s +CHECK: AlignmentAssumptionTest.cpp:22:34: runtime error: assumption of 32768 byte alignment for pointer of type 'const {{.*}} *' (aka 'const unsigned char *') failed +CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + +CHECK: Test unit written to ./crash- |

