diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -1472,6 +1472,11 @@ This function attribute indicates that the function does not call itself either directly or indirectly down any possible call path. This produces undefined behavior at runtime if the function ever does recurse. +``will-return`` + This function attribute indicates that a call of this function will, + either exhibit undefined behavior or comes back to the invoking call site. + This produces undefined behavior at runtime if the function never comes back + to the call site. ``nounwind`` This function attribute indicates that the function never raises an exception. If the function does raise an exception, its runtime diff --git a/llvm/test/Transforms/FunctionAttrs/will-return.ll b/llvm/test/Transforms/FunctionAttrs/will-return.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/FunctionAttrs/will-return.ll @@ -0,0 +1,213 @@ +; RUN: opt -functionattrs -S < %s | FileCheck %s --check-prefix=FNATTR + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +; Test cases specifically designed for the "will-return" function attribute. +; We use FIXME's to indicate problems and missing attributes. + + +; TEST 1 (positive case) +; FIXME: missing "will-return" +; FNATTR: Function Attrs: noinline norecurse nounwind readnone uwtable +; FNATTR-NEXT: define void @only_return() +define void @only_return() #0 { + ret void +} + + +; TEST 2 (negative case) +; recursive function +; int fib(int n){ +; return n<=1? n : fib(n-1) + fib(n-2); +; } + +; FNATTR: Function Attrs: noinline nounwind readnone uwtable +; FNATTR-NOT: "will-return" +; FNATTR-NEXT: define i32 @fib(i32) +define i32 @fib(i32) local_unnamed_addr #0 { + %2 = icmp slt i32 %0, 2 + br i1 %2, label %9, label %3 + +;