From 0662b611cac5f21fb083e0a27a4583387b874ba2 Mon Sep 17 00:00:00 2001
From: florian <florian@freepascal.org>
Date: Wed, 31 Jan 2018 18:34:42 +0000
Subject: [PATCH] * patch by Christo Crause: prevent that the compiler converts
 breq into jmp in inline assembler blocks, resolves #32949

git-svn-id: trunk@38088 -
---
 .gitattributes           |  1 +
 compiler/avr/aasmcpu.pas | 17 +++++++++++------
 tests/webtbf/tw32949.pp  | 16 ++++++++++++++++
 3 files changed, 28 insertions(+), 6 deletions(-)
 create mode 100644 tests/webtbf/tw32949.pp

diff --git a/.gitattributes b/.gitattributes
index 2c19be3851..b7ca8cd990 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -14335,6 +14335,7 @@ tests/webtbf/tw3267.pp svneol=native#text/plain
 tests/webtbf/tw3275.pp svneol=native#text/plain
 tests/webtbf/tw32906.pp svneol=native#text/plain
 tests/webtbf/tw3294.pp svneol=native#text/plain
+tests/webtbf/tw32949.pp svneol=native#text/pascal
 tests/webtbf/tw3331.pp svneol=native#text/plain
 tests/webtbf/tw3337.pp svneol=native#text/plain
 tests/webtbf/tw3342.pp svneol=native#text/plain
diff --git a/compiler/avr/aasmcpu.pas b/compiler/avr/aasmcpu.pas
index bd7d8598a7..0fa4d94501 100644
--- a/compiler/avr/aasmcpu.pas
+++ b/compiler/avr/aasmcpu.pas
@@ -448,12 +448,17 @@ implementation
                         if (taicpu(curtai).InsOffset-taicpu(curtai).oper[0]^.ref^.symbol.offset>64) or
                           (taicpu(curtai).InsOffset-taicpu(curtai).oper[0]^.ref^.symbol.offset<-63) then
                           begin
-                            current_asmdata.getjumplabel(l);
-                            list.insertafter(tai_label.create(l),curtai);
-                            list.insertafter(taicpu.op_sym(A_JMP,taicpu(curtai).oper[0]^.ref^.symbol),curtai);
-                            taicpu(curtai).oper[0]^.ref^.symbol:=l;
-                            taicpu(curtai).condition:=inverse_cond(taicpu(curtai).condition);
-                            again:=true;
+                            if inasmblock then
+                              Message(asmw_e_short_jmp_out_of_range)
+                            else
+                              begin
+                                current_asmdata.getjumplabel(l);
+                                list.insertafter(tai_label.create(l),curtai);
+                                list.insertafter(taicpu.op_sym(A_JMP,taicpu(curtai).oper[0]^.ref^.symbol),curtai);
+                                taicpu(curtai).oper[0]^.ref^.symbol:=l;
+                                taicpu(curtai).condition:=inverse_cond(taicpu(curtai).condition);
+                                again:=true;
+                              end;
                           end;
                       A_JMP:
                         { replace JMP by RJMP? ...
diff --git a/tests/webtbf/tw32949.pp b/tests/webtbf/tw32949.pp
new file mode 100644
index 0000000000..2f21f9017a
--- /dev/null
+++ b/tests/webtbf/tw32949.pp
@@ -0,0 +1,16 @@
+{ %CPU=avr }
+{ %fail }
+{$goto on}
+program test;
+label lbl;
+
+begin
+  asm
+    lbl:
+    nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
+    nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
+    nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
+    nop; nop; nop;
+    breq lbl
+  end;
+end.