Index: llvm/docs/LangRef.rst =================================================================== --- llvm/docs/LangRef.rst +++ llvm/docs/LangRef.rst @@ -1472,6 +1472,13 @@ 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. +``willreturn`` + This function attribute indicates that a call of this function will + either exhibit undefined behavior or comes back and continues execution + at a point in the existing call stack that includes the current invocation. + Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied. + If an invocation of an annotated function does not return control back + to a point in the call stack, the behavior is undefined. ``nounwind`` This function attribute indicates that the function never raises an exception. If the function does raise an exception, its runtime Index: llvm/test/Transforms/FunctionAttrs/will-return.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/FunctionAttrs/will-return.ll @@ -0,0 +1,466 @@ +; 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 "willreturn" function attribute. +; We use FIXME's to indicate problems and missing attributes. + + +; TEST 1 (positive case) +; FIXME: missing "willreturn" +; FNATTR: Function Attrs: noinline norecurse nounwind readnone uwtable +; FNATTR-NEXT: define void @only_return() +define void @only_return() #0 { + ret void +} + + +; TEST 2 (positive & negative case) +; 2.1 (positive case) +; recursive function which will halt +; int fib(int n){ +; return n<=1? n : fib(n-1) + fib(n-2); +; } + +; FIXME: missing "willreturn" +; FNATTR: Function Attrs: noinline nounwind readnone uwtable +; 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 + +;