From 4caa875442b929f78dfee1d8e02d09ab5b289f64 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 15 Feb 2020 10:10:01 +0900 Subject: [PATCH] Finish up alignment tests and add address cast It turns out that initializing a local int with a pointer cast doesn't work. --- tools/qfcc/test/Makefile.am | 10 ++++++++++ tools/qfcc/test/address-cast.r | 17 +++++++++++++++++ tools/qfcc/test/alignment.r | 29 ++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tools/qfcc/test/address-cast.r diff --git a/tools/qfcc/test/Makefile.am b/tools/qfcc/test/Makefile.am index cdc9d8c01..c13bfd9d0 100644 --- a/tools/qfcc/test/Makefile.am +++ b/tools/qfcc/test/Makefile.am @@ -29,6 +29,7 @@ test_bins=\ fail_bins= test_progs_dat=\ + address-cast.dat \ alignment.dat \ chewed-alias.dat \ chewed-return.dat \ @@ -89,6 +90,15 @@ test_harness_DEPENDENCIES= $(QFCC_TEST_DEPS) r_depfiles_remade= +address_cast_dat_SOURCES=address-cast.r +address_cast_obj=$(address_cast_dat_SOURCES:.r=.qfo) +address-cast.dat$(EXEEXT): $(address_cast_obj) $(QFCC_DEP) + $(QFCC) $(QCFLAGS) -o $@ $(address_cast_obj) +address-cast.run: Makefile build-run + $(srcdir)/build-run $@ +include ./$(DEPDIR)/address-cast.Qo # am--include-marker +r_depfiles_remade += ./$(DEPDIR)/address-cast.Qo + alignment_dat_SOURCES=alignment.r alignment_obj=$(alignment_dat_SOURCES:.r=.qfo) alignment.dat$(EXEEXT): $(alignment_obj) $(QFCC_DEP) diff --git a/tools/qfcc/test/address-cast.r b/tools/qfcc/test/address-cast.r new file mode 100644 index 000000000..b9f11640d --- /dev/null +++ b/tools/qfcc/test/address-cast.r @@ -0,0 +1,17 @@ +int a; +double b; +int c; +double d; +void printf (string fmt, ...) = #0; + +int main() +{ + int di = (int) &d; + int fail = 0; + + if (!di) { + printf ("address cast fail: %d\n", di); + fail |= 1; + } + return fail; +} diff --git a/tools/qfcc/test/alignment.r b/tools/qfcc/test/alignment.r index 819f45d30..9b867b2d6 100644 --- a/tools/qfcc/test/alignment.r +++ b/tools/qfcc/test/alignment.r @@ -2,8 +2,35 @@ int a; double b; int c; double d; +void printf (string fmt, ...) = #0; int main() { - return 1; + int fail = 0; + void *ap = &a; + void *bp = &b; + void *cp = &c; + void *dp = &d; + int aa = (int) ap; + int ba = (int) bp; + int ca = (int) cp; + int da = (int) dp; + + if (ba & 1) { + printf ("double b is not aligned: %d\n", ba); + fail |= 1; + } + if (da & 1) { + printf ("double d is not aligned: %d\n", da); + fail |= 1; + } + if (ca - aa != 1) { + printf ("int c (%d) is not adjacant to int a (%d)\n", ca, aa); + fail |= 1; + } + if (ba <= ca) { + printf ("double b does not come after int c: %d %d\n", ba, ca); + fail |= 1; + } + return fail; }