; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=5 -S < %s | FileCheck %s --check-prefixes=ATTRIBUTOR,ATTRIBUTOR_OPM ; RUN: opt -passes=attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=5 -S < %s | FileCheck %s --check-prefixes=ATTRIBUTOR,ATTRIBUTOR_NPM ; Copied from Transforms/FunctoinAttrs/nonnull.ll 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() { ; ATTRIBUTOR: 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) { ; ATTRIBUTOR: 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) { ; ATTRIBUTOR: define noalias 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) { ; ATTRIBUTOR: 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() { ; ATTRIBUTOR: define noalias nonnull align 536870912 dereferenceable(4294967295) i8* @test4_helper %ret = call i8* @test4() ret i8* %ret } define 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(i1 %c) { ; ATTRIBUTOR: 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) { ; ATTRIBUTOR: define noalias i8* @test5 %ret = call i8* @test5_helper(i1 %c) ret i8* %ret } ; Local analysis, but going through a self recursive phi ; ATTRIBUTOR: Function Attrs: noreturn ; ATTRIBUTOR: define noalias nonnull align 536870912 dereferenceable(4294967295) i8* @test6a() 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 } ; ATTRIBUTOR: define nonnull i8* @test6b(i1 %c) 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 } ; ATTRIBUTOR: define i8* @test7 define i8* @test7(i8* %a) { %b = getelementptr inbounds i8, i8* %a, i64 0 ret i8* %b } ; ATTRIBUTOR: define nonnull i8* @test8 define i8* @test8(i8* %a) { %b = getelementptr inbounds i8, i8* %a, i64 1 ret i8* %b } ; ATTRIBUTOR: 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) ; 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(); ; } ; 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 ;