summaryrefslogtreecommitdiff
path: root/src/regression/ptrfunc.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 /src/regression/ptrfunc.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 'src/regression/ptrfunc.c')
-rw-r--r--src/regression/ptrfunc.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/regression/ptrfunc.c b/src/regression/ptrfunc.c
new file mode 100644
index 0000000..317b19f
--- /dev/null
+++ b/src/regression/ptrfunc.c
@@ -0,0 +1,106 @@
+#include "gpsim_assert.h"
+
+unsigned char failures=0;
+
+unsigned int uint0 = 0;
+unsigned int uint1 = 0;
+
+/*
+ * BUG: if these aren't volatile, an overzealous optimizer or somthing
+ * wreaks havoc with the simple tests like "if(uchar != 3)failures++"
+ */
+volatile unsigned char uchar0 = 0;
+volatile unsigned char uchar1 = 0;
+volatile unsigned char uchar2 = 0;
+
+void (*pfunc)();
+void (*p1func)();
+unsigned char (*pcfunc)();
+
+void
+done()
+{
+ ASSERT(MANGLE(failures) == 0);
+ PASSED();
+}
+
+void call0(void)
+{
+ uchar0++;
+}
+
+void call1(void)
+{
+ uchar1++;
+}
+
+unsigned char call2(void)
+{
+ return uchar0 + 9;
+}
+
+void docall0(void)
+{
+ pfunc = call0;
+ (pfunc)();
+ if(uchar0 != 1)
+ failures++;
+}
+
+void docall1()
+{
+ unsigned char i;
+ for(i = 0; i < 3; i++) {
+ (*p1func)();
+ }
+}
+
+void docall2( void(*pf)() )
+{
+ unsigned char i;
+ for(i = 0; i < 2; i++) {
+ pf();
+ }
+}
+
+void main(void)
+{
+ docall0();
+
+
+ p1func = call1;
+ docall1();
+ if(uchar1 != 3)
+ failures++;
+ if(uchar0 != 1)
+ failures++;
+
+ p1func = call0;
+ docall1();
+ if(uchar1 != 3)
+ failures++;
+ if(uchar0 != 4)
+ failures++;
+
+ docall2(call0);
+ if(uchar1 != 3)
+ failures++;
+ if(uchar0 != 6)
+ failures++;
+
+ docall2(call1);
+ if(uchar1 != 5)
+ failures++;
+ if(uchar0 != 6)
+ failures++;
+
+ pcfunc = call2;
+ uchar2 = (*pcfunc)();
+ if(uchar2 != 15)
+ failures++;
+/**/
+/* uchar2 += (pcfunc)(); */ /* FRONT-END BUG? - type-mismatch error */
+/* uchar2 += pcfunc(); */ /* FRONT-END BUG? - type-mismatch error */
+
+ done();
+}