From 54920193e5e00574179a27abf9b4fc39f71b7a89 Mon Sep 17 00:00:00 2001
From: mrdudz <mrdudz@users.noreply.github.com>
Date: Sat, 27 Mar 2021 15:11:47 +0100
Subject: [PATCH] added test for issue #1438

---
 test/val/bug1438.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 test/val/bug1438.c

diff --git a/test/val/bug1438.c b/test/val/bug1438.c
new file mode 100644
index 000000000..93addb877
--- /dev/null
+++ b/test/val/bug1438.c
@@ -0,0 +1,35 @@
+
+/* Issue #1438 fix #1439 - crash in cc65, related to delayed post-counting 
+
+  this is an odd issue, the compile would crash *sometimes*, perhaps in one
+  of ten compilation runs.
+*/
+
+#define __fastcall__
+
+unsigned short a[10] = {0,1,2,3,4,5,6,7,8,9};
+
+unsigned short __fastcall__ func2(void)
+{
+    return 42;
+}
+
+void func1(unsigned short *wp)
+{
+    *wp++ = func2();
+}
+
+int main(void)
+{
+    func1(&a[3]);
+    if (a[2] != 2) {
+        return 1;
+    }
+    if (a[3] != 42) {
+        return 1;
+    }
+    if (a[4] != 4) {
+        return 1;
+    }
+    return 0;
+}