| ... | @@ -673,6 +673,7 @@ pub const Object = struct { | ... | @@ -673,6 +673,7 @@ pub const Object = struct { |
| 673 | ) !void { | 673 | ) !void { |
| 674 | const decl_index = func.owner_decl; | 674 | const decl_index = func.owner_decl; |
| 675 | const decl = module.declPtr(decl_index); | 675 | const decl = module.declPtr(decl_index); |
| | 676 | const target = module.getTarget(); |
| 676 | | 677 | |
| 677 | var dg: DeclGen = .{ | 678 | var dg: DeclGen = .{ |
| 678 | .context = o.context, | 679 | .context = o.context, |
| ... | @@ -706,6 +707,17 @@ pub const Object = struct { | ... | @@ -706,6 +707,17 @@ pub const Object = struct { |
| 706 | DeclGen.removeFnAttr(llvm_func, "noinline"); | 707 | DeclGen.removeFnAttr(llvm_func, "noinline"); |
| 707 | } | 708 | } |
| 708 | | 709 | |
| | 710 | // TODO: port these over from stage1 |
| | 711 | // addLLVMFnAttr(llvm_fn, "sspstrong"); |
| | 712 | // addLLVMFnAttrStr(llvm_fn, "stack-protector-buffer-size", "4"); |
| | 713 | |
| | 714 | // TODO: disable this if safety is off for the function scope |
| | 715 | if (module.comp.bin_file.options.stack_check) { |
| | 716 | dg.addFnAttrString(llvm_func, "probe-stack", "__zig_probe_stack"); |
| | 717 | } else if (target.os.tag == .uefi) { |
| | 718 | dg.addFnAttrString(llvm_func, "no-stack-arg-probe", ""); |
| | 719 | } |
| | 720 | |
| 709 | // Remove all the basic blocks of a function in order to start over, generating | 721 | // Remove all the basic blocks of a function in order to start over, generating |
| 710 | // LLVM IR from an empty function body. | 722 | // LLVM IR from an empty function body. |
| 711 | while (llvm_func.getFirstBasicBlock()) |bb| { | 723 | while (llvm_func.getFirstBasicBlock()) |bb| { |
| ... | @@ -719,7 +731,6 @@ pub const Object = struct { | ... | @@ -719,7 +731,6 @@ pub const Object = struct { |
| 719 | | 731 | |
| 720 | // This gets the LLVM values from the function and stores them in `dg.args`. | 732 | // This gets the LLVM values from the function and stores them in `dg.args`. |
| 721 | const fn_info = decl.ty.fnInfo(); | 733 | const fn_info = decl.ty.fnInfo(); |
| 722 | const target = dg.module.getTarget(); | | |
| 723 | const sret = firstParamSRet(fn_info, target); | 734 | const sret = firstParamSRet(fn_info, target); |
| 724 | const ret_ptr = if (sret) llvm_func.getParam(0) else null; | 735 | const ret_ptr = if (sret) llvm_func.getParam(0) else null; |
| 725 | const gpa = dg.gpa; | 736 | const gpa = dg.gpa; |
| ... | @@ -730,7 +741,7 @@ pub const Object = struct { | ... | @@ -730,7 +741,7 @@ pub const Object = struct { |
| 730 | }; | 741 | }; |
| 731 | | 742 | |
| 732 | const err_return_tracing = fn_info.return_type.isError() and | 743 | const err_return_tracing = fn_info.return_type.isError() and |
| 733 | dg.module.comp.bin_file.options.error_return_tracing; | 744 | module.comp.bin_file.options.error_return_tracing; |
| 734 | | 745 | |
| 735 | const err_ret_trace = if (err_return_tracing) | 746 | const err_ret_trace = if (err_return_tracing) |
| 736 | llvm_func.getParam(@boolToInt(ret_ptr != null)) | 747 | llvm_func.getParam(@boolToInt(ret_ptr != null)) |
| ... | @@ -920,7 +931,7 @@ pub const Object = struct { | ... | @@ -920,7 +931,7 @@ pub const Object = struct { |
| 920 | | 931 | |
| 921 | const line_number = decl.src_line + 1; | 932 | const line_number = decl.src_line + 1; |
| 922 | const is_internal_linkage = decl.val.tag() != .extern_fn and | 933 | const is_internal_linkage = decl.val.tag() != .extern_fn and |
| 923 | !dg.module.decl_exports.contains(decl_index); | 934 | !module.decl_exports.contains(decl_index); |
| 924 | const noret_bit: c_uint = if (fn_info.return_type.isNoReturn()) | 935 | const noret_bit: c_uint = if (fn_info.return_type.isNoReturn()) |
| 925 | llvm.DIFlags.NoReturn | 936 | llvm.DIFlags.NoReturn |
| 926 | else | 937 | else |
| ... | @@ -936,7 +947,7 @@ pub const Object = struct { | ... | @@ -936,7 +947,7 @@ pub const Object = struct { |
| 936 | true, // is definition | 947 | true, // is definition |
| 937 | line_number + func.lbrace_line, // scope line | 948 | line_number + func.lbrace_line, // scope line |
| 938 | llvm.DIFlags.StaticMember | noret_bit, | 949 | llvm.DIFlags.StaticMember | noret_bit, |
| 939 | dg.module.comp.bin_file.options.optimize_mode != .Debug, | 950 | module.comp.bin_file.options.optimize_mode != .Debug, |
| 940 | null, // decl_subprogram | 951 | null, // decl_subprogram |
| 941 | ); | 952 | ); |
| 942 | try dg.object.di_map.put(gpa, decl, subprogram.toNode()); | 953 | try dg.object.di_map.put(gpa, decl, subprogram.toNode()); |