aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-17 17:33:44 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-03-19 09:53:54 -0400
commit8d0ac6dc4d32daea3561e7de8eeee9ce34d2c5cb (patch)
tree3c0b0da0ab8562da8899417bef24726407667b07 /src/analyze.cpp
parentc896c5001f55c67ba2379505464f85dcabb3f3f2 (diff)
downloadzig-8d0ac6dc4d32daea3561e7de8eeee9ce34d2c5cb.tar.gz
zig-8d0ac6dc4d32daea3561e7de8eeee9ce34d2c5cb.zip
`@ptrCast` supports casting a slice to pointer
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index afffe47c82..1f511fa834 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -4486,7 +4486,14 @@ static uint32_t get_async_frame_align_bytes(CodeGen *g) {
}
uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
- ZigType *ptr_type = get_src_ptr_type(type);
+ ZigType *ptr_type;
+ if (type->id == ZigTypeIdStruct) {
+ assert(type->data.structure.special == StructSpecialSlice);
+ TypeStructField *ptr_field = type->data.structure.fields[slice_ptr_index];
+ ptr_type = resolve_struct_field_type(g, ptr_field);
+ } else {
+ ptr_type = get_src_ptr_type(type);
+ }
if (ptr_type->id == ZigTypeIdPointer) {
return (ptr_type->data.pointer.explicit_alignment == 0) ?
get_abi_alignment(g, ptr_type->data.pointer.child_type) : ptr_type->data.pointer.explicit_alignment;
@@ -4503,8 +4510,15 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
}
}
-bool get_ptr_const(ZigType *type) {
- ZigType *ptr_type = get_src_ptr_type(type);
+bool get_ptr_const(CodeGen *g, ZigType *type) {
+ ZigType *ptr_type;
+ if (type->id == ZigTypeIdStruct) {
+ assert(type->data.structure.special == StructSpecialSlice);
+ TypeStructField *ptr_field = type->data.structure.fields[slice_ptr_index];
+ ptr_type = resolve_struct_field_type(g, ptr_field);
+ } else {
+ ptr_type = get_src_ptr_type(type);
+ }
if (ptr_type->id == ZigTypeIdPointer) {
return ptr_type->data.pointer.is_const;
} else if (ptr_type->id == ZigTypeIdFn) {