aboutsummaryrefslogtreecommitdiff
path: root/src/Value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-09-06 11:42:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-09-20 18:33:00 -0700
commit7b8a7989ef54b7ac859035cbc603b8012f8f4102 (patch)
tree64a847caaa2d1808bb0718ad9025d9c84ff5af0a /src/Value.zig
parent2fdf0e29b380cdd891797d642894dd58fd66fd1d (diff)
downloadzig-7b8a7989ef54b7ac859035cbc603b8012f8f4102.tar.gz
zig-7b8a7989ef54b7ac859035cbc603b8012f8f4102.zip
frontend: additionally handle C pointers in ptrOptPayload
Diffstat (limited to 'src/Value.zig')
-rw-r--r--src/Value.zig12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/Value.zig b/src/Value.zig
index f2516d53bd..b3271d85cb 100644
--- a/src/Value.zig
+++ b/src/Value.zig
@@ -2149,15 +2149,18 @@ pub fn makeBool(x: bool) Value {
return if (x) .true else .false;
}
-/// `parent_ptr` must be a single-pointer to some optional.
+/// `parent_ptr` must be a single-pointer or C pointer to some optional.
+///
/// Returns a pointer to the payload of the optional.
+///
/// May perform type resolution.
pub fn ptrOptPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
const zcu = pt.zcu;
const parent_ptr_ty = parent_ptr.typeOf(zcu);
const opt_ty = parent_ptr_ty.childType(zcu);
+ const ptr_size = parent_ptr_ty.ptrSize(zcu);
- assert(parent_ptr_ty.ptrSize(zcu) == .one);
+ assert(ptr_size == .one or ptr_size == .c);
assert(opt_ty.zigTypeTag(zcu) == .optional);
const result_ty = try pt.ptrTypeSema(info: {
@@ -2212,9 +2215,12 @@ pub fn ptrEuPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
} }));
}
-/// `parent_ptr` must be a single-pointer to a struct, union, or slice.
+/// `parent_ptr` must be a single-pointer or c pointer to a struct, union, or slice.
+///
/// Returns a pointer to the aggregate field at the specified index.
+///
/// For slices, uses `slice_ptr_index` and `slice_len_index`.
+///
/// May perform type resolution.
pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
const zcu = pt.zcu;