authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-27 00:23:43+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-27 01:31:18+03:00
logf3a3fb3d880528e8b6404648c605ed092ef1412c
tree057fc8501bee11acfed485d49dfe52accb86aa7e
parent595ccecd88d82874e7f677ee1809c04fc29424ff

llvm: pass optional slices like regular slices


1 files changed, 10 insertions(+), 3 deletions(-)

src/codegen/llvm.zig+10-3
...@@ -1027,7 +1027,9 @@ pub const Object = struct {...@@ -1027,7 +1027,9 @@ pub const Object = struct {
1027 dg.addArgAttr(llvm_func, llvm_arg_i, "noalias");1027 dg.addArgAttr(llvm_func, llvm_arg_i, "noalias");
1028 }1028 }
1029 }1029 }
1030 dg.addArgAttr(llvm_func, llvm_arg_i, "nonnull");1030 if (param_ty.zigTypeTag() != .Optional) {
1031 dg.addArgAttr(llvm_func, llvm_arg_i, "nonnull");
1032 }
1031 if (!ptr_info.mutable) {1033 if (!ptr_info.mutable) {
1032 dg.addArgAttr(llvm_func, llvm_arg_i, "readonly");1034 dg.addArgAttr(llvm_func, llvm_arg_i, "readonly");
1033 }1035 }
...@@ -3117,7 +3119,11 @@ pub const DeclGen = struct {...@@ -3117,7 +3119,11 @@ pub const DeclGen = struct {
3117 .slice => {3119 .slice => {
3118 const param_ty = fn_info.param_types[it.zig_index - 1];3120 const param_ty = fn_info.param_types[it.zig_index - 1];
3119 var buf: Type.SlicePtrFieldTypeBuffer = undefined;3121 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
3120 const ptr_ty = param_ty.slicePtrFieldType(&buf);3122 var opt_buf: Type.Payload.ElemType = undefined;
3123 const ptr_ty = if (param_ty.zigTypeTag() == .Optional)
3124 param_ty.optionalChild(&opt_buf).slicePtrFieldType(&buf)
3125 else
3126 param_ty.slicePtrFieldType(&buf);
3121 const ptr_llvm_ty = try dg.lowerType(ptr_ty);3127 const ptr_llvm_ty = try dg.lowerType(ptr_ty);
3122 const len_llvm_ty = try dg.lowerType(Type.usize);3128 const len_llvm_ty = try dg.lowerType(Type.usize);
31233129
...@@ -10358,7 +10364,8 @@ const ParamTypeIterator = struct {...@@ -10358,7 +10364,8 @@ const ParamTypeIterator = struct {
10358 .Unspecified, .Inline => {10364 .Unspecified, .Inline => {
10359 it.zig_index += 1;10365 it.zig_index += 1;
10360 it.llvm_index += 1;10366 it.llvm_index += 1;
10361 if (ty.isSlice()) {10367 var buf: Type.Payload.ElemType = undefined;
10368 if (ty.isSlice() or (ty.zigTypeTag() == .Optional and ty.optionalChild(&buf).isSlice())) {
10362 return .slice;10369 return .slice;
10363 } else if (isByRef(ty)) {10370 } else if (isByRef(ty)) {
10364 return .byref;10371 return .byref;