summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2197.c
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/regression/tests/bug-2197.c
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/regression/tests/bug-2197.c')
-rw-r--r--support/regression/tests/bug-2197.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/support/regression/tests/bug-2197.c b/support/regression/tests/bug-2197.c
new file mode 100644
index 0000000..be2a384
--- /dev/null
+++ b/support/regression/tests/bug-2197.c
@@ -0,0 +1,50 @@
+/*
+ bug-2197.c - originally part of the tests from the execute part of the gcc torture suite (see 20020503-1.c).
+ Heavily modified to reproduce the underlying issue of bug 2197 on multiple architectures.
+ */
+
+#include <testfwk.h>
+
+#if defined(__SDCC_MODEL_SMALL) || defined(__SDCC_MODEL_MEDIUM) || \
+ (defined(__SDCC_mcs51) && defined(__SDCC_STACK_AUTO)) || defined(__SDCC_pdk15)
+#define N 32
+#else
+#define N 128
+#endif
+
+/* PR 6534 */
+/* GCSE unified the two i<0 tests, but if-conversion to ui=abs(i)
+ inserted the code at the wrong place corrupting the i<0 test. */
+
+static char *
+inttostr (long i, char buf[N])
+{
+ unsigned long ui = i;
+ char *p = buf + (N-1);
+ *p = '\0';
+ if (i < 0)
+ ui = -ui;
+ do
+ *--p = '0' + ui % 10;
+ while ((ui /= 10) != 0);
+ if (i < 0)
+ *--p = '-';
+ return p;
+}
+
+void
+testTortureExecute (void)
+{
+#ifndef __SDCC_pdk14 // Lack of memory
+ char buf[N], *p;
+
+ p = inttostr (-1, buf);
+
+ ASSERT(p[0] == '-');
+ ASSERT(p[1] == '1');
+ ASSERT(p[2] == '\0');
+ ASSERT(p == buf + (N-1) - 2);
+
+ return;
+#endif
+}