mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
migrate make_ptr_const to new anonymous decl mechanism
Instead of creating Module.Decl objects, directly create InternPool pointer values using the anon_decl Addr encoding. The LLVM backend needed code to notice the alignment of the pointer and lower accordingly. The other backends likely need a similar change.
This commit is contained in:
parent
3cd3052d4d
commit
ecfb18286a
5 changed files with 18 additions and 16 deletions
|
|
@ -3657,9 +3657,10 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
|
|||
const elem_ty = ptr_info.child.toType();
|
||||
|
||||
if (try sema.resolveComptimeKnownAllocValue(block, alloc, null)) |val| {
|
||||
var anon_decl = try block.startAnonDecl();
|
||||
defer anon_decl.deinit();
|
||||
const new_mut_ptr = try sema.analyzeDeclRef(try anon_decl.finish(elem_ty, val.toValue(), ptr_info.flags.alignment));
|
||||
const new_mut_ptr = Air.internedToRef((try mod.intern(.{ .ptr = .{
|
||||
.ty = alloc_ty.toIntern(),
|
||||
.addr = .{ .anon_decl = val },
|
||||
} })));
|
||||
return sema.makePtrConst(block, new_mut_ptr);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3049,6 +3049,7 @@ pub const Object = struct {
|
|||
o: *Object,
|
||||
decl_val: InternPool.Index,
|
||||
llvm_addr_space: Builder.AddrSpace,
|
||||
alignment: InternPool.Alignment,
|
||||
) Error!Builder.Variable.Index {
|
||||
// TODO: Add address space to the anon_decl_map
|
||||
const gop = try o.anon_decl_map.getOrPut(o.gpa, decl_val);
|
||||
|
|
@ -3068,6 +3069,8 @@ pub const Object = struct {
|
|||
try variable_index.setInitializer(try o.lowerValue(decl_val), &o.builder);
|
||||
variable_index.setLinkage(.internal, &o.builder);
|
||||
variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
|
||||
if (alignment != .none)
|
||||
variable_index.setAlignment(alignment.toLlvm(), &o.builder);
|
||||
return variable_index;
|
||||
}
|
||||
|
||||
|
|
@ -4415,7 +4418,8 @@ pub const Object = struct {
|
|||
|
||||
const addr_space = target_util.defaultAddressSpace(target, .global_constant);
|
||||
const llvm_addr_space = toLlvmAddressSpace(addr_space, target);
|
||||
const llvm_global = (try o.resolveGlobalAnonDecl(decl_val, llvm_addr_space)).ptrConst(&o.builder).global;
|
||||
const alignment = ptr_ty.ptrAlignment(mod);
|
||||
const llvm_global = (try o.resolveGlobalAnonDecl(decl_val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
|
||||
|
||||
const llvm_val = try o.builder.convConst(
|
||||
.unneeded,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ test {
|
|||
_ = @import("behavior/bugs/1500.zig");
|
||||
_ = @import("behavior/bugs/1607.zig");
|
||||
_ = @import("behavior/bugs/1735.zig");
|
||||
_ = @import("behavior/bugs/1741.zig");
|
||||
_ = @import("behavior/bugs/1851.zig");
|
||||
_ = @import("behavior/bugs/1914.zig");
|
||||
_ = @import("behavior/bugs/2006.zig");
|
||||
|
|
|
|||
|
|
@ -15,6 +15,15 @@ test "global variable alignment" {
|
|||
}
|
||||
}
|
||||
|
||||
test "large alignment of local constant" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // flaky
|
||||
|
||||
const x: f32 align(128) = 12.34;
|
||||
try std.testing.expect(@intFromPtr(&x) % 128 == 0);
|
||||
}
|
||||
|
||||
test "slicing array of length 1 can not assume runtime index is always zero" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
test "fixed" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // flaky
|
||||
|
||||
const x: f32 align(128) = 12.34;
|
||||
try std.testing.expect(@intFromPtr(&x) % 128 == 0);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue