authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-06 11:42:22-07:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-21 21:08:52+02:00
log670c4fae617af3a7cfbdfcd850b65d61b94d1cf8
tree3aad1537a4a2016c57e15257b65fd55df5db354f
parent4d102751b6346cf614699f0a830fb5a2c1ee9f66
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

frontend: additionally handle C pointers in ptrOptPayload


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

src/Value.zig+9-3
...@@ -2149,15 +2149,18 @@ pub fn makeBool(x: bool) Value {...@@ -2149,15 +2149,18 @@ pub fn makeBool(x: bool) Value {
2149 return if (x) .true else .false;2149 return if (x) .true else .false;
2150}2150}
21512151
2152/// `parent_ptr` must be a single-pointer to some optional.2152/// `parent_ptr` must be a single-pointer or C pointer to some optional.
2153///
2153/// Returns a pointer to the payload of the optional.2154/// Returns a pointer to the payload of the optional.
2155///
2154/// May perform type resolution.2156/// May perform type resolution.
2155pub fn ptrOptPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {2157pub fn ptrOptPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
2156 const zcu = pt.zcu;2158 const zcu = pt.zcu;
2157 const parent_ptr_ty = parent_ptr.typeOf(zcu);2159 const parent_ptr_ty = parent_ptr.typeOf(zcu);
2158 const opt_ty = parent_ptr_ty.childType(zcu);2160 const opt_ty = parent_ptr_ty.childType(zcu);
2161 const ptr_size = parent_ptr_ty.ptrSize(zcu);
21592162
2160 assert(parent_ptr_ty.ptrSize(zcu) == .one);2163 assert(ptr_size == .one or ptr_size == .c);
2161 assert(opt_ty.zigTypeTag(zcu) == .optional);2164 assert(opt_ty.zigTypeTag(zcu) == .optional);
21622165
2163 const result_ty = try pt.ptrTypeSema(info: {2166 const result_ty = try pt.ptrTypeSema(info: {
...@@ -2212,9 +2215,12 @@ pub fn ptrEuPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {...@@ -2212,9 +2215,12 @@ pub fn ptrEuPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
2212 } }));2215 } }));
2213}2216}
22142217
2215/// `parent_ptr` must be a single-pointer to a struct, union, or slice.2218/// `parent_ptr` must be a single-pointer or c pointer to a struct, union, or slice.
2219///
2216/// Returns a pointer to the aggregate field at the specified index.2220/// Returns a pointer to the aggregate field at the specified index.
2221///
2217/// For slices, uses `slice_ptr_index` and `slice_len_index`.2222/// For slices, uses `slice_ptr_index` and `slice_len_index`.
2223///
2218/// May perform type resolution.2224/// May perform type resolution.
2219pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {2225pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
2220 const zcu = pt.zcu;2226 const zcu = pt.zcu;