authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-03 19:11:41-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-03 19:11:41-04:00
logb6108eed522b7a0122d305dc1a74de8f12f20d5b
tree156392d4f61f4afa193c67606673fa789a62657b
parenteb8a132d23c5c2a365eb3a8034a381cb74c3436c
signaturelock-open Commit is signed but in an unrecognized format.

fix alignment of consts


4 files changed, 15 insertions(+), 11 deletions(-)

BRANCH_TODO-1
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1Scratch pad for stuff to do before merging master1Scratch pad for stuff to do before merging master
2=================================================2=================================================
33
4 * alignment of consts
5 * implicit casts4 * implicit casts
6 * for loops5 * for loops
7 * switch expression6 * switch expression
src/all_types.hpp+1
...@@ -292,6 +292,7 @@ struct RuntimeHintSlice {...@@ -292,6 +292,7 @@ struct RuntimeHintSlice {
292struct ConstGlobalRefs {292struct ConstGlobalRefs {
293 LLVMValueRef llvm_value;293 LLVMValueRef llvm_value;
294 LLVMValueRef llvm_global;294 LLVMValueRef llvm_global;
295 uint32_t align;
295};296};
296297
297struct ConstExprValue {298struct ConstExprValue {
src/codegen.cpp+2-1
...@@ -6599,7 +6599,8 @@ static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const...@@ -6599,7 +6599,8 @@ static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const
6599 LLVMSetLinkage(global_value, LLVMInternalLinkage);6599 LLVMSetLinkage(global_value, LLVMInternalLinkage);
6600 LLVMSetGlobalConstant(global_value, true);6600 LLVMSetGlobalConstant(global_value, true);
6601 LLVMSetUnnamedAddr(global_value, true);6601 LLVMSetUnnamedAddr(global_value, true);
6602 LLVMSetAlignment(global_value, get_abi_alignment(g, const_val->type));6602 LLVMSetAlignment(global_value, (const_val->global_refs->align == 0) ?
6603 get_abi_alignment(g, const_val->type) : const_val->global_refs->align);
66036604
6604 const_val->global_refs->llvm_global = global_value;6605 const_val->global_refs->llvm_global = global_value;
6605 }6606 }
src/ir.cpp+12-9
...@@ -14363,19 +14363,22 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z...@@ -14363,19 +14363,22 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z
14363 IrInstructionAllocaSrc *alloca_src =14363 IrInstructionAllocaSrc *alloca_src =
14364 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);14364 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
14365 if (alloca_src->base.child == nullptr) {14365 if (alloca_src->base.child == nullptr) {
14366 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime &&14366 bool force_comptime;
14367 result_loc_var->var->gen_is_const;14367 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
14368 return ira->codegen->invalid_instruction;
14369 bool is_comptime = force_comptime || (value != nullptr &&
14370 value->value.special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
14371 uint32_t align = 0;
14372 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) {
14373 return ira->codegen->invalid_instruction;
14374 }
14368 IrInstruction *alloca_gen;14375 IrInstruction *alloca_gen;
14369 if (is_comptime) {14376 if (is_comptime) {
14377 if (align > value->value.global_refs->align) {
14378 value->value.global_refs->align = align;
14379 }
14370 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);14380 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
14371 } else {14381 } else {
14372 uint32_t align = 0;
14373 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) {
14374 return ira->codegen->invalid_instruction;
14375 }
14376 bool force_comptime;
14377 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
14378 return ira->codegen->invalid_instruction;
14379 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,14382 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
14380 alloca_src->name_hint, force_comptime);14383 alloca_src->name_hint, force_comptime);
14381 }14384 }