From 6e5315646a505a536b05c99c213686a51dd534eb Mon Sep 17 00:00:00 2001 From: Roman Venediktov Date: Fri, 20 Dec 2024 15:57:11 +0100 Subject: [PATCH] Added fail in case of indirect assignment into register --- src/X86_64.ml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/X86_64.ml b/src/X86_64.ml index d4574d465..d0c80e02e 100644 --- a/src/X86_64.ml +++ b/src/X86_64.ml @@ -697,10 +697,20 @@ let compile cmd env imports code = let l, env = env#allocate in let env, call = compile_call env ~fname:".string" 1 false in (env, mov addr l @ call) - | LDA x -> + | LDA x -> ( let s, env' = (env#variable x)#allocate in let s', env'' = env'#allocate in - (env'', [ Lea (env'#loc x, rax); Mov (rax, s); Mov (rax, s') ]) + let loc_x = env'#loc x in + match loc_x with + | R _ -> + failwith + "We are not able to take an address of a register. This \ + is the known limitation of 64-bit compiler. If you \ + encountered this issue, just do not use indirect \ + assignment :(" + | _ -> + (); + (env'', [ Lea (loc_x, rax); Mov (rax, s); Mov (rax, s') ])) | LD x -> ( let s, env' = (env#variable x)#allocate in ( env',