Skip to content

Commit 4171256

Browse files
committed
use contains_is and also guard against invalid ::Int argument
1 parent 0141925 commit 4171256

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

Compiler/src/optimize.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,19 +1008,11 @@ matchpass(::Nothing, _, _) = false
10081008
function run_passes_ipo_safe(
10091009
ci::CodeInfo,
10101010
sv::OptimizationState,
1011-
optimize_until::Union{Nothing, Int, String} = nothing, # run all passes by default
1012-
)
1013-
if optimize_until isa String
1014-
found_pass = false
1015-
for pass in ALL_PASS_NAMES
1016-
if optimize_until == pass
1017-
found_pass = true
1018-
break
1019-
end
1020-
end
1021-
if !found_pass
1022-
error("invalid `optimize_until` argument, no such optimization pass")
1023-
end
1011+
optimize_until::Union{Nothing, Int, String} = nothing) # run all passes by default
1012+
if optimize_until isa String && !contains_is(ALL_PASS_NAMES, optimize_until)
1013+
error("invalid `optimize_until` argument, no such optimization pass")
1014+
elseif optimize_until isa Int && (optimize_until < 1 || optimize_until > length(ALL_PASS_NAMES))
1015+
error("invalid `optimize_until` argument, no such optimization pass")
10241016
end
10251017

10261018
__stage__ = 0 # used by @pass

Compiler/test/ssair.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,4 @@ let cl = Int32[32, 1, 1, 1000, 240, 230]
823823
end
824824

825825
@test_throws ErrorException Base.code_ircode(+, (Float64, Float64); optimize_until = "nonexisting pass name")
826+
@test_throws ErrorException Base.code_ircode(+, (Float64, Float64); optimize_until = typemax(Int))

0 commit comments

Comments
 (0)