diff options
author | Vedant Kumar <vsk@apple.com> | 2017-06-01 19:40:59 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-06-01 19:40:59 +0000 |
commit | efd9e1ef2ba69497829dde2af6a879b789662e9b (patch) | |
tree | 41de6808c18c9e698b4c4ce1e3027056e91fcc5b /test/ubsan | |
parent | 0c1676c0068c7bda6cba4a7d24ba1aa500201086 (diff) |
[ubsan] Runtime support for pointer overflow checking
Patch by John Regehr and Will Dietz!
Differential Revision: https://reviews.llvm.org/D20323
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@304461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/ubsan')
-rw-r--r-- | test/ubsan/TestCases/Pointer/index-overflow.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ubsan/TestCases/Pointer/index-overflow.cpp b/test/ubsan/TestCases/Pointer/index-overflow.cpp new file mode 100644 index 000000000..eb7f95e85 --- /dev/null +++ b/test/ubsan/TestCases/Pointer/index-overflow.cpp @@ -0,0 +1,19 @@ +// RUN: %clangxx -fsanitize=pointer-overflow %s -o %t +// RUN: %t 1 2>&1 | FileCheck %s --check-prefix=ERR +// RUN: %t 0 2>&1 | FileCheck %s --check-prefix=SAFE +// RUN: %t -1 2>&1 | FileCheck %s --check-prefix=SAFE + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) { + // SAFE-NOT: runtime error + // ERR: runtime error: pointer index expression with base {{.*}} overflowed to + + char *p = (char *)(UINTPTR_MAX); + + printf("%p\n", p + atoi(argv[1])); + + return 0; +} |