; RUN: opt -S -functionattrs -enable-nonnull-arg-prop %s | FileCheck %s --check-prefixes=BOTH,FNATTR ; RUN: opt -S -passes=function-attrs -enable-nonnull-arg-prop %s | FileCheck %s --check-prefixes=BOTH,FNATTR ; RUN: opt -attributor --attributor-disable=false -S < %s | FileCheck %s --check-prefixes=BOTH,ATTRIBUTOR 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() { ; BOTH: 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) { ; BOTH: 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() { ; FNATTR: define i8* @scc_binder ; ATTRIBUTOR: define noalias i8* @scc_binder call i8* @test3() ret i8* null } define i8* @test3() { ; BOTH: define nonnull i8* @test3 call i8* @scc_binder() %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 ; ATTRIBUTOR: define noalias nonnull align 536870912 dereferenceable(4294967295) i8* @test4_helper %ret = call i8* @test4() ret i8* %ret } define i8* @test4() { ; FNATTR: define noalias nonnull i8* @test4 ; ATTRIBUTOR: define noalias nonnull align 536870912 dereferenceable(4294967295) 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() { ; FNATTR: define noalias i8* @test5_helper ; ATTRIBUTOR: define noalias i8* @test5_helper %ret = call i8* @test5() ret i8* null } define i8* @test5() { ; FNATTR: define noalias i8* @test5 ; ATTRIBUTOR: define noalias i8* @test5 %ret = call i8* @test5_helper() ret i8* %ret } ; Local analysis, but going through a self recursive phi define i8* @test6() { entry: ; BOTH: define nonnull i8* @test6 %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 } ; BOTH: define i8* @test7 define i8* @test7(i8* %a) { %b = getelementptr inbounds i8, i8* %a, i64 0 ret i8* %b } ; BOTH: define nonnull i8* @test8 define i8* @test8(i8* %a) { %b = getelementptr inbounds i8, i8* %a, i64 1 ret i8* %b } ; BOTH: 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 ; ATTRIBUTOR: define i8* @test10 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 ; ATTRIBUTOR: define i8* @test11 define i8* @test11(i8*) local_unnamed_addr { %2 = icmp eq i8* %0, null br i1 %2, label %3, label %5 ;