| ... | @@ -2909,7 +2909,17 @@ pub const Object = struct { | ... | @@ -2909,7 +2909,17 @@ pub const Object = struct { |
| 2909 | function_index.setAlignment(resolved.alignment.toLlvm(), &o.builder); | 2909 | function_index.setAlignment(resolved.alignment.toLlvm(), &o.builder); |
| 2910 | | 2910 | |
| 2911 | // Function attributes that are independent of analysis results of the function body. | 2911 | // Function attributes that are independent of analysis results of the function body. |
| 2912 | try o.addCommonFnAttributes(&attributes, owner_mod); | 2912 | try o.addCommonFnAttributes( |
| | 2913 | &attributes, |
| | 2914 | owner_mod, |
| | 2915 | // Some backends don't respect the `naked` attribute in `TargetFrameLowering::hasFP()`, |
| | 2916 | // so for these backends, LLVM will happily emit code that accesses the stack through |
| | 2917 | // the frame pointer. This is nonsensical since what the `naked` attribute does is |
| | 2918 | // suppress generation of the prologue and epilogue, and the prologue is where the |
| | 2919 | // frame pointer normally gets set up. At time of writing, this is the case for at |
| | 2920 | // least x86 and RISC-V. |
| | 2921 | owner_mod.omit_frame_pointer or fn_info.cc == .Naked, |
| | 2922 | ); |
| 2913 | | 2923 | |
| 2914 | if (fn_info.return_type == .noreturn_type) try attributes.addFnAttr(.noreturn, &o.builder); | 2924 | if (fn_info.return_type == .noreturn_type) try attributes.addFnAttr(.noreturn, &o.builder); |
| 2915 | | 2925 | |
| ... | @@ -2956,13 +2966,14 @@ pub const Object = struct { | ... | @@ -2956,13 +2966,14 @@ pub const Object = struct { |
| 2956 | o: *Object, | 2966 | o: *Object, |
| 2957 | attributes: *Builder.FunctionAttributes.Wip, | 2967 | attributes: *Builder.FunctionAttributes.Wip, |
| 2958 | owner_mod: *Package.Module, | 2968 | owner_mod: *Package.Module, |
| | 2969 | omit_frame_pointer: bool, |
| 2959 | ) Allocator.Error!void { | 2970 | ) Allocator.Error!void { |
| 2960 | const comp = o.pt.zcu.comp; | 2971 | const comp = o.pt.zcu.comp; |
| 2961 | | 2972 | |
| 2962 | if (!owner_mod.red_zone) { | 2973 | if (!owner_mod.red_zone) { |
| 2963 | try attributes.addFnAttr(.noredzone, &o.builder); | 2974 | try attributes.addFnAttr(.noredzone, &o.builder); |
| 2964 | } | 2975 | } |
| 2965 | if (owner_mod.omit_frame_pointer) { | 2976 | if (omit_frame_pointer) { |
| 2966 | try attributes.addFnAttr(.{ .string = .{ | 2977 | try attributes.addFnAttr(.{ .string = .{ |
| 2967 | .kind = try o.builder.string("frame-pointer"), | 2978 | .kind = try o.builder.string("frame-pointer"), |
| 2968 | .value = try o.builder.string("none"), | 2979 | .value = try o.builder.string("none"), |
| ... | @@ -4528,7 +4539,7 @@ pub const Object = struct { | ... | @@ -4528,7 +4539,7 @@ pub const Object = struct { |
| 4528 | | 4539 | |
| 4529 | var attributes: Builder.FunctionAttributes.Wip = .{}; | 4540 | var attributes: Builder.FunctionAttributes.Wip = .{}; |
| 4530 | defer attributes.deinit(&o.builder); | 4541 | defer attributes.deinit(&o.builder); |
| 4531 | try o.addCommonFnAttributes(&attributes, zcu.root_mod); | 4542 | try o.addCommonFnAttributes(&attributes, zcu.root_mod, zcu.root_mod.omit_frame_pointer); |
| 4532 | | 4543 | |
| 4533 | function_index.setLinkage(.internal, &o.builder); | 4544 | function_index.setLinkage(.internal, &o.builder); |
| 4534 | function_index.setCallConv(.fastcc, &o.builder); | 4545 | function_index.setCallConv(.fastcc, &o.builder); |
| ... | @@ -4557,7 +4568,7 @@ pub const Object = struct { | ... | @@ -4557,7 +4568,7 @@ pub const Object = struct { |
| 4557 | | 4568 | |
| 4558 | var attributes: Builder.FunctionAttributes.Wip = .{}; | 4569 | var attributes: Builder.FunctionAttributes.Wip = .{}; |
| 4559 | defer attributes.deinit(&o.builder); | 4570 | defer attributes.deinit(&o.builder); |
| 4560 | try o.addCommonFnAttributes(&attributes, zcu.root_mod); | 4571 | try o.addCommonFnAttributes(&attributes, zcu.root_mod, zcu.root_mod.omit_frame_pointer); |
| 4561 | | 4572 | |
| 4562 | function_index.setLinkage(.internal, &o.builder); | 4573 | function_index.setLinkage(.internal, &o.builder); |
| 4563 | function_index.setCallConv(.fastcc, &o.builder); | 4574 | function_index.setCallConv(.fastcc, &o.builder); |
| ... | @@ -9676,7 +9687,7 @@ pub const FuncGen = struct { | ... | @@ -9676,7 +9687,7 @@ pub const FuncGen = struct { |
| 9676 | | 9687 | |
| 9677 | var attributes: Builder.FunctionAttributes.Wip = .{}; | 9688 | var attributes: Builder.FunctionAttributes.Wip = .{}; |
| 9678 | defer attributes.deinit(&o.builder); | 9689 | defer attributes.deinit(&o.builder); |
| 9679 | try o.addCommonFnAttributes(&attributes, zcu.root_mod); | 9690 | try o.addCommonFnAttributes(&attributes, zcu.root_mod, zcu.root_mod.omit_frame_pointer); |
| 9680 | | 9691 | |
| 9681 | function_index.setLinkage(.internal, &o.builder); | 9692 | function_index.setLinkage(.internal, &o.builder); |
| 9682 | function_index.setCallConv(.fastcc, &o.builder); | 9693 | function_index.setCallConv(.fastcc, &o.builder); |