xref: /aosp_15_r20/external/compiler-rt/test/ubsan/TestCases/Misc/nonnull.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx -fsanitize=returns-nonnull-attribute %s -O3 -o %t
2*7c3d14c8STreehugger Robot // RUN: %run %t foo
3*7c3d14c8STreehugger Robot // RUN: %run %t 2>&1 | FileCheck %s
4*7c3d14c8STreehugger Robot 
5*7c3d14c8STreehugger Robot __attribute__((returns_nonnull)) char *foo(char *a);
6*7c3d14c8STreehugger Robot 
foo(char * a)7*7c3d14c8STreehugger Robot char *foo(char *a) {
8*7c3d14c8STreehugger Robot   return a;
9*7c3d14c8STreehugger Robot   // CHECK: nonnull.cpp:[[@LINE+2]]:1: runtime error: null pointer returned from function declared to never return null
10*7c3d14c8STreehugger Robot   // CHECK-NEXT: nonnull.cpp:[[@LINE-5]]:16: note: returns_nonnull attribute specified here
11*7c3d14c8STreehugger Robot }
12*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)13*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
14*7c3d14c8STreehugger Robot   return foo(argv[1]) == 0;
15*7c3d14c8STreehugger Robot }
16