aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-25 22:23:32 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-05-25 22:33:48 -0700
commit83f69af971723d3a0774deb9dfda4b3fcbf0006f (patch)
treeba516b2bdd17b1492c6764dd1cc6bbd198cea853 /src/codegen/llvm.zig
parentb82081e7092a6198e6f8c65524a5829e2e08527b (diff)
downloadzig-83f69af971723d3a0774deb9dfda4b3fcbf0006f.tar.gz
zig-83f69af971723d3a0774deb9dfda4b3fcbf0006f.zip
stage2: implement runtime array multiplication
Additionally: * Sema: fix array cat/mul not setting the sentinel value - This required an LLVM backend enhancement to the handling of the AIR instruction aggregate_init that likely needs to be propagated to the other backends. * Sema: report integer overflow of array concatenation in a proper compile error instead of crashing. * Sema: fix not using proper pointer address space for array cat/mul
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index ec71297c10..f958fdfbb3 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -7728,7 +7728,14 @@ pub const FuncGen = struct {
const alloca_inst = self.buildAlloca(llvm_result_ty);
alloca_inst.setAlignment(result_ty.abiAlignment(target));
- const elem_ty = result_ty.childType();
+ const array_info = result_ty.arrayInfo();
+ var elem_ptr_payload: Type.Payload.Pointer = .{
+ .data = .{
+ .pointee_type = array_info.elem_type,
+ .@"addrspace" = .generic,
+ },
+ };
+ const elem_ptr_ty = Type.initPayload(&elem_ptr_payload.base);
for (elements) |elem, i| {
const indices: [2]*const llvm.Value = .{
@@ -7737,13 +7744,19 @@ pub const FuncGen = struct {
};
const elem_ptr = self.builder.buildInBoundsGEP(alloca_inst, &indices, indices.len, "");
const llvm_elem = try self.resolveInst(elem);
- var elem_ptr_payload: Type.Payload.Pointer = .{
- .data = .{
- .pointee_type = elem_ty,
- .@"addrspace" = .generic,
- },
+ self.store(elem_ptr, elem_ptr_ty, llvm_elem, .NotAtomic);
+ }
+ if (array_info.sentinel) |sent_val| {
+ const indices: [2]*const llvm.Value = .{
+ llvm_usize.constNull(),
+ llvm_usize.constInt(@intCast(c_uint, array_info.len), .False),
};
- const elem_ptr_ty = Type.initPayload(&elem_ptr_payload.base);
+ const elem_ptr = self.builder.buildInBoundsGEP(alloca_inst, &indices, indices.len, "");
+ const llvm_elem = try self.dg.lowerValue(.{
+ .ty = array_info.elem_type,
+ .val = sent_val,
+ });
+
self.store(elem_ptr, elem_ptr_ty, llvm_elem, .NotAtomic);
}