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
signature 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 @@
11Scratch pad for stuff to do before merging master
22=================================================
33
4 * alignment of consts
54 * implicit casts
65 * for loops
76 * switch expression
src/all_types.hpp+1
......@@ -292,6 +292,7 @@ struct RuntimeHintSlice {
292292struct ConstGlobalRefs {
293293 LLVMValueRef llvm_value;
294294 LLVMValueRef llvm_global;
295 uint32_t align;
295296};
296297
297298struct ConstExprValue {
src/codegen.cpp+2-1
......@@ -6599,7 +6599,8 @@ static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const
65996599 LLVMSetLinkage(global_value, LLVMInternalLinkage);
66006600 LLVMSetGlobalConstant(global_value, true);
66016601 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
66046605 const_val->global_refs->llvm_global = global_value;
66056606 }
src/ir.cpp+12-9
......@@ -14363,19 +14363,22 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z
1436314363 IrInstructionAllocaSrc *alloca_src =
1436414364 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
1436514365 if (alloca_src->base.child == nullptr) {
14366 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime &&
14367 result_loc_var->var->gen_is_const;
14366 bool force_comptime;
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 }
1436814375 IrInstruction *alloca_gen;
1436914376 if (is_comptime) {
14377 if (align > value->value.global_refs->align) {
14378 value->value.global_refs->align = align;
14379 }
1437014380 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
1437114381 } 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;
1437914382 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
1438014383 alloca_src->name_hint, force_comptime);
1438114384 }