| author | |
| committer | |
| log | 1e1598950aeb20e8f414fdb3993109f05f1b4765 |
| tree | 80e2028257e69c9c4d44954d00fe18d51eb159d4 |
| parent | 661137ac92ef05490a22dfcfb812a81a3014f0c7 |
This avoids llvm module verification errors when the strip option
is different across modules.3 files changed, 69 insertions(+), 52 deletions(-)
src/Sema.zig+2-2| ... | ... | @@ -6415,8 +6415,6 @@ fn zirDbgVar( |
| 6415 | 6415 | inst: Zir.Inst.Index, |
| 6416 | 6416 | air_tag: Air.Inst.Tag, |
| 6417 | 6417 | ) CompileError!void { |
| 6418 | if (block.is_comptime or block.ownerModule().strip) return; | |
| 6419 | ||
| 6420 | 6418 | const str_op = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_op; |
| 6421 | 6419 | const operand = try sema.resolveInst(str_op.operand); |
| 6422 | 6420 | const name = str_op.getStr(sema.code); |
| ... | ... | @@ -6430,6 +6428,8 @@ fn addDbgVar( |
| 6430 | 6428 | air_tag: Air.Inst.Tag, |
| 6431 | 6429 | name: []const u8, |
| 6432 | 6430 | ) CompileError!void { |
| 6431 | if (block.is_comptime or block.ownerModule().strip) return; | |
| 6432 | ||
| 6433 | 6433 | const mod = sema.mod; |
| 6434 | 6434 | const operand_ty = sema.typeOf(operand); |
| 6435 | 6435 | const val_ty = switch (air_tag) { |
src/codegen/llvm.zig+32-26| ... | ... | @@ -837,11 +837,10 @@ pub const Object = struct { |
| 837 | 837 | const gpa = comp.gpa; |
| 838 | 838 | const target = comp.root_mod.resolved_target.result; |
| 839 | 839 | const llvm_target_triple = try targetTriple(arena, target); |
| 840 | const strip = comp.root_mod.strip; | |
| 841 | 840 | |
| 842 | 841 | var builder = try Builder.init(.{ |
| 843 | 842 | .allocator = gpa, |
| 844 | .strip = strip, | |
| 843 | .strip = comp.config.debug_format == .strip, | |
| 845 | 844 | .name = comp.root_name, |
| 846 | 845 | .target = target, |
| 847 | 846 | .triple = llvm_target_triple, |
| ... | ... | @@ -1052,7 +1051,10 @@ pub const Object = struct { |
| 1052 | 1051 | const mod = o.module; |
| 1053 | 1052 | const errors_len = mod.global_error_set.count(); |
| 1054 | 1053 | |
| 1055 | var wip = try Builder.WipFunction.init(&o.builder, llvm_fn.ptrConst(&o.builder).kind.function); | |
| 1054 | var wip = try Builder.WipFunction.init(&o.builder, .{ | |
| 1055 | .function = llvm_fn.ptrConst(&o.builder).kind.function, | |
| 1056 | .strip = true, | |
| 1057 | }); | |
| 1056 | 1058 | defer wip.deinit(); |
| 1057 | 1059 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 1058 | 1060 | |
| ... | ... | @@ -1372,6 +1374,7 @@ pub const Object = struct { |
| 1372 | 1374 | air: Air, |
| 1373 | 1375 | liveness: Liveness, |
| 1374 | 1376 | ) !void { |
| 1377 | const comp = zcu.comp; | |
| 1375 | 1378 | const func = zcu.funcInfo(func_index); |
| 1376 | 1379 | const decl_index = func.owner_decl; |
| 1377 | 1380 | const decl = zcu.declPtr(decl_index); |
| ... | ... | @@ -1440,7 +1443,10 @@ pub const Object = struct { |
| 1440 | 1443 | function_index.setSection(try o.builder.string(section), &o.builder); |
| 1441 | 1444 | |
| 1442 | 1445 | var deinit_wip = true; |
| 1443 | var wip = try Builder.WipFunction.init(&o.builder, function_index); | |
| 1446 | var wip = try Builder.WipFunction.init(&o.builder, .{ | |
| 1447 | .function = function_index, | |
| 1448 | .strip = owner_mod.strip, | |
| 1449 | }); | |
| 1444 | 1450 | defer if (deinit_wip) wip.deinit(); |
| 1445 | 1451 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 1446 | 1452 | |
| ... | ... | @@ -1459,8 +1465,6 @@ pub const Object = struct { |
| 1459 | 1465 | .unsigned => try attributes.addRetAttr(.zeroext, &o.builder), |
| 1460 | 1466 | }; |
| 1461 | 1467 | |
| 1462 | const comp = zcu.comp; | |
| 1463 | ||
| 1464 | 1468 | const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(zcu) and |
| 1465 | 1469 | comp.config.any_error_tracing; |
| 1466 | 1470 | |
| ... | ... | @@ -1645,7 +1649,7 @@ pub const Object = struct { |
| 1645 | 1649 | |
| 1646 | 1650 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 1647 | 1651 | |
| 1648 | const file, const subprogram = if (!o.builder.strip) debug_info: { | |
| 1652 | const file, const subprogram = if (!wip.strip) debug_info: { | |
| 1649 | 1653 | const file = try o.getDebugFile(namespace.file_scope); |
| 1650 | 1654 | |
| 1651 | 1655 | const line_number = decl.src_line + 1; |
| ... | ... | @@ -4616,7 +4620,10 @@ pub const Object = struct { |
| 4616 | 4620 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 4617 | 4621 | gop.value_ptr.* = function_index.ptrConst(&o.builder).global; |
| 4618 | 4622 | |
| 4619 | var wip = try Builder.WipFunction.init(&o.builder, function_index); | |
| 4623 | var wip = try Builder.WipFunction.init(&o.builder, .{ | |
| 4624 | .function = function_index, | |
| 4625 | .strip = true, | |
| 4626 | }); | |
| 4620 | 4627 | defer wip.deinit(); |
| 4621 | 4628 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 4622 | 4629 | |
| ... | ... | @@ -4686,23 +4693,23 @@ pub const DeclGen = struct { |
| 4686 | 4693 | |
| 4687 | 4694 | fn genDecl(dg: *DeclGen) !void { |
| 4688 | 4695 | const o = dg.object; |
| 4689 | const mod = o.module; | |
| 4696 | const zcu = o.module; | |
| 4690 | 4697 | const decl = dg.decl; |
| 4691 | 4698 | const decl_index = dg.decl_index; |
| 4692 | 4699 | assert(decl.has_tv); |
| 4693 | 4700 | |
| 4694 | if (decl.val.getExternFunc(mod)) |extern_func| { | |
| 4701 | if (decl.val.getExternFunc(zcu)) |extern_func| { | |
| 4695 | 4702 | _ = try o.resolveLlvmFunction(extern_func.decl); |
| 4696 | 4703 | } else { |
| 4697 | 4704 | const variable_index = try o.resolveGlobalDecl(decl_index); |
| 4698 | 4705 | variable_index.setAlignment( |
| 4699 | decl.getAlignment(mod).toLlvm(), | |
| 4706 | decl.getAlignment(zcu).toLlvm(), | |
| 4700 | 4707 | &o.builder, |
| 4701 | 4708 | ); |
| 4702 | if (mod.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section| | |
| 4709 | if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section| | |
| 4703 | 4710 | variable_index.setSection(try o.builder.string(section), &o.builder); |
| 4704 | 4711 | assert(decl.has_tv); |
| 4705 | const init_val = if (decl.val.getVariable(mod)) |decl_var| decl_var.init else init_val: { | |
| 4712 | const init_val = if (decl.val.getVariable(zcu)) |decl_var| decl_var.init else init_val: { | |
| 4706 | 4713 | variable_index.setMutability(.constant, &o.builder); |
| 4707 | 4714 | break :init_val decl.val.toIntern(); |
| 4708 | 4715 | }; |
| ... | ... | @@ -4714,12 +4721,15 @@ pub const DeclGen = struct { |
| 4714 | 4721 | const line_number = decl.src_line + 1; |
| 4715 | 4722 | const is_internal_linkage = !o.module.decl_exports.contains(decl_index); |
| 4716 | 4723 | |
| 4717 | if (dg.object.builder.strip) return; | |
| 4724 | const namespace = zcu.namespacePtr(decl.src_namespace); | |
| 4725 | const owner_mod = namespace.file_scope.mod; | |
| 4718 | 4726 | |
| 4719 | const debug_file = try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope); | |
| 4727 | if (owner_mod.strip) return; | |
| 4728 | ||
| 4729 | const debug_file = try o.getDebugFile(namespace.file_scope); | |
| 4720 | 4730 | |
| 4721 | 4731 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4722 | try o.builder.metadataString(mod.intern_pool.stringToSlice(decl.name)), // Name | |
| 4732 | try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)), // Name | |
| 4723 | 4733 | try o.builder.metadataStringFromString(variable_index.name(&o.builder)), // Linkage name |
| 4724 | 4734 | debug_file, // File |
| 4725 | 4735 | debug_file, // Scope |
| ... | ... | @@ -4735,7 +4745,7 @@ pub const DeclGen = struct { |
| 4735 | 4745 | debug_global_var, |
| 4736 | 4746 | debug_expression, |
| 4737 | 4747 | ); |
| 4738 | if (!is_internal_linkage or decl.isExtern(mod)) | |
| 4748 | if (!is_internal_linkage or decl.isExtern(zcu)) | |
| 4739 | 4749 | variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder); |
| 4740 | 4750 | try o.debug_globals.append(o.gpa, debug_global_var_expression); |
| 4741 | 4751 | } |
| ... | ... | @@ -6570,7 +6580,6 @@ pub const FuncGen = struct { |
| 6570 | 6580 | } |
| 6571 | 6581 | |
| 6572 | 6582 | fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6573 | if (self.wip.builder.strip) return .none; | |
| 6574 | 6583 | const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; |
| 6575 | 6584 | self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1); |
| 6576 | 6585 | self.prev_dbg_column = @intCast(dbg_stmt.column + 1); |
| ... | ... | @@ -6593,7 +6602,6 @@ pub const FuncGen = struct { |
| 6593 | 6602 | } |
| 6594 | 6603 | |
| 6595 | 6604 | fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6596 | if (self.wip.builder.strip) return .none; | |
| 6597 | 6605 | const o = self.dg.object; |
| 6598 | 6606 | const zcu = o.module; |
| 6599 | 6607 | |
| ... | ... | @@ -6660,7 +6668,6 @@ pub const FuncGen = struct { |
| 6660 | 6668 | } |
| 6661 | 6669 | |
| 6662 | 6670 | fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 6663 | if (self.wip.builder.strip) return .none; | |
| 6664 | 6671 | const o = self.dg.object; |
| 6665 | 6672 | |
| 6666 | 6673 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; |
| ... | ... | @@ -6677,7 +6684,6 @@ pub const FuncGen = struct { |
| 6677 | 6684 | } |
| 6678 | 6685 | |
| 6679 | 6686 | fn airDbgBlockBegin(self: *FuncGen) Allocator.Error!Builder.Value { |
| 6680 | if (self.wip.builder.strip) return .none; | |
| 6681 | 6687 | const o = self.dg.object; |
| 6682 | 6688 | |
| 6683 | 6689 | try self.scope_stack.append(self.gpa, self.scope); |
| ... | ... | @@ -6693,13 +6699,11 @@ pub const FuncGen = struct { |
| 6693 | 6699 | } |
| 6694 | 6700 | |
| 6695 | 6701 | fn airDbgBlockEnd(self: *FuncGen) !Builder.Value { |
| 6696 | if (self.wip.builder.strip) return .none; | |
| 6697 | 6702 | self.scope = self.scope_stack.pop(); |
| 6698 | 6703 | return .none; |
| 6699 | 6704 | } |
| 6700 | 6705 | |
| 6701 | 6706 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6702 | if (self.wip.builder.strip) return .none; | |
| 6703 | 6707 | const o = self.dg.object; |
| 6704 | 6708 | const mod = o.module; |
| 6705 | 6709 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| ... | ... | @@ -6732,7 +6736,6 @@ pub const FuncGen = struct { |
| 6732 | 6736 | } |
| 6733 | 6737 | |
| 6734 | 6738 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6735 | if (self.wip.builder.strip) return .none; | |
| 6736 | 6739 | const o = self.dg.object; |
| 6737 | 6740 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 6738 | 6741 | const operand = try self.resolveInst(pl_op.operand); |
| ... | ... | @@ -8813,7 +8816,7 @@ pub const FuncGen = struct { |
| 8813 | 8816 | const arg_val = self.args[self.arg_index]; |
| 8814 | 8817 | self.arg_index += 1; |
| 8815 | 8818 | |
| 8816 | if (self.wip.builder.strip) return arg_val; | |
| 8819 | if (self.wip.strip) return arg_val; | |
| 8817 | 8820 | |
| 8818 | 8821 | const inst_ty = self.typeOfIndex(inst); |
| 8819 | 8822 | if (needDbgVarWorkaround(o)) return arg_val; |
| ... | ... | @@ -9660,7 +9663,10 @@ pub const FuncGen = struct { |
| 9660 | 9663 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 9661 | 9664 | gop.value_ptr.* = function_index; |
| 9662 | 9665 | |
| 9663 | var wip = try Builder.WipFunction.init(&o.builder, function_index); | |
| 9666 | var wip = try Builder.WipFunction.init(&o.builder, .{ | |
| 9667 | .function = function_index, | |
| 9668 | .strip = true, | |
| 9669 | }); | |
| 9664 | 9670 | defer wip.deinit(); |
| 9665 | 9671 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 9666 | 9672 |
src/codegen/llvm/Builder.zig+35-24| ... | ... | @@ -3797,6 +3797,7 @@ pub const Function = struct { |
| 3797 | 3797 | instructions: std.MultiArrayList(Instruction) = .{}, |
| 3798 | 3798 | names: [*]const String = &[0]String{}, |
| 3799 | 3799 | value_indices: [*]const u32 = &[0]u32{}, |
| 3800 | strip: bool, | |
| 3800 | 3801 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}, |
| 3801 | 3802 | debug_values: []const Instruction.Index = &.{}, |
| 3802 | 3803 | extra: []const u32 = &.{}, |
| ... | ... | @@ -4890,6 +4891,7 @@ pub const WipFunction = struct { |
| 4890 | 4891 | blocks: std.ArrayListUnmanaged(Block), |
| 4891 | 4892 | instructions: std.MultiArrayList(Instruction), |
| 4892 | 4893 | names: std.ArrayListUnmanaged(String), |
| 4894 | strip: bool, | |
| 4893 | 4895 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation), |
| 4894 | 4896 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), |
| 4895 | 4897 | extra: std.ArrayListUnmanaged(u32), |
| ... | ... | @@ -4922,31 +4924,35 @@ pub const WipFunction = struct { |
| 4922 | 4924 | |
| 4923 | 4925 | pub const Instruction = Function.Instruction; |
| 4924 | 4926 | |
| 4925 | pub fn init(builder: *Builder, function: Function.Index) Allocator.Error!WipFunction { | |
| 4927 | pub fn init(builder: *Builder, options: struct { | |
| 4928 | function: Function.Index, | |
| 4929 | strip: bool, | |
| 4930 | }) Allocator.Error!WipFunction { | |
| 4926 | 4931 | var self: WipFunction = .{ |
| 4927 | 4932 | .builder = builder, |
| 4928 | .function = function, | |
| 4933 | .function = options.function, | |
| 4929 | 4934 | .prev_debug_location = .no_location, |
| 4930 | 4935 | .debug_location = .no_location, |
| 4931 | 4936 | .cursor = undefined, |
| 4932 | 4937 | .blocks = .{}, |
| 4933 | 4938 | .instructions = .{}, |
| 4934 | 4939 | .names = .{}, |
| 4940 | .strip = options.strip, | |
| 4935 | 4941 | .debug_locations = .{}, |
| 4936 | 4942 | .debug_values = .{}, |
| 4937 | 4943 | .extra = .{}, |
| 4938 | 4944 | }; |
| 4939 | 4945 | errdefer self.deinit(); |
| 4940 | 4946 | |
| 4941 | const params_len = function.typeOf(self.builder).functionParameters(self.builder).len; | |
| 4947 | const params_len = options.function.typeOf(self.builder).functionParameters(self.builder).len; | |
| 4942 | 4948 | try self.ensureUnusedExtraCapacity(params_len, NoExtra, 0); |
| 4943 | 4949 | try self.instructions.ensureUnusedCapacity(self.builder.gpa, params_len); |
| 4944 | if (!self.builder.strip) { | |
| 4950 | if (!self.strip) { | |
| 4945 | 4951 | try self.names.ensureUnusedCapacity(self.builder.gpa, params_len); |
| 4946 | 4952 | } |
| 4947 | 4953 | for (0..params_len) |param_index| { |
| 4948 | 4954 | self.instructions.appendAssumeCapacity(.{ .tag = .arg, .data = @intCast(param_index) }); |
| 4949 | if (!self.builder.strip) { | |
| 4955 | if (!self.strip) { | |
| 4950 | 4956 | self.names.appendAssumeCapacity(.empty); // TODO: param names |
| 4951 | 4957 | } |
| 4952 | 4958 | } |
| ... | ... | @@ -4967,7 +4973,7 @@ pub const WipFunction = struct { |
| 4967 | 4973 | try self.blocks.ensureUnusedCapacity(self.builder.gpa, 1); |
| 4968 | 4974 | |
| 4969 | 4975 | const index: Block.Index = @enumFromInt(self.blocks.items.len); |
| 4970 | const final_name = if (self.builder.strip) .empty else try self.builder.string(name); | |
| 4976 | const final_name = if (self.strip) .empty else try self.builder.string(name); | |
| 4971 | 4977 | self.blocks.appendAssumeCapacity(.{ |
| 4972 | 4978 | .name = final_name, |
| 4973 | 4979 | .incoming = incoming, |
| ... | ... | @@ -5828,7 +5834,7 @@ pub const WipFunction = struct { |
| 5828 | 5834 | } |
| 5829 | 5835 | |
| 5830 | 5836 | pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata { |
| 5831 | if (self.builder.strip) return .none; | |
| 5837 | if (self.strip) return .none; | |
| 5832 | 5838 | return switch (value.unwrap()) { |
| 5833 | 5839 | .instruction => |instr_index| blk: { |
| 5834 | 5840 | const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index); |
| ... | ... | @@ -6015,7 +6021,7 @@ pub const WipFunction = struct { |
| 6015 | 6021 | value_index += 1; |
| 6016 | 6022 | function.instructions.appendAssumeCapacity(argument); |
| 6017 | 6023 | names[@intFromEnum(new_argument_index)] = try wip_name.map( |
| 6018 | if (self.builder.strip) .empty else self.names.items[@intFromEnum(old_argument_index)], | |
| 6024 | if (self.strip) .empty else self.names.items[@intFromEnum(old_argument_index)], | |
| 6019 | 6025 | ".", |
| 6020 | 6026 | ); |
| 6021 | 6027 | if (self.debug_locations.get(old_argument_index)) |location| { |
| ... | ... | @@ -6333,7 +6339,7 @@ pub const WipFunction = struct { |
| 6333 | 6339 | }, |
| 6334 | 6340 | } |
| 6335 | 6341 | function.instructions.appendAssumeCapacity(instruction); |
| 6336 | names[@intFromEnum(new_instruction_index)] = try wip_name.map(if (self.builder.strip) | |
| 6342 | names[@intFromEnum(new_instruction_index)] = try wip_name.map(if (self.strip) | |
| 6337 | 6343 | if (old_instruction_index.hasResultWip(self)) .empty else .none |
| 6338 | 6344 | else |
| 6339 | 6345 | self.names.items[@intFromEnum(old_instruction_index)], "."); |
| ... | ... | @@ -6356,6 +6362,7 @@ pub const WipFunction = struct { |
| 6356 | 6362 | function.blocks = blocks; |
| 6357 | 6363 | function.names = names.ptr; |
| 6358 | 6364 | function.value_indices = value_indices.ptr; |
| 6365 | function.strip = self.strip; | |
| 6359 | 6366 | function.debug_locations = debug_locations; |
| 6360 | 6367 | function.debug_values = debug_values; |
| 6361 | 6368 | } |
| ... | ... | @@ -6503,19 +6510,19 @@ pub const WipFunction = struct { |
| 6503 | 6510 | ) Allocator.Error!Instruction.Index { |
| 6504 | 6511 | const block_instructions = &self.cursor.block.ptr(self).instructions; |
| 6505 | 6512 | try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6506 | if (!self.builder.strip) { | |
| 6513 | if (!self.strip) { | |
| 6507 | 6514 | try self.names.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6508 | 6515 | try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6509 | 6516 | } |
| 6510 | 6517 | try block_instructions.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6511 | 6518 | const final_name = if (name) |n| |
| 6512 | if (self.builder.strip) .empty else try self.builder.string(n) | |
| 6519 | if (self.strip) .empty else try self.builder.string(n) | |
| 6513 | 6520 | else |
| 6514 | 6521 | .none; |
| 6515 | 6522 | |
| 6516 | 6523 | const index: Instruction.Index = @enumFromInt(self.instructions.len); |
| 6517 | 6524 | self.instructions.appendAssumeCapacity(instruction); |
| 6518 | if (!self.builder.strip) { | |
| 6525 | if (!self.strip) { | |
| 6519 | 6526 | self.names.appendAssumeCapacity(final_name); |
| 6520 | 6527 | if (block_instructions.items.len == 0 or |
| 6521 | 6528 | !std.meta.eql(self.debug_location, self.prev_debug_location)) |
| ... | ... | @@ -8723,11 +8730,14 @@ pub fn addFunctionAssumeCapacity( |
| 8723 | 8730 | ) Function.Index { |
| 8724 | 8731 | assert(ty.isFunction(self)); |
| 8725 | 8732 | const function_index: Function.Index = @enumFromInt(self.functions.items.len); |
| 8726 | self.functions.appendAssumeCapacity(.{ .global = self.addGlobalAssumeCapacity(name, .{ | |
| 8727 | .addr_space = addr_space, | |
| 8728 | .type = ty, | |
| 8729 | .kind = .{ .function = function_index }, | |
| 8730 | }) }); | |
| 8733 | self.functions.appendAssumeCapacity(.{ | |
| 8734 | .global = self.addGlobalAssumeCapacity(name, .{ | |
| 8735 | .addr_space = addr_space, | |
| 8736 | .type = ty, | |
| 8737 | .kind = .{ .function = function_index }, | |
| 8738 | }), | |
| 8739 | .strip = undefined, | |
| 8740 | }); | |
| 8731 | 8741 | return function_index; |
| 8732 | 8742 | } |
| 8733 | 8743 | |
| ... | ... | @@ -14396,16 +14406,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14396 | 14406 | return @intCast(switch (value.unwrap()) { |
| 14397 | 14407 | .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(), |
| 14398 | 14408 | .constant => |constant| adapter.constant_adapter.getConstantIndex(constant), |
| 14399 | .metadata => |metadata| if (!adapter.metadata_adapter.builder.strip) blk: { | |
| 14409 | .metadata => |metadata| { | |
| 14410 | assert(!adapter.func.strip); | |
| 14400 | 14411 | const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder); |
| 14401 | 14412 | if (@intFromEnum(real_metadata) < Metadata.first_local_metadata) |
| 14402 | break :blk adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1; | |
| 14413 | return adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1; | |
| 14403 | 14414 | |
| 14404 | 14415 | return @intCast(@intFromEnum(metadata) - |
| 14405 | 14416 | Metadata.first_local_metadata + |
| 14406 | 14417 | adapter.metadata_adapter.builder.metadata_string_map.count() - 1 + |
| 14407 | 14418 | adapter.metadata_adapter.builder.metadata_map.count() - 1); |
| 14408 | } else unreachable, | |
| 14419 | }, | |
| 14409 | 14420 | }); |
| 14410 | 14421 | } |
| 14411 | 14422 | |
| ... | ... | @@ -14452,7 +14463,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14452 | 14463 | var adapter = FunctionAdapter.init(constant_adapter, metadata_adapter, &func); |
| 14453 | 14464 | |
| 14454 | 14465 | // Emit function level metadata block |
| 14455 | if (!self.strip and func.debug_values.len != 0) { | |
| 14466 | if (!func.strip and func.debug_values.len > 0) { | |
| 14456 | 14467 | const MetadataBlock = ir.FunctionMetadataBlock; |
| 14457 | 14468 | var metadata_block = try function_block.enterSubBlock(MetadataBlock); |
| 14458 | 14469 | |
| ... | ... | @@ -14913,7 +14924,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14913 | 14924 | }, |
| 14914 | 14925 | } |
| 14915 | 14926 | |
| 14916 | if (!self.strip) { | |
| 14927 | if (!func.strip) { | |
| 14917 | 14928 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { |
| 14918 | 14929 | switch (debug_location) { |
| 14919 | 14930 | .no_location => has_location = false, |
| ... | ... | @@ -14937,7 +14948,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14937 | 14948 | } |
| 14938 | 14949 | |
| 14939 | 14950 | // VALUE_SYMTAB |
| 14940 | if (!self.strip) { | |
| 14951 | if (!func.strip) { | |
| 14941 | 14952 | const ValueSymbolTable = ir.FunctionValueSymbolTable; |
| 14942 | 14953 | |
| 14943 | 14954 | var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable); |
| ... | ... | @@ -14959,7 +14970,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14959 | 14970 | } |
| 14960 | 14971 | |
| 14961 | 14972 | // METADATA_ATTACHMENT_BLOCK |
| 14962 | if (!self.strip) blk: { | |
| 14973 | if (!func.strip) blk: { | |
| 14963 | 14974 | const dbg = func.global.ptrConst(self).dbg; |
| 14964 | 14975 | |
| 14965 | 14976 | if (dbg == .none) break :blk; |