summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/FunctionAttrs
diff options
context:
space:
mode:
authorJohannes Doerfert <johannes@jdoerfert.de>2019-11-01 20:17:48 -0500
committerJohannes Doerfert <johannes@jdoerfert.de>2019-11-02 00:35:22 -0500
commit1b6041a9e8c537894dfda998fdd3d284b1111bd2 (patch)
tree7ee6d5b951b826686a06c4cc62f81c1faf4195be /llvm/test/Transforms/FunctionAttrs
parente360ee62650609112b08e4ab2249e1e5a8c9e0d0 (diff)
downloadbcm5719-llvm-1b6041a9e8c537894dfda998fdd3d284b1111bd2.tar.gz
bcm5719-llvm-1b6041a9e8c537894dfda998fdd3d284b1111bd2.zip
[Attributor] `willreturn` + `noreturn` = UB
We gave up on `noreturn` if `willreturn` was known for a while but we now again try to always derive `noreturn`. This is useful because a function that is `noreturn` + `willreturn` is basically dead as executing it would lead to undefined behavior (UB). This came up in the IPConstantProp cases where a function only contained a unreachable but was not marked `noreturn` which caused missed opportunities down the line.
Diffstat (limited to 'llvm/test/Transforms/FunctionAttrs')
-rw-r--r--llvm/test/Transforms/FunctionAttrs/fn_noreturn.ll16
-rw-r--r--llvm/test/Transforms/FunctionAttrs/internal-noalias.ll2
-rw-r--r--llvm/test/Transforms/FunctionAttrs/norecurse.ll2
3 files changed, 15 insertions, 5 deletions
diff --git a/llvm/test/Transforms/FunctionAttrs/fn_noreturn.ll b/llvm/test/Transforms/FunctionAttrs/fn_noreturn.ll
index d0ccb87485b..2b15e0780df 100644
--- a/llvm/test/Transforms/FunctionAttrs/fn_noreturn.ll
+++ b/llvm/test/Transforms/FunctionAttrs/fn_noreturn.ll
@@ -125,10 +125,12 @@ cond.end: ; preds = %cond.false, %cond.t
}
-; TEST 6: willreturn means *not* no-return
-; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
+; TEST 6a: willreturn means *not* no-return or UB
+; FIXME: we should derive "UB" as an argument and report it to the user on request.
+
+; CHECK: Function Attrs: nofree norecurse noreturn nosync nounwind readnone willreturn
; CHECK-NEXT: define i32 @endless_loop_but_willreturn
-define i32 @endless_loop_but_willreturn(i32 %a) willreturn {
+define i32 @endless_loop_but_willreturn() willreturn {
entry:
br label %while.body
@@ -136,4 +138,12 @@ while.body: ; preds = %entry, %while.body
br label %while.body
}
+; TEST 6b: willreturn means *not* no-return or UB
+; CHECK: Function Attrs: nofree norecurse noreturn nosync nounwind readnone willreturn
+; CHECK-NEXT: define i32 @UB_and_willreturn
+define i32 @UB_and_willreturn() willreturn {
+entry:
+ unreachable
+}
+
attributes #0 = { noinline nounwind uwtable }
diff --git a/llvm/test/Transforms/FunctionAttrs/internal-noalias.ll b/llvm/test/Transforms/FunctionAttrs/internal-noalias.ll
index 2ccb4b67e56..9afea1fbf8d 100644
--- a/llvm/test/Transforms/FunctionAttrs/internal-noalias.ll
+++ b/llvm/test/Transforms/FunctionAttrs/internal-noalias.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=7 < %s | FileCheck %s
define dso_local i32 @visible(i32* noalias %A, i32* noalias %B) #0 {
entry:
diff --git a/llvm/test/Transforms/FunctionAttrs/norecurse.ll b/llvm/test/Transforms/FunctionAttrs/norecurse.ll
index 0e67a600f34..132396fc37f 100644
--- a/llvm/test/Transforms/FunctionAttrs/norecurse.ll
+++ b/llvm/test/Transforms/FunctionAttrs/norecurse.ll
@@ -1,6 +1,6 @@
; RUN: opt < %s -basicaa -functionattrs -rpo-functionattrs -S | FileCheck %s --check-prefixes=CHECK,BOTH
; RUN: opt < %s -aa-pipeline=basic-aa -passes='cgscc(function-attrs),rpo-functionattrs' -S | FileCheck %s --check-prefixes=CHECK,BOTH
-; RUN: opt -passes=attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=4 -S < %s | FileCheck %s --check-prefixes=ATTRIBUTOR,BOTH
+; RUN: opt -passes=attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=ATTRIBUTOR,BOTH
; CHECK: Function Attrs
; CHECK-SAME: norecurse nounwind readnone
OpenPOWER on IntegriCloud