authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-12 10:16:57+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-18 17:32:41-07:00
logd3f1a4edce3f67568ab1e4bf359069e3129e14fa
tree27a73e6feacb06835ac048323f948c5d723ae5a7
parent1add7c616f2e8fed2329f282b634c51dd6250b66

stage1: Add architecture-specific clobbers to asm()

We're basically following Clang's lead, add the necessary clobbers to minimize the risk of generating wrong code.

1 files changed, 23 insertions(+), 0 deletions(-)

src/stage1/codegen.cpp+23
...@@ -4838,6 +4838,29 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I...@@ -4838,6 +4838,29 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I
4838 }4838 }
4839 }4839 }
48404840
4841 // Add some architecture-specific clobbers.
4842 const char *arch_clobbers = nullptr;
4843 switch (g->zig_target->arch) {
4844 case ZigLLVM_x86:
4845 case ZigLLVM_x86_64:
4846 arch_clobbers = "~{dirflag},~{fpsr},~{flags}";
4847 break;
4848 case ZigLLVM_mips:
4849 case ZigLLVM_mipsel:
4850 case ZigLLVM_mips64:
4851 case ZigLLVM_mips64el:
4852 arch_clobbers = "~{$1}";
4853 break;
4854 default:
4855 break;
4856 }
4857
4858 if (arch_clobbers != nullptr) {
4859 if (buf_len(&constraint_buf))
4860 buf_append_char(&constraint_buf, ',');
4861 buf_append_str(&constraint_buf, arch_clobbers);
4862 }
4863
4841 LLVMTypeRef ret_type;4864 LLVMTypeRef ret_type;
4842 if (instruction->return_count == 0) {4865 if (instruction->return_count == 0) {
4843 ret_type = LLVMVoidType();4866 ret_type = LLVMVoidType();