From e6b8f4d71581883083d0bb34e67141ad0b2e53c5 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 19 Aug 2020 22:25:18 +0200 Subject: [PATCH] move/fix bug264.c as suggested in issue #1122 --- test/err/bug264.c | 62 +++++++++++++++++++++ test/{misc/bug264.c => val/return-struct.c} | 0 2 files changed, 62 insertions(+) create mode 100644 test/err/bug264.c rename test/{misc/bug264.c => val/return-struct.c} (100%) diff --git a/test/err/bug264.c b/test/err/bug264.c new file mode 100644 index 000000000..6898f3790 --- /dev/null +++ b/test/err/bug264.c @@ -0,0 +1,62 @@ +/* bug #264 - cc65 fails to warn about a function returning struct */ + +#include +#include +#include + +typedef uint32_t u32; +typedef uint16_t u16; + +/* this struct is too large, we can only handle max 4 bytes right now */ +typedef struct { + u32 quot; + u32 rem; +} udiv_t; + +udiv_t div3(u32 in) { + + udiv_t u; + u32 q = 0; + + while (in >= 300) { + in -= 300; + q += 100; + } + + while (in >= 30) { + in -= 30; + q += 10; + } + + while (in >= 3) { + in -= 3; + ++q; + } + + u.quot = q; + u.rem = in; + + return u; /* error */ +} + +int res = 0; + +int main(void) { + + u32 i; + div_t d; + udiv_t u; + + for (i = 1024; i; i--) { + d = div((u16)i, 3); + u = div3(i); + + if (d.quot != u.quot || d.rem != u.rem) { + printf("Mismatch at %u/3, div %u %u, div3 %u %u\n", i, + d.quot, d.rem, u.quot, u.rem); + res++; + } + } + + return res; +} diff --git a/test/misc/bug264.c b/test/val/return-struct.c similarity index 100% rename from test/misc/bug264.c rename to test/val/return-struct.c