From b09669dffe04ed05fa7f4c19cdde5a2531be0668 Mon Sep 17 00:00:00 2001
From: florian <florian@freepascal.org>
Date: Fri, 9 Apr 2021 20:09:19 +0000
Subject: [PATCH]   * allow also CSUBSETREG in
 tx86inlinenode.second_IncludeExclude, resolves #38733

git-svn-id: trunk@49151 -
---
 .gitattributes           |  1 +
 compiler/x86/nx86inl.pas |  3 ++-
 tests/webtbs/tw38733.pp  | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 tests/webtbs/tw38733.pp

diff --git a/.gitattributes b/.gitattributes
index bc6e8cfc1d..9e09692d5c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -18775,6 +18775,7 @@ tests/webtbs/tw3865.pp svneol=native#text/plain
 tests/webtbs/tw38695.pp svneol=native#text/pascal
 tests/webtbs/tw3870.pp svneol=native#text/plain
 tests/webtbs/tw38703.pp svneol=native#text/pascal
+tests/webtbs/tw38733.pp svneol=native#text/pascal
 tests/webtbs/tw3893.pp svneol=native#text/plain
 tests/webtbs/tw3898.pp svneol=native#text/plain
 tests/webtbs/tw3899.pp svneol=native#text/plain
diff --git a/compiler/x86/nx86inl.pas b/compiler/x86/nx86inl.pas
index c26cbd5a32..09d351c853 100644
--- a/compiler/x86/nx86inl.pas
+++ b/compiler/x86/nx86inl.pas
@@ -1075,8 +1075,9 @@ implementation
                       ((tcallparanode(tcallparanode(left).right).left.location.value-setbase) div bitsperop)*tcgsize2size[opsize]);
                     cg.a_op_const_ref(current_asmdata.CurrAsmList,cgop,opsize,l,tcallparanode(left).left.location.reference);
                   end;
+                LOC_CSUBSETREG,
                 LOC_CREGISTER :
-                  cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,tcallparanode(left).left.location.size,l,tcallparanode(left).left.location.register);
+                  hlcg.a_op_const_loc(current_asmdata.CurrAsmList,cgop,tcallparanode(left).left.resultdef,l,tcallparanode(left).left.location);
                 else
                   internalerror(200405022);
               end;
diff --git a/tests/webtbs/tw38733.pp b/tests/webtbs/tw38733.pp
new file mode 100644
index 0000000000..391659ae6f
--- /dev/null
+++ b/tests/webtbs/tw38733.pp
@@ -0,0 +1,38 @@
+type
+       TSimpleEnum = (seOne, seTwo);
+       TSimpleSet = set of TSimpleEnum;
+
+       TRecordWithSet = record
+               TheSet  :       TSimpleSet;
+       end;
+
+function FirstFunc:TRecordWithSet;
+begin
+       FirstFunc.TheSet := [];
+
+       //below would work fine
+       //FirstFunc.TheSet := FirstFunc.TheSet + [seOne];
+
+       //below line causes error "Fatal: Internal error 200405022"
+       Include(FirstFunc.TheSet, seOne);
+	   if not(seOne in FirstFunc.TheSet) then
+	     halt(1);
+end;
+
+//absolute variable overlaying Result doesn't help
+function SecondFunc:TRecordWithSet;
+var
+       LocalAbs        : TRecordWithSet absolute SecondFunc;
+begin
+       LocalAbs.TheSet := [];
+       //below line would cause same error
+       Include(LocalAbs.TheSet, seOne);
+	   if not(seOne in LocalAbs.TheSet) then
+	     halt(1);
+end;
+
+var
+       Collected       : TRecordWithSet;
+begin
+       Collected := FirstFunc;
+end.