aboutsummaryrefslogtreecommitdiff
path: root/test/ubsan/TestCases/Misc/nonnull.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/ubsan/TestCases/Misc/nonnull.cpp')
-rw-r--r--test/ubsan/TestCases/Misc/nonnull.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ubsan/TestCases/Misc/nonnull.cpp b/test/ubsan/TestCases/Misc/nonnull.cpp
new file mode 100644
index 000000000000..c3ab49c11df7
--- /dev/null
+++ b/test/ubsan/TestCases/Misc/nonnull.cpp
@@ -0,0 +1,15 @@
+// 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);
+
+char *foo(char *a) {
+ return a;
+ // CHECK: nonnull.cpp:[[@LINE+2]]:1: runtime error: null pointer returned from function declared to never return null
+ // CHECK-NEXT: nonnull.cpp:[[@LINE-5]]:16: note: returns_nonnull attribute specified here
+}
+
+int main(int argc, char **argv) {
+ return foo(argv[1]) == 0;
+}