Skip to content

Commit

Permalink
Assertion failed when casting argument to enum #1196
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed May 16, 2024
1 parent c40c933 commit 97c9bd7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Casting a slice address to its pointer type should not compile #1193.
- Union is not properly zero-initialized with designated initializer #1194.
- Compile time fmod evaluates to 0 #1195.
- Assertion failed when casting (unsigned) argument to enum #1196

### Stdlib changes
- Add 'zstr' variants for `string::new_format` / `string::tformat`.
Expand Down
1 change: 1 addition & 0 deletions src/compiler/llvm_codegen_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ void llvm_emit_cast(GenContext *c, CastKind cast_kind, Expr *expr, BEValue *valu
llvm_value_set(value, llvm_zext_trunc(c, value->value, llvm_get_type(c, to_type)), to_type);
return;
}
value->type = type_lowering(to_type);
return;
case CAST_SABOOL:
llvm_value_fold_optional(c, value);
Expand Down
27 changes: 27 additions & 0 deletions test/test_suite/enumerations/enum_signed_cast_swap.c3t
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// #target: macos-x64
module test;
enum Abc : char { ABC }

enum Mouse_Button {
LEFT,
RIGHT,
MIDDLE,
}

fn void foo(Mouse_Button button)
{
}

fn int main() {
uint x = 1;
foo((Mouse_Button)x);
return 0;
}

/* #expect: test.ll

%x = alloca i32, align 4
store i32 1, ptr %x, align 4
%0 = load i32, ptr %x, align 4
call void @test.foo(i32 %0)
ret i32 0

0 comments on commit 97c9bd7

Please sign in to comment.