Browse Source

Fix pseudo-constant local slice initialization

gingerBill 4 years ago
parent
commit
c5c82e0551
1 changed files with 8 additions and 7 deletions
  1. 8 7
      src/llvm_backend.cpp

+ 8 - 7
src/llvm_backend.cpp

@@ -6079,16 +6079,17 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 				return res;
 				return res;
 			} else {
 			} else {
 				// TODO(bill): THIS IS HACK BUT IT WORKS FOR WHAT I NEED
 				// TODO(bill): THIS IS HACK BUT IT WORKS FOR WHAT I NEED
+				LLVMValueRef *old_values = values;
 				LLVMValueRef *new_values = gb_alloc_array(temporary_allocator(), LLVMValueRef, value_count);
 				LLVMValueRef *new_values = gb_alloc_array(temporary_allocator(), LLVMValueRef, value_count);
 				for (isize i = 0; i < value_count; i++) {
 				for (isize i = 0; i < value_count; i++) {
-					LLVMValueRef val = values[i];
-					if (LLVMIsConstant(val)) {
-						new_values[i] = val;
+					LLVMValueRef old_value = old_values[i];
+					if (LLVMIsConstant(old_value)) {
+						new_values[i] = old_value;
 					} else {
 					} else {
-						values[i] = lb_const_nil(m, get_struct_field_type(type, i-offset)).value;
+						new_values[i] = LLVMConstNull(LLVMTypeOf(old_value));
 					}
 					}
 				}
 				}
-				LLVMValueRef constant_value = llvm_const_named_struct(lb_type(m, original_type), values, cast(unsigned)value_count);
+				LLVMValueRef constant_value = llvm_const_named_struct(lb_type(m, original_type), new_values, cast(unsigned)value_count);
 
 
 
 
 				GB_ASSERT(is_local);
 				GB_ASSERT(is_local);
@@ -6096,10 +6097,10 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 				lbAddr v = lb_add_local_generated(p, res.type, true);
 				lbAddr v = lb_add_local_generated(p, res.type, true);
 				LLVMBuildStore(p->builder, constant_value, v.addr.value);
 				LLVMBuildStore(p->builder, constant_value, v.addr.value);
 				for (isize i = 0; i < value_count; i++) {
 				for (isize i = 0; i < value_count; i++) {
-					LLVMValueRef val = values[i];
+					LLVMValueRef val = old_values[i];
 					if (!LLVMIsConstant(val)) {
 					if (!LLVMIsConstant(val)) {
 						LLVMValueRef dst = LLVMBuildStructGEP(p->builder, v.addr.value, cast(unsigned)i, "");
 						LLVMValueRef dst = LLVMBuildStructGEP(p->builder, v.addr.value, cast(unsigned)i, "");
-						LLVMBuildStore(p->builder, dst, val);
+						LLVMBuildStore(p->builder, val, dst);
 					}
 					}
 				}
 				}
 				return lb_addr_load(p, v);
 				return lb_addr_load(p, v);