summaryrefslogtreecommitdiff
path: root/test/ubsan/TestCases/Misc
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2014-08-13 00:26:40 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2014-08-13 00:26:40 +0000
commit14034c1df0a6c8f6e89c4f92d8e4f6ff09095de6 (patch)
treeb6a5773fb9e30655d0f6b626d6dc169a8f63c95b /test/ubsan/TestCases/Misc
parent3d42f6f3203aa12de411cfaa1fd9b16b681d1bcd (diff)
[UBSan] Add returns-nonnull sanitizer.
Summary: This patch adds a runtime check verifying that functions annotated with "returns_nonnull" attribute do in fact return nonnull pointers. It is based on suggestion by Jakub Jelinek: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140623/223693.html. Test Plan: regression test suite Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4849 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@215485 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/ubsan/TestCases/Misc')
-rw-r--r--test/ubsan/TestCases/Misc/nonnull.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/ubsan/TestCases/Misc/nonnull.cpp b/test/ubsan/TestCases/Misc/nonnull.cpp
new file mode 100644
index 000000000..8b5fcaf43
--- /dev/null
+++ b/test/ubsan/TestCases/Misc/nonnull.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx -fsanitize=returns-nonnull-attribute %s -O3 -o %t
+// RUN: %run %t foo
+// RUN: %run %t 2>&1 | FileCheck %s
+
+__attribute__((returns_nonnull))
+char *foo(char *a) {
+ return a;
+ // CHECK: nonnull.cpp:[[@LINE+1]]:1: runtime error: null pointer returned from function declared to never return null
+}
+
+int main(int argc, char **argv) {
+ return foo(argv[1]) == 0;
+}