; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; 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 ptr @ret_nonnull() ; Return a pointer trivially nonnull (call return attribute) define ptr @test1() { ; FNATTR: define nonnull ptr @test1 %ret = call ptr @ret_nonnull() ret ptr %ret } ; Return a pointer trivially nonnull (argument attribute) define ptr @test2(ptr nonnull %p) { ; FNATTR: define nonnull ptr @test2 ret ptr %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 ptr @scc_binder(i1 %c) { ; FNATTR: define ptr @scc_binder br i1 %c, label %rec, label %end rec: call ptr @test3(i1 %c) br label %end end: ret ptr null } define ptr @test3(i1 %c) { ; FNATTR: define nonnull ptr @test3 call ptr @scc_binder(i1 %c) %ret = call ptr @ret_nonnull() ret ptr %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 ptr @test4_helper() { ; FNATTR: define noalias nonnull ptr @test4_helper %ret = call ptr @test4() ret ptr %ret } define ptr @test4() { ; FNATTR: define noalias nonnull ptr @test4 %ret = call ptr @test4_helper() ret ptr %ret } ; Given a mutual recursive set of functions which *can* return null ; make sure we haven't marked them as nonnull. define ptr @test5_helper(i1 %c) { ; FNATTR: define noalias ptr @test5_helper br i1 %c, label %rec, label %end rec: %ret = call ptr @test5(i1 %c) br label %end end: ret ptr null } define ptr @test5(i1 %c) { ; FNATTR: define noalias ptr @test5 %ret = call ptr @test5_helper(i1 %c) ret ptr %ret } ; Local analysis, but going through a self recursive phi define ptr @test6a() { entry: %ret = call ptr @ret_nonnull() br label %loop loop: %phi = phi ptr [%ret, %entry], [%phi, %loop] br i1 undef, label %loop, label %exit exit: ret ptr %phi } define ptr @test6b(i1 %c) { entry: %ret = call ptr @ret_nonnull() br label %loop loop: %phi = phi ptr [%ret, %entry], [%phi, %loop] br i1 %c, label %loop, label %exit exit: ret ptr %phi } ; FNATTR: define ptr @test7 define ptr @test7(ptr %a) { ret ptr %a } ; FNATTR: define nonnull ptr @test8 define ptr @test8(ptr %a) { %b = getelementptr inbounds i8, ptr %a, i64 1 ret ptr %b } ; FNATTR: define ptr @test9 define ptr @test9(ptr %a, i64 %n) { %b = getelementptr inbounds i8, ptr %a, i64 %n ret ptr %b } declare void @llvm.assume(i1) ; FNATTR: define ptr @test10 ; FIXME: missing nonnull define ptr @test10(ptr %a, i64 %n) { %cmp = icmp ne i64 %n, 0 call void @llvm.assume(i1 %cmp) %b = getelementptr inbounds i8, ptr %a, i64 %n ret ptr %b } ; TEST 11 ; char* test11(char *p) { ; return p? p: nonnull(); ; } ; FNATTR: define ptr @test11 ; FIXME: missing nonnull define ptr @test11(ptr) local_unnamed_addr { %2 = icmp eq ptr %0, null br i1 %2, label %3, label %5 ;