mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
fix alignment of consts
This commit is contained in:
parent
eb8a132d23
commit
b6108eed52
@ -1,7 +1,6 @@
|
||||
Scratch pad for stuff to do before merging master
|
||||
=================================================
|
||||
|
||||
* alignment of consts
|
||||
* implicit casts
|
||||
* for loops
|
||||
* switch expression
|
||||
|
||||
@ -292,6 +292,7 @@ struct RuntimeHintSlice {
|
||||
struct ConstGlobalRefs {
|
||||
LLVMValueRef llvm_value;
|
||||
LLVMValueRef llvm_global;
|
||||
uint32_t align;
|
||||
};
|
||||
|
||||
struct ConstExprValue {
|
||||
|
||||
@ -6599,7 +6599,8 @@ static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const
|
||||
LLVMSetLinkage(global_value, LLVMInternalLinkage);
|
||||
LLVMSetGlobalConstant(global_value, true);
|
||||
LLVMSetUnnamedAddr(global_value, true);
|
||||
LLVMSetAlignment(global_value, get_abi_alignment(g, const_val->type));
|
||||
LLVMSetAlignment(global_value, (const_val->global_refs->align == 0) ?
|
||||
get_abi_alignment(g, const_val->type) : const_val->global_refs->align);
|
||||
|
||||
const_val->global_refs->llvm_global = global_value;
|
||||
}
|
||||
|
||||
21
src/ir.cpp
21
src/ir.cpp
@ -14363,19 +14363,22 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z
|
||||
IrInstructionAllocaSrc *alloca_src =
|
||||
reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
|
||||
if (alloca_src->base.child == nullptr) {
|
||||
bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime &&
|
||||
result_loc_var->var->gen_is_const;
|
||||
bool force_comptime;
|
||||
if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
|
||||
return ira->codegen->invalid_instruction;
|
||||
bool is_comptime = force_comptime || (value != nullptr &&
|
||||
value->value.special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
|
||||
uint32_t align = 0;
|
||||
if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) {
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
IrInstruction *alloca_gen;
|
||||
if (is_comptime) {
|
||||
if (align > value->value.global_refs->align) {
|
||||
value->value.global_refs->align = align;
|
||||
}
|
||||
alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
|
||||
} else {
|
||||
uint32_t align = 0;
|
||||
if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) {
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
bool force_comptime;
|
||||
if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
|
||||
return ira->codegen->invalid_instruction;
|
||||
alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
|
||||
alloca_src->name_hint, force_comptime);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user