File tree 3 files changed +41
-0
lines changed
3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,8 @@ Library improvements
74
74
* New ` ordschur ` and ` ordschur! ` functions for sorting a schur factorization by the eigenvalues.
75
75
76
76
* ` deepcopy ` recurses through immutable types and makes copies of their mutable fields ([ #8560 ] ).
77
+
78
+ * ` @simd ` now rejects invalid control flow (` @goto ` / break / continue) in the inner loop body at compile time ([ #8624 ] ).
77
79
78
80
* Givens type doesn't have a size anymore and is no longer a subtype of AbstractMatrix ([ #8660 ] )
79
81
Original file line number Diff line number Diff line change @@ -19,10 +19,26 @@ function parse_iteration_space(x)
19
19
x. args # symbol, range
20
20
end
21
21
22
+ # reject invalid control flow statements in @simd loop body
23
+ function check_body! (x:: Expr )
24
+ if x. head === :break || x. head == :continue
25
+ throw (SimdError (" $(x. head) is not allowed inside a @simd loop body" ))
26
+ elseif x. head === :macrocall && x. args[1 ] === symbol (" @goto" )
27
+ throw (SimdError (" $(x. args[1 ]) is not allowed inside a @simd loop body" ))
28
+ end
29
+ for arg in x. args
30
+ check_body! (arg)
31
+ end
32
+ return true
33
+ end
34
+ check_body! (x:: QuoteNode ) = check_body! (x. value)
35
+ check_body! (x) = true
36
+
22
37
# Compile Expr x in context of @simd.
23
38
function compile (x)
24
39
(isa (x, Expr) && x. head == :for ) || throw (SimdError (" for loop expected" ))
25
40
length (x. args) == 2 || throw (SimdError (" 1D for loop expected" ))
41
+ check_body! (x)
26
42
27
43
var,range = parse_iteration_space (x. args[1 ])
28
44
r = gensym (" r" ) # Range value
Original file line number Diff line number Diff line change @@ -67,3 +67,26 @@ let j=4
67
67
end
68
68
@test ! simd_loop_local_present
69
69
end
70
+
71
+ import Base. SimdLoop. SimdError
72
+
73
+ # Test that @simd rejects inner loop body with invalid control flow statements
74
+ # issue #8613
75
+ @test_throws SimdError eval (:(begin
76
+ @simd for x = 1 : 10
77
+ x == 1 && break
78
+ end
79
+ end ))
80
+
81
+ @test_throws SimdError eval (:(begin
82
+ @simd for x = 1 : 10
83
+ x < 5 && continue
84
+ end
85
+ end ))
86
+
87
+ @test_throws SimdError eval (:(begin
88
+ @simd for x = 1 : 10
89
+ x == 1 || @goto exit_loop
90
+ end
91
+ @label exit_loop
92
+ end ))
You can’t perform that action at this time.
0 commit comments