Odin
Odin copied to clipboard
Switch crashes compiler if both u8 and byte cases are used
Context
The following code crashes the compiler
import "core:runtime"
f :: proc(ti: ^runtime.Type_Info) -> bool {
switch ti.id {
case u8: return true
case byte: return false
case: return true
}
}
main :: proc() {
f(type_info_of(int))
}
Odin: dev-2022-08:c041d155
OS: Windows 10 Home Basic, build 18363.1556
CPU: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
RAM: 16244 MiB
Expected Behavior
Either an error if this is not allowed, or for this behavior to work.
Current Behavior
The compiler crashes without a good user-facing error.
Failure Logs
LLVM CODE GEN FAILED FOR PROCEDURE: wasm_bindgen.f
define internal i8 @wasm_bindgen.f(%runtime.Type_Info* %0, i8* noalias nocapture nonnull %__.context_ptr) {
decls:
%1 = alloca %runtime.Type_Info*, align 8
br label %entry
entry: ; preds = %decls
store %runtime.Type_Info* %0, %runtime.Type_Info** %1, align 8
%2 = bitcast i8* %__.context_ptr to %runtime.Context*
%3 = load %runtime.Type_Info*, %runtime.Type_Info** %1, align 8
%4 = getelementptr inbounds %runtime.Type_Info, %runtime.Type_Info* %3, i32 0, i32 4
%5 = load i64, i64* %4, align 8
switch i64 %5, label %switch.default.body [
i64 72057594037927950, label %switch.case.body
i64 72057594037927950, label %switch.case.body1
]
switch.case.body: ; preds = %entry
ret i8 1
switch.case.body1: ; preds = %entry
ret i8 0
switch.default.body: ; preds = %entry
ret i8 1
switch.done: ; No predecessors!
unreachable
}
Duplicate integer as switch case
switch i64 %5, label %switch.default.body [
i64 72057594037927950, label %switch.case.body
i64 72057594037927950, label %switch.case.body1
]
i64 72057594037927950
ran into this today as well. V2 ::[2]f32 i am only adding to the issue in that the error is a bit obtuse, i removed v2 and im good for my code.
switch member.type {
//cases
case V2, [2]f32:
//...
case:
}
[error] LLVM Error: Duplicate integer as switch case switch i64 %79, label %switch.default.body [ i64 504403158265495591, label %switch.case.body i64 4683743612465315843, label %switch.case.body1 i64 4683743612465315876, label %switch.case.body1 i64 72057594037928055, label %switch.case.body2 i64 72057594037927952, label %switch.case.body2 i64 216172782113783818, label %switch.case.body3 i64 216172782113783945, label %switch.case.body3 i64 936748722493063330, label %switch.case.body4 i64 936748722493063330, label %switch.case.body4 ], !dbg !13523 i64 936748722493063330