gingerBill 5 years ago
parent
commit
13e5cb8cc4
2 changed files with 63 additions and 7 deletions
  1. 46 0
      src/ir.cpp
  2. 17 7
      src/llvm_backend.cpp

+ 46 - 0
src/ir.cpp

@@ -2845,6 +2845,52 @@ irDebugInfo *ir_add_debug_info_type(irModule *module, Type *type, Entity *e, irD
 		return di;
 	}
 
+	if (is_type_relative_pointer(type)) {
+		Type *base_integer = base_type(type)->RelativePointer.base_integer;
+		base_integer = core_type(base_integer);
+		GB_ASSERT(base_integer->kind == Type_Basic);
+		irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_BasicType);
+		di->BasicType.encoding = ir_debug_encoding_for_basic(base_integer->Basic.kind);
+		di->BasicType.name = base_integer->Basic.name;
+		di->BasicType.size = ir_debug_size_bits(type);
+		di->BasicType.align = ir_debug_align_bits(type);
+		map_set(&module->debug_info, hash_type(type), di);
+		return di;
+	}
+
+	if (is_type_relative_slice(type)) {
+		Type *base_integer = base_type(type)->RelativeSlice.base_integer;
+		base_integer = core_type(base_integer);
+
+		// NOTE(lachsinc): Every slice type has its own composite type / field debug infos created. This is sorta wasteful.
+		irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompositeType);
+		di->CompositeType.name = str_lit("relative slice");
+		di->CompositeType.tag = irDebugBasicEncoding_structure_type;
+		di->CompositeType.size = ir_debug_size_bits(type); // TODO(lachsinc): Correct ??
+		di->CompositeType.align = ir_debug_align_bits(type);
+		map_set(&module->debug_info, hash_type(type), di);
+
+		irDebugInfo *data_di = ir_add_debug_info_field_internal(module, str_lit("data"), base_integer,
+		                                                        0,
+		                                                        nullptr,
+		                                                        di);
+		map_set(&module->debug_info, hash_pointer(data_di), data_di);
+
+		irDebugInfo *len_di = ir_add_debug_info_field_internal(module, str_lit("len"), base_integer,
+		                                                       data_di->DerivedType.size,
+		                                                       nullptr,
+		                                                       di);
+		map_set(&module->debug_info, hash_pointer(len_di), len_di);
+
+		irDebugInfo *elements_di = ir_add_debug_info_array(module, 0, 2);
+		array_add(&elements_di->DebugInfoArray.elements, data_di);
+		array_add(&elements_di->DebugInfoArray.elements, len_di);
+		di->CompositeType.elements = elements_di;
+		map_set(&module->debug_info, hash_pointer(elements_di), elements_di);
+
+		return di;
+	}
+
 	GB_PANIC("Unreachable %s", type_to_string(type));
 	return nullptr;
 }

+ 17 - 7
src/llvm_backend.cpp

@@ -7977,15 +7977,25 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
 		}
 
 		// TODO(bill): Figure out how to make it weak
-		LLVMBool single_threaded = !weak;
+		LLVMBool single_threaded = weak;
+
+		LLVMValueRef value = LLVMBuildAtomicCmpXchg(
+			p->builder, address.value,
+			old_value.value, new_value.value,
+			success_ordering,
+			failure_ordering,
+			single_threaded
+		);
+
+		GB_ASSERT(tv.type->kind == Type_Tuple);
+		Type *fix_typed = alloc_type_tuple();
+		array_init(&fix_typed->Tuple.variables, heap_allocator(), 2);
+		fix_typed->Tuple.variables[0] = tv.type->Tuple.variables[0];
+		fix_typed->Tuple.variables[1] = alloc_entity_field(nullptr, blank_token, t_llvm_bool, false, 1);
 
 		lbValue res = {};
-		res.value = LLVMBuildAtomicCmpXchg(p->builder, address.value,
-		                                   old_value.value, new_value.value,
-		                                   success_ordering,
-		                                   failure_ordering,
-		                                   single_threaded);
-		res.type = tv.type;
+		res.value = value;
+		res.type = fix_typed;
 		return res;
 	}
 	}