summaryrefslogtreecommitdiff
path: root/test/ubsan/TestCases/Misc/nonnull.cpp
blob: c3ab49c11df7bdcae078766ee5cb6d329fedbe19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
}