[llvm] 5a4f193 - Add tests to reproduce pointer/index width confusion crashes
Krzysztof Drewniak via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 23 14:50:47 PST 2023
Author: Krzysztof Drewniak
Date: 2023-02-23T22:50:43Z
New Revision: 5a4f193afa0d73f7ec459648d8f02535577dd604
URL: https://github.com/llvm/llvm-project/commit/5a4f193afa0d73f7ec459648d8f02535577dd604
DIFF: https://github.com/llvm/llvm-project/commit/5a4f193afa0d73f7ec459648d8f02535577dd604.diff
LOG: Add tests to reproduce pointer/index width confusion crashes
Some calls to GEPOperator::accumulateConstantOffset(APInt) passed the
pointer bitwidth as the width of the APInt, while the function asserts
that the width of its argument is equal to the index width of the GEP
pointer input. These values are almost always the same, so mixing up
which call to use doesn't usually cause issues. However, when dealing
with data layouts where these values are different, the passes tested
here can crash.
This will be fixed in D143437 .
Differential Revision: https://reviews.llvm.org/D144673
Added:
llvm/test/Transforms/LowerTypeTests/distinct-index-width-crash.ll
llvm/test/Transforms/MergeFunc/different-index-width-gep-crash.ll
llvm/test/Transforms/MergeICmps/X86/distinct-index-width-crash.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/LowerTypeTests/distinct-index-width-crash.ll b/llvm/test/Transforms/LowerTypeTests/distinct-index-width-crash.ll
new file mode 100644
index 0000000000000..c9a15425e8d45
--- /dev/null
+++ b/llvm/test/Transforms/LowerTypeTests/distinct-index-width-crash.ll
@@ -0,0 +1,17 @@
+; RUN: not --crash opt -passes=lowertypetests %s -disable-output
+target datalayout = "e-p:64:64:64:32"
+
+ at a = constant i32 1, !type !0
+ at b = constant [2 x i32] [i32 2, i32 3], !type !1
+
+!0 = !{i32 0, !"typeid1"}
+!1 = !{i32 4, !"typeid1"}
+
+declare i1 @llvm.type.test(ptr %ptr, metadata %bitset) nounwind readnone
+
+; CHECK: @bar(
+define i1 @bar() {
+ ; CHECK: ret i1 true
+ %x = call i1 @llvm.type.test(ptr getelementptr ([2 x i32], ptr @b, i32 0, i32 1), metadata !"typeid1")
+ ret i1 %x
+}
diff --git a/llvm/test/Transforms/MergeFunc/
diff erent-index-width-gep-crash.ll b/llvm/test/Transforms/MergeFunc/
diff erent-index-width-gep-crash.ll
new file mode 100644
index 0000000000000..8644493a7e4e6
--- /dev/null
+++ b/llvm/test/Transforms/MergeFunc/
diff erent-index-width-gep-crash.ll
@@ -0,0 +1,13 @@
+; RUN: not --crash opt -disable-output -passes=mergefunc -S < %s
+
+target datalayout = "e-p:64:64-p2:128:128:128:32"
+
+define void @foo(ptr addrspace(2) %x) {
+ %tmp = getelementptr i32, ptr addrspace(2) %x, i32 1
+ ret void
+}
+
+define void @bar(ptr addrspace(2) %x) {
+ %tmp = getelementptr i32, ptr addrspace(2) %x, i32 1
+ ret void
+}
diff --git a/llvm/test/Transforms/MergeICmps/X86/distinct-index-width-crash.ll b/llvm/test/Transforms/MergeICmps/X86/distinct-index-width-crash.ll
new file mode 100644
index 0000000000000..78c04b48f2065
--- /dev/null
+++ b/llvm/test/Transforms/MergeICmps/X86/distinct-index-width-crash.ll
@@ -0,0 +1,32 @@
+; RUN: not --crash opt < %s -passes=mergeicmps -verify-dom-info -disable-output
+
+target triple = "x86_64"
+
+; This is very much not an x86 ABI, in current use, but we're testing
+; that we've fixed a bug where accumulateConstantOffset() was called incorrectly.
+target datalayout = "e-p:64:64:64:32"
+
+; Define a cunstom data layout that has index width < pointer width
+; and make sure that doesn't mreak anything
+define void @fat_ptrs(ptr dereferenceable(16) %a, ptr dereferenceable(16) %b) {
+bb0:
+ %ptr_a1 = getelementptr inbounds [2 x i64], ptr %a, i64 0, i64 1
+ %ptr_b1 = getelementptr inbounds [2 x i64], ptr %b, i64 0, i64 1
+ br label %bb1
+
+bb1: ; preds = %bb0
+ %a0 = load i64, ptr %a
+ %b0 = load i64, ptr %b
+ %cond0 = icmp eq i64 %a0, %b0
+ br i1 %cond0, label %bb2, label %bb3
+
+bb2: ; preds = %bb1
+ %a1 = load i64, ptr %ptr_a1
+ %b1 = load i64, ptr %ptr_b1
+ %cond1 = icmp eq i64 %a1, %b1
+ br label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ %necessary = phi i1 [ %cond1, %bb2 ], [ false, %bb1 ]
+ ret void
+}
More information about the llvm-commits
mailing list