; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -function-attrs -enable-nonnull-arg-prop %s | FileCheck %s --check-prefixes=FNATTR ; RUN: opt -S -passes=function-attrs -enable-nonnull-arg-prop %s | FileCheck %s --check-prefixes=FNATTR target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" declare nonnull i8* @ret_nonnull() ; Return a pointer trivially nonnull (call return attribute) define i8* @test1() { ; FNATTR: define nonnull i8* @test1 %ret = call i8* @ret_nonnull() ret i8* %ret } ; Return a pointer trivially nonnull (argument attribute) define i8* @test2(i8* nonnull %p) { ; FNATTR: define nonnull i8* @test2 ret i8* %p } ; Given an SCC where one of the functions can not be marked nonnull, ; can we still mark the other one which is trivially nonnull define i8* @scc_binder(i1 %c) { ; FNATTR: define i8* @scc_binder br i1 %c, label %rec, label %end rec: call i8* @test3(i1 %c) br label %end end: ret i8* null } define i8* @test3(i1 %c) { ; FNATTR: define nonnull i8* @test3 call i8* @scc_binder(i1 %c) %ret = call i8* @ret_nonnull() ret i8* %ret } ; Given a mutual recursive set of functions, we can mark them ; nonnull if neither can ever return null. (In this case, they ; just never return period.) define i8* @test4_helper() { ; FNATTR: define noalias nonnull i8* @test4_helper %ret = call i8* @test4() ret i8* %ret } define i8* @test4() { ; FNATTR: define noalias nonnull i8* @test4 %ret = call i8* @test4_helper() ret i8* %ret } ; Given a mutual recursive set of functions which *can* return null ; make sure we haven't marked them as nonnull. define i8* @test5_helper(i1 %c) { ; FNATTR: define noalias i8* @test5_helper br i1 %c, label %rec, label %end rec: %ret = call i8* @test5(i1 %c) br label %end end: ret i8* null } define i8* @test5(i1 %c) { ; FNATTR: define noalias i8* @test5 %ret = call i8* @test5_helper(i1 %c) ret i8* %ret } ; Local analysis, but going through a self recursive phi define i8* @test6a() { entry: %ret = call i8* @ret_nonnull() br label %loop loop: %phi = phi i8* [%ret, %entry], [%phi, %loop] br i1 undef, label %loop, label %exit exit: ret i8* %phi } define i8* @test6b(i1 %c) { entry: %ret = call i8* @ret_nonnull() br label %loop loop: %phi = phi i8* [%ret, %entry], [%phi, %loop] br i1 %c, label %loop, label %exit exit: ret i8* %phi } ; FNATTR: define i8* @test7 define i8* @test7(i8* %a) { %b = getelementptr inbounds i8, i8* %a, i64 0 ret i8* %b } ; FNATTR: define nonnull i8* @test8 define i8* @test8(i8* %a) { %b = getelementptr inbounds i8, i8* %a, i64 1 ret i8* %b } ; FNATTR: define i8* @test9 define i8* @test9(i8* %a, i64 %n) { %b = getelementptr inbounds i8, i8* %a, i64 %n ret i8* %b } declare void @llvm.assume(i1) ; FNATTR: define i8* @test10 ; FIXME: missing nonnull define i8* @test10(i8* %a, i64 %n) { %cmp = icmp ne i64 %n, 0 call void @llvm.assume(i1 %cmp) %b = getelementptr inbounds i8, i8* %a, i64 %n ret i8* %b } ; TEST 11 ; char* test11(char *p) { ; return p? p: nonnull(); ; } ; FNATTR: define i8* @test11 ; FIXME: missing nonnull define i8* @test11(i8*) local_unnamed_addr { %2 = icmp eq i8* %0, null br i1 %2, label %3, label %5 ;