diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2744a0e97..57e064de7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -216,7 +216,7 @@ jobs: fail-fast: false matrix: build_type: [Release, Debug] - llvm_version: [17, 18, 19, 20] + llvm_version: [17, 18, 19] steps: - uses: actions/checkout@v4 @@ -496,7 +496,7 @@ jobs: matrix: ubuntu_version: [20.04, 22.04] build_type: [Release, Debug] - llvm_version: [17, 18, 19, 20] + llvm_version: [17, 18, 19] steps: - uses: actions/checkout@v4 diff --git a/releasenotes.md b/releasenotes.md index 7690e3ed4..7fc411ddd 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -10,6 +10,7 @@ - Generic methods were incorrectly registered as functions, leading to naming collisions. #1402 - Deprecated inline generic types. - Deprecated tuple / triple types. +- Converting a slice to a vector/array would copy too little data. ### Stdlib changes *None yet* diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index c8ee6bd6c..cf3199e99 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -1277,9 +1277,7 @@ void llvm_emit_slice_to_vec_array_cast(GenContext *c, BEValue *value, Type *to_t LLVMTypeRef type = llvm_get_type(c, to_type); AlignSize alignment = llvm_abi_alignment(c, type); LLVMValueRef temp = llvm_emit_alloca(c, type, alignment, ".temp"); - unsigned elements = LLVMGetTypeKind(type) == LLVMVectorTypeKind - ? LLVMGetVectorSize(type) : LLVMGetArrayLength(type); - llvm_emit_memcpy(c, temp, alignment, pointer.value, element_alignment, elements); + llvm_emit_memcpy(c, temp, alignment, pointer.value, element_alignment, llvm_abi_size(c, type)); llvm_value_set_address(value, temp, to_type, alignment); } diff --git a/test/unit/regression/vector_conversion.c3 b/test/unit/regression/vector_conversion.c3 index 1e8dce393..106e0aec4 100644 --- a/test/unit/regression/vector_conversion.c3 +++ b/test/unit/regression/vector_conversion.c3 @@ -16,6 +16,13 @@ fn void vector_array_inferred() assert(w == int[<2>] { 4, 7 }); } +fn void vector_convert_slice() +{ + int[<2>] x = { 1, 2 }; + int[2] y = { 4, 4 }; + x *= y[:2]; + assert(x == { 4, 8 }); +} fn void vector_convert_bool() { bool[<2>] a = { true, false };