stage2: make anyopaque sized

While this is technically incorrect, proper handling of anyopaque, as well
as regular opaque, is probably best left until pointers to zero-sized types
having no bits is abolished.
This commit is contained in:
Robin Voetter
2021-12-20 03:58:19 +01:00
parent c47ed0c912
commit 58d67a6718
2 changed files with 17 additions and 13 deletions

View File

@@ -761,21 +761,25 @@ pub const DeclGen = struct {
dg.context.intType(8);
return llvm_elem_ty.pointerType(llvm_addrspace);
},
.Opaque => {
const gop = try dg.object.type_map.getOrPut(gpa, t);
if (gop.found_existing) return gop.value_ptr.*;
.Opaque => switch (t.tag()) {
.@"opaque" => {
const gop = try dg.object.type_map.getOrPut(gpa, t);
if (gop.found_existing) return gop.value_ptr.*;
// The Type memory is ephemeral; since we want to store a longer-lived
// reference, we need to copy it here.
gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
// The Type memory is ephemeral; since we want to store a longer-lived
// reference, we need to copy it here.
gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
const opaque_obj = t.castTag(.@"opaque").?.data;
const name = try opaque_obj.getFullyQualifiedName(gpa);
defer gpa.free(name);
const opaque_obj = t.castTag(.@"opaque").?.data;
const name = try opaque_obj.getFullyQualifiedName(gpa);
defer gpa.free(name);
const llvm_struct_ty = dg.context.structCreateNamed(name);
gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
return llvm_struct_ty;
const llvm_struct_ty = dg.context.structCreateNamed(name);
gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
return llvm_struct_ty;
},
.anyopaque => return dg.context.intType(8),
else => unreachable,
},
.Array => {
const elem_type = try dg.llvmType(t.childType());

View File

@@ -1575,6 +1575,7 @@ pub const Type = extern union {
.extern_options,
.@"anyframe",
.anyframe_T,
.anyopaque,
.@"opaque",
.single_const_pointer,
.single_mut_pointer,
@@ -1654,7 +1655,6 @@ pub const Type = extern union {
return payload.error_set.hasCodeGenBits() or payload.payload.hasCodeGenBits();
},
.anyopaque,
.void,
.type,
.comptime_int,