summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/MergeFunc
diff options
context:
space:
mode:
authorErik Eckstein <eeckstein@apple.com>2016-05-31 17:20:23 +0000
committerErik Eckstein <eeckstein@apple.com>2016-05-31 17:20:23 +0000
commit0c48dd8ca53f3a962ffa408908b03f4cf45bddcb (patch)
tree6a6b56378415477e0b0350f98d3601728db1fe8c /llvm/test/Transforms/MergeFunc
parent1762eef57240d261e0fc0ec7ad64aafc3e1b3fc6 (diff)
downloadbcm5719-llvm-0c48dd8ca53f3a962ffa408908b03f4cf45bddcb.tar.gz
bcm5719-llvm-0c48dd8ca53f3a962ffa408908b03f4cf45bddcb.zip
Fix a crash in MergeFunctions related to ordering of weak/strong functions
The assumption, made in insert() that weak functions are always inserted after strong functions, is only true in the first round of adding functions. In subsequent rounds this is no longer guaranteed , because we might remove a strong function from the tree (because it's modified) and add it later, where an equivalent weak function already exists in the tree. This change removes the assert in insert() and explicitly enforces a weak->strong order. This also removes the need of two separate loops in runOnModule(). llvm-svn: 271299
Diffstat (limited to 'llvm/test/Transforms/MergeFunc')
-rw-r--r--llvm/test/Transforms/MergeFunc/merge-weak-crash.ll47
1 files changed, 47 insertions, 0 deletions
diff --git a/llvm/test/Transforms/MergeFunc/merge-weak-crash.ll b/llvm/test/Transforms/MergeFunc/merge-weak-crash.ll
new file mode 100644
index 00000000000..9d2c5caa4e5
--- /dev/null
+++ b/llvm/test/Transforms/MergeFunc/merge-weak-crash.ll
@@ -0,0 +1,47 @@
+; RUN: opt -S -mergefunc < %s | FileCheck %s
+
+; CHECK-LABEL: define i32 @func1
+; CHECK: call i32 @func2
+; CHECK: ret
+
+; CHECK-LABEL: define i32 @func2
+; CHECK: call i32 @unknown
+; CHECK: ret
+
+; CHECK-LABEL: define i32 @func4
+; CHECK: call i32 @func2
+; CHECK: ret
+
+; CHECK-LABEL: define weak i32 @func3_weak
+; CHECK: call i32 @func1
+; CHECK: ret
+
+define i32 @func1(i32 %x, i32 %y) {
+ %sum = add i32 %x, %y
+ %sum2 = add i32 %sum, %y
+ %sum3 = call i32 @func4(i32 %sum, i32 %sum2)
+ ret i32 %sum3
+}
+
+define i32 @func4(i32 %x, i32 %y) {
+ %sum = add i32 %x, %y
+ %sum2 = add i32 %sum, %y
+ %sum3 = call i32 @unknown(i32 %sum, i32 %sum2)
+ ret i32 %sum3
+}
+
+define weak i32 @func3_weak(i32 %x, i32 %y) {
+ %sum = add i32 %x, %y
+ %sum2 = add i32 %sum, %y
+ %sum3 = call i32 @func2(i32 %sum, i32 %sum2)
+ ret i32 %sum3
+}
+
+define i32 @func2(i32 %x, i32 %y) {
+ %sum = add i32 %x, %y
+ %sum2 = add i32 %sum, %y
+ %sum3 = call i32 @unknown(i32 %sum, i32 %sum2)
+ ret i32 %sum3
+}
+
+declare i32 @unknown(i32 %x, i32 %y)
OpenPOWER on IntegriCloud