Skip to content

Commit 6d12617

Browse files
author
Tyler Lanphear
committed
[SLP] Precommit test demonstrating catchswitch crash.
In SLPVectorizer, when computing spill costs for a tree, we call `BasicBlock::getFirstNonPHIOrDbgOrAlloca()` without checking if its return value is an end iterator. This can occur if the basic block is a `catchswitch` block. Dereferencing this iterator in an assertions build with sentinel-tracking causes a crash. This patch commits a test which demonstrates this issue.
1 parent 6727d58 commit 6d12617

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; REQUIRES: asserts
3+
; RUN: opt -passes=slp-vectorizer -S < %s | FileCheck %s
4+
5+
; This test demonstrates a crash when trying to compute spill costs when
6+
; vectorizing a tree in a function which contains a `catchswitch` block.
7+
8+
; XFAIL: *
9+
10+
target triple = "x86_64-pc-windows-msvc19.40.33811"
11+
12+
%"class.boost::execution_exception" = type { i32, %"class.boost::unit_test::basic_cstring", %"struct.boost::execution_exception::location" }
13+
%"class.boost::unit_test::basic_cstring" = type { ptr, ptr }
14+
%"struct.boost::execution_exception::location" = type { %"class.boost::unit_test::basic_cstring", i64, %"class.boost::unit_test::basic_cstring" }
15+
16+
define void @foo() personality ptr null {
17+
; CHECK-LABEL: define void @foo() personality ptr null {
18+
; CHECK-NEXT: [[ENTRY:.*]]:
19+
; CHECK-NEXT: br label %[[FOR_COND109:.*]]
20+
; CHECK: [[FOR_COND109]]:
21+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x ptr> [ zeroinitializer, %[[ENTRY]] ], [ zeroinitializer, %[[IF_END153:.*]] ]
22+
; CHECK-NEXT: br label %[[INIT_ATTEMPT_I664:.*]]
23+
; CHECK: [[INIT_ATTEMPT_I664]]:
24+
; CHECK-NEXT: [[CALL_I666:%.*]] = invoke ptr null(ptr null)
25+
; CHECK-NEXT: to label %[[INVOKE_CONT_I668:.*]] unwind label %[[CATCH_DISPATCH:.*]]
26+
; CHECK: [[INVOKE_CONT_I668]]:
27+
; CHECK-NEXT: ret void
28+
; CHECK: [[CATCH_DISPATCH]]:
29+
; CHECK-NEXT: [[TMP1:%.*]] = catchswitch within none [label %catch] unwind to caller
30+
; CHECK: [[CATCH:.*]]:
31+
; CHECK-NEXT: [[TMP2:%.*]] = catchpad within [[TMP1]] [ptr null, i32 0, ptr null]
32+
; CHECK-NEXT: br i1 false, label %[[IF_END153]], label %[[INVOKE_CONT149:.*]]
33+
; CHECK: [[INVOKE_CONT149]]:
34+
; CHECK-NEXT: [[TMP3:%.*]] = load <2 x ptr>, ptr null, align 8
35+
; CHECK-NEXT: br label %[[IF_END153]]
36+
; CHECK: [[IF_END153]]:
37+
; CHECK-NEXT: [[TMP4:%.*]] = phi <2 x ptr> [ [[TMP0]], %[[CATCH]] ], [ [[TMP3]], %[[INVOKE_CONT149]] ]
38+
; CHECK-NEXT: catchret from [[TMP2]] to label %[[FOR_COND109]]
39+
;
40+
entry:
41+
br label %for.cond109
42+
43+
for.cond109: ; preds = %if.end153, %entry
44+
%setup_error.sroa.0.1 = phi ptr [ null, %entry ], [ null, %if.end153 ]
45+
%setup_error.sroa.6.1 = phi ptr [ null, %entry ], [ null, %if.end153 ]
46+
br label %init.attempt.i664
47+
48+
init.attempt.i664: ; preds = %for.cond109
49+
%call.i666 = invoke ptr null(ptr null)
50+
to label %invoke.cont.i668 unwind label %catch.dispatch
51+
52+
invoke.cont.i668: ; preds = %init.attempt.i664
53+
ret void
54+
55+
catch.dispatch: ; preds = %init.attempt.i664
56+
%0 = catchswitch within none [label %catch] unwind to caller
57+
58+
catch: ; preds = %catch.dispatch
59+
%1 = catchpad within %0 [ptr null, i32 0, ptr null]
60+
br i1 false, label %if.end153, label %invoke.cont149
61+
62+
invoke.cont149: ; preds = %catch
63+
%m_begin2.i.i = getelementptr %"class.boost::execution_exception", ptr null, i64 0, i32 1, i32 0
64+
%2 = load ptr, ptr %m_begin2.i.i, align 8
65+
%3 = load ptr, ptr null, align 8
66+
br label %if.end153
67+
68+
if.end153: ; preds = %invoke.cont149, %catch
69+
%setup_error.sroa.0.2 = phi ptr [ %setup_error.sroa.0.1, %catch ], [ %2, %invoke.cont149 ]
70+
%setup_error.sroa.6.2 = phi ptr [ %setup_error.sroa.6.1, %catch ], [ %3, %invoke.cont149 ]
71+
catchret from %1 to label %for.cond109
72+
}

0 commit comments

Comments
 (0)