Mercurial > hg > CbC > old > device
changeset 664:ec1bac997e50
fix 387 floating point stack overflow
author | kono |
---|---|
date | Sat, 28 Apr 2007 21:10:26 +0900 |
parents | 92a401bef729 |
children | 2cc418b247ce |
files | Changes Makefile mc-code-ia32.c mc-code-powerpc.c mc-codegen.c |
diffstat | 5 files changed, 106 insertions(+), 122 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sun Mar 04 18:24:10 2007 +0900 +++ b/Changes Sat Apr 28 21:10:26 2007 +0900 @@ -9207,3 +9207,14 @@ Wed Jan 24 14:12:20 JST 2007 get_register_var を使った後、free してない例が多いみたい。 + + +Sat Apr 28 21:00:15 JST 2007 + +どうも、code_dassop のテストをしてないらしい。 + +i387 の演算で、use flag を間違えると、387 のstack overflow +が出るらしい。g_expr は use flag を1にするので注意。 + + +
--- a/Makefile Sun Mar 04 18:24:10 2007 +0900 +++ b/Makefile Sat Apr 28 21:10:26 2007 +0900 @@ -1,48 +1,41 @@ -CC = gcc -std=c99 -# -O2 -# -O99 +# CC = gcc -std=c99 +CC = cc +# -O3 CFLAGS = -g -Wall -I. -DUSE_CODE_KEYWORD # CFLAGS = -g -Wall -I. -pg -fprofile-arcs -ftest-coverage # LDFLAGS = -pg # for Linux Zaurus # CFLAGS = -fsigned-char -pipe -g -I. -I/home/zaurus/develop/include -CFLAGS1 = -g -I. -DUSE_CODE_KEYWORD +CFLAGS1 = -g -I. BASE=0 STAGE=1 MFLAGS=$(MFALGS) BASE=$(BASE) STAGE=$(STAGE) -ARCH=powerpc +ARCH=ia32 MC=mc-$(ARCH) MLIB = -lm PRINTF= # printf.c -CONVERTER=conv/c.o conv/null.o conv/cbc2c.o conv/c2cbc.o - -# conv/c2cbc.o conv/cbc2c.o +CONVERTER=conv/c.o conv/null.o conv/c2cbc.o conv/cbc2c.o COMPLIB = mc-parse.o mc-codegen.o mc-switch.o mc-macro.o mc-tree.o mc-inline.o # CODE=mc-code-ia32.c CODE=mc-code-$(ARCH).c GCC_INCLUDE=`perl tools/find-gcc-include-path -p $(CC)` - +# # TARGET=test/simp -all: mc-include.c mc mc-spu - -allall: mc-include.c mc mc-ia32 mc-powerpc mc-mips mc-arm +all: mc-include.c mc mc: mc-$(ARCH) cp mc-$(ARCH) mc TAGS: - ctags mc-code-null.c mc-code.h mc-codegen.c mc-codegen.h \ + ctags mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h \ mc-macro.c \ mc-parse.c mc-tree.c mc-switch.c mc-switch.h \ mc.h conv/c.c conv/c.h \ mc-inline.h mc-inline.c \ conv/conv.h conv/convdef.h conv/null.c -mc-null : mc-code-null.o $(COMPLIB) $(CONVERTER) - $(CC) $(LDFLAGS) -g mc-code-null.o $(COMPLIB) $(CONVERTER) -o $@ - mc-powerpc : mc-code-powerpc.o $(COMPLIB) $(CONVERTER) $(CC) $(LDFLAGS) -g mc-code-powerpc.o $(COMPLIB) $(CONVERTER) -o $@ @@ -55,9 +48,6 @@ mc-arm : mc-code-arm.o $(COMPLIB) $(CONVERTER) $(CC) $(LDFLAGS) -g mc-code-arm.o $(COMPLIB) $(CONVERTER) -o $@ -mc-spu : mc-code-spu.o $(COMPLIB) $(CONVERTER) - $(CC) $(LDFLAGS) -g mc-code-spu.o $(COMPLIB) $(CONVERTER) -o $@ - conv/conv.h: conv_func.tbl tools/conv_func.pl perl tools/conv_func.pl conv/convdef.h: conv_func.tbl tools/conv_func.pl @@ -95,7 +85,7 @@ make check TARGET=test/tmp12 make check TARGET=test/tmp5 make check TARGET=test/tmp7 - make check-inline TARGET=test/tmp8 + make check TARGET=test/tmp8 make check TARGET=test/tmp9 make check TARGET=test/enum make check TARGET=test/obsf @@ -104,18 +94,15 @@ make check TARGET=test/tstdarg make check TARGET=test/switch make check TARGET=test/strinit - make check-inline TARGET=test/strinit make check TARGET=test/code-gen-all make check-inline TARGET=test/code-gen-all make check TARGET=test/bitfield make check TARGET=test/bitfield1 - make check-inline TARGET=test/bitfield1 make check TARGET=test/cext make check TARGET=test/const make check TARGET=test/void_code make check TARGET=test/putenemy make check TARGET=test/inline - make check TARGET=test/offset make check TARGET=test/ps2 make check TARGET=test/multi # make check TARGET=test/scope STDFLAG="-std=gnu99" @@ -130,15 +117,15 @@ make check-code$(MK) TARGET=test/fact make check-code$(MK) TARGET=test/goto make check-code$(MK) TARGET=test/test1 + make check-code$(MK) TARGET=test/test2 make check-code$(MK) TARGET=test/tmpa make check-code$(MK) TARGET=test/tmp1 make check-code$(MK) TARGET=test/tmp2 make check-code$(MK) TARGET=test/tmp4 make check-code$(MK) TARGET=test/tmp6 + make check-code$(MK) TARGET=test/tmpb make check-code$(MK) TARGET=test/scope make check-code$(MK) TARGET=test/throw - make check-code$(MK) TARGET=test/test2 - make check-code$(MK) TARGET=test/hoge make check-code$(MK) TARGET=test/too-long-argument check-nkf: @@ -152,7 +139,7 @@ check: mc $(MC) $(TARGET).c -$(CC) $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) -./b.out > $(TARGET).gcc.out - -./$(MC) -s $(TARGET).c + -./$(MC) -s $(TARGET).c -$(CC) $(TARGET).s $(MLIB) -./a.out > $(TARGET).$(MC).out -diff $(TARGET).gcc.out $(TARGET).$(MC).out @@ -160,18 +147,18 @@ check-inline: mc $(MC) $(TARGET).c -$(CC) $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) -./b.out > $(TARGET).gcc.out - -./$(MC) -s -DINLINE=inline $(TARGET).c + -./$(MC) -s -DINLINE=inline $(TARGET).c -$(CC) $(TARGET).s $(MLIB) -./a.out > $(TARGET).$(MC).out -diff $(TARGET).gcc.out $(TARGET).$(MC).out check-code: mc $(MC) - -./$(MC) -s $(TARGET).c + -./$(MC) -s $(TARGET).c -$(CC) $(TARGET).s $(MLIB) -./a.out > $(TARGET).$(MC).out -diff $(TARGET).code-out $(TARGET).$(MC).out check-code-make: mc $(MC) - -./$(MC) -s $(TARGET).c + -./$(MC) -s $(TARGET).c -$(CC) $(TARGET).s $(MLIB) -./a.out > $(TARGET).code-out @@ -193,19 +180,18 @@ make clean tar cBf - . | gzip > ../comp.tgz -depend : mc.h mc-include.c conv/conv.h +depend : mc.h mc-include.c makedepend -I$(GCC_INCLUDE) mc-code-ia32.c mc-code.h mc-codegen.c mc-codegen.h \ - mc-parse.c mc-tree.c mc-switch.c mc-switch.h mc.h \ - mc-inline.c mc-macro.c mc-macro.h mc-parse.h \ + mc-parse.c mc-tree.c mc-switch.c mc-switch.h mc.h \ + mc-inline.c mc-macro.c mc-macro.h mc-parse.h \ conv/c.c conv/c.h conv/c2cbc.c conv/c2cbc.h conv/cbc2c.c \ conv/cbc2c.h conv/conv.h conv/convdef.h conv/null.c conv/null.h \ - mc-code-arm.c \ - mc-code-powerpc.c \ - mc-code-mips.c + mc-code-arm.c \ + mc-code-powerpc.c \ + mc-code-mips.c clean : - -rm -f mc mc-null mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i *.cbc.? */*.cbc.? mc-include.h - -rm -f *.tsv ../test/*.tsv ../test/sample/*.tsv + -rm -f mc mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i mc-include.c mc1 : b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) $(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) @@ -263,61 +249,3 @@ # DO NOT DELETE -mc-code-ia32.o: /usr/include/stdio.h /usr/include/_types.h -mc-code-ia32.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-code-ia32.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-code-ia32.o: mc-parse.h mc-codegen.h mc-code.h mc-include.c -mc-codegen.o: /usr/include/stdio.h /usr/include/_types.h -mc-codegen.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-codegen.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-codegen.o: mc-parse.h mc-codegen.h mc-code.h mc-switch.h mc-inline.h -mc-codegen.o: conv/conv.h -mc-parse.o: /usr/include/stdio.h /usr/include/_types.h -mc-parse.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-parse.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-parse.o: mc-parse.h mc-codegen.h mc-switch.h mc-macro.h mc-inline.h -mc-parse.o: conv/conv.h -mc-tree.o: /usr/include/stdio.h /usr/include/_types.h -mc-tree.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-tree.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-tree.o: mc-parse.h mc-codegen.h -mc-switch.o: /usr/include/stdio.h /usr/include/_types.h -mc-switch.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-switch.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-switch.o: mc-parse.h mc-codegen.h mc-code.h -mc-inline.o: /usr/include/stdio.h /usr/include/_types.h -mc-inline.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-inline.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-inline.o: mc-parse.h mc-codegen.h mc-switch.h mc-code.h mc-inline.h -mc-macro.o: /usr/include/stdio.h /usr/include/_types.h -mc-macro.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-macro.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-macro.o: mc-parse.h mc-macro.h mc-codegen.h mc-code.h -conv/c.o: /usr/include/stdio.h /usr/include/_types.h -conv/c.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -conv/c.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -conv/c.o: mc-parse.h mc-codegen.h conv/conv.h conv/convdef.h conv/c.h -conv/c2cbc.o: /usr/include/stdio.h /usr/include/_types.h -conv/c2cbc.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -conv/c2cbc.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -conv/c2cbc.o: mc-parse.h mc-codegen.h conv/conv.h conv/convdef.h conv/c2cbc.h -conv/cbc2c.o: /usr/include/stdio.h /usr/include/_types.h -conv/cbc2c.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -conv/cbc2c.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -conv/cbc2c.o: mc-parse.h mc-codegen.h conv/conv.h conv/convdef.h conv/cbc2c.h -conv/null.o: /usr/include/stdio.h /usr/include/_types.h -conv/null.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -conv/null.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -conv/null.o: mc-parse.h conv/conv.h conv/convdef.h conv/null.h -mc-code-arm.o: /usr/include/stdio.h /usr/include/_types.h -mc-code-arm.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-code-arm.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-code-arm.o: mc-parse.h mc-code.h mc-codegen.h -mc-code-powerpc.o: /usr/include/stdio.h /usr/include/_types.h -mc-code-powerpc.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-code-powerpc.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h -mc-code-powerpc.o: mc.h mc-parse.h mc-code.h mc-codegen.h mc-include.c -mc-code-mips.o: /usr/include/stdio.h /usr/include/_types.h -mc-code-mips.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h -mc-code-mips.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-code-mips.o: mc-parse.h mc-code.h mc-codegen.h mc-include.c
--- a/mc-code-ia32.c Sun Mar 04 18:24:10 2007 +0900 +++ b/mc-code-ia32.c Sat Apr 28 21:10:26 2007 +0900 @@ -57,31 +57,31 @@ #define __CHAR_BIT__ 8\n\ #define __WCHAR_MAX__ 2147483647\n\ #define __DBL_DENORM_MIN__ 4.9406564584124654e-324\n\ -#define __FLT_EVAL_METHOD__ 2\n\ +#define __FLT_EVAL_METHOD__ 0\n\ #define __DBL_MIN_10_EXP__ (-307)\n\ #define __FINITE_MATH_ONLY__ 0\n\ -#define __GNUC_PATCHLEVEL__ 3\n\ #define __SHRT_MAX__ 32767\n\ #define __LDBL_MAX__ 1.18973149535723176502e+4932L\n\ +#define __APPLE_CC__ 5367\n\ #define __UINTMAX_TYPE__ long long unsigned int\n\ -#define __linux 1\n\ -#define __unix 1\n\ -#define __LDBL_MAX_EXP__ 16384\n\ -#define __linux__ 1\n\ #define __SCHAR_MAX__ 127\n\ -#define __USER_LABEL_PREFIX__ \n\ +#define __USER_LABEL_PREFIX__ _\n\ #define __STDC_HOSTED__ 1\n\ -#define __LDBL_HAS_INFINITY__ 1\n\ -#define __DBL_DIG__ 15 \n\ +#define __DBL_DIG__ 15\n\ #define __FLT_EPSILON__ 1.19209290e-7F\n\ -#define __unix__ 1\n\ +#define __LDBL_MIN__ 3.36210314311209350626e-4932L\n\ +#define __strong \n\ +#define __APPLE__ 1\n\ #define __DECIMAL_DIG__ 21\n\ -#define __gnu_linux__ 1\n\ #define __LDBL_HAS_QUIET_NAN__ 1\n\ +#define __DYNAMIC__ 1\n\ #define __GNUC__ 4\n\ +#define __MMX__ 1\n\ #define __DBL_MAX__ 1.7976931348623157e+308\n\ #define __DBL_HAS_INFINITY__ 1\n\ +#define __weak \n\ #define __DBL_MAX_EXP__ 1024\n\ +#define __SSE2_MATH__ 1\n\ #define __LONG_LONG_MAX__ 9223372036854775807LL\n\ #define __GXX_ABI_VERSION 1002\n\ #define __FLT_MIN_EXP__ (-125)\n\ @@ -91,6 +91,51 @@ #define __NO_INLINE__ 1\n\ #define __i386 1\n\ #define __FLT_MANT_DIG__ 24\n\ +#define __tune_nocona__ 1\n\ +#define i386 1\n\ +#define __i386__ 1\n\ +#define __SIZE_TYPE__ long unsigned int\n\ +#define __FLT_RADIX__ 2\n\ +#define __LDBL_EPSILON__ 1.08420217248550443401e-19L\n\ +#define __SSE_MATH__ 1\n\ +#define __FLT_HAS_QUIET_NAN__ 1\n\ +#define __FLT_MAX_10_EXP__ 38\n\ +#define __LONG_MAX__ 2147483647L\n\ +#define __FLT_HAS_INFINITY__ 1\n\ +#define __LITTLE_ENDIAN__ 1\n\ +#define __LDBL_MANT_DIG__ 64\n\ +#define __CONSTANT_CFSTRINGS__ 1\n\ +#define __WCHAR_TYPE__ int\n\ +#define __FLT_DIG__ 6\n\ +#define __INT_MAX__ 2147483647\n\ +#define __nocona 1\n\ +#define __FLT_MAX_EXP__ 128\n\ +#define __DBL_MANT_DIG__ 53\n\ +#define __WINT_TYPE__ int\n\ +#define __SSE__ 1\n\ +#define __LDBL_MIN_EXP__ (-16381)\n\ +#define __MACH__ 1\n\ +#define __LDBL_MAX_EXP__ 16384\n\ +#define __LDBL_MAX_10_EXP__ 4932\n\ +#define __DBL_EPSILON__ 2.2204460492503131e-16\n\ +#define __GNUC_PATCHLEVEL__ 1\n\ +#define __LDBL_HAS_INFINITY__ 1\n\ +#define __INTMAX_MAX__ 9223372036854775807LL\n\ +#define __FLT_DENORM_MIN__ 1.40129846e-45F\n\ +#define __PIC__ 1\n\ +#define __FLT_MAX__ 3.40282347e+38F\n\ +#define __SSE2__ 1\n\ +#define __FLT_MIN_10_EXP__ (-37)\n\ +#define __INTMAX_TYPE__ long long int\n\ +#define __nocona__ 1\n\ +#define __GNUC_MINOR__ 0\n\ +#define __DBL_MAX_10_EXP__ 308\n\ +#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L\n\ +#define __PTRDIFF_TYPE__ int\n\ +#define __LDBL_MIN_10_EXP__ (-4931)\n\ +#define __LDBL_DIG__ 18\n\ +#define __i386 1\n\ +#define __FLT_MANT_DIG__ 24\n\ #define __VERSION__ \"micro-c $Id$\"\n\ #define i386 1\n\ #define __i486__ 1\n\
--- a/mc-code-powerpc.c Sun Mar 04 18:24:10 2007 +0900 +++ b/mc-code-powerpc.c Sat Apr 28 21:10:26 2007 +0900 @@ -31,7 +31,7 @@ #include "mc-include.c" -#undef __APPLE__ +// #undef __APPLE__ static char *init_src0 = "\ @@ -3358,7 +3358,7 @@ register_name(REG_VAR_BASE-max_reg_var),reg_save,register_name(1)); printf("\tstw %s,8(%s)\n",register_name(0),register_name(1)); if (max_freg_var>=0) { -#ifdef __APPLE +#ifdef __APPLE__ printf("\tb saveFP+%d ; save f%d-f31\n", freg_save, FREG_VAR_BASE-max_freg_var);
--- a/mc-codegen.c Sun Mar 04 18:24:10 2007 +0900 +++ b/mc-codegen.c Sat Apr 28 21:10:26 2007 +0900 @@ -2498,7 +2498,7 @@ // oprtc expected if (car(e2)==LVAR||car(e2)==GVAR|| (car(e2)==INDIRECT&&car(cadr(e2))==REGISTER)) { - g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); + g_expr0(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); return; } #if 0 @@ -2509,7 +2509,7 @@ // たぶん、i386 の時には有効だったんだろうなぁ。 int n = list3(LVAR,new_lvar(size_of_int),0); // get register var? g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT)); - g_expr(assign_expr0(rvalue_t(n,INT), + g_expr0(assign_expr0(rvalue_t(n,INT), list3(op,rvalue_t(list2(INDIRECT,rvalue_t(n,INT)),t),e3),t,t)); free_lvar(cadr(n)); return; @@ -2550,7 +2550,7 @@ // oprtc expected if (car(e2)==LVAR||car(e2)==GVAR|| (car(e2)==INDIRECT&&car(cadr(e2))==REGISTER)) { - g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); + g_expr0(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); return; } } @@ -2606,19 +2606,19 @@ t = long_sign(op); if (car(e2)==LREGISTER||car(e2)==LVAR||car(e2)==GVAR|| (car(e2)==INDIRECT&&car(cadr(e2))==REGISTER)) { - g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); + g_expr0(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); return; } -#if 0 - /* new = &e2 */ - /* *new = *new op e3 */ - int n = list3(LVAR,new_lvar(size_of_int),0); - g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT)); - g_expr(assign_expr0(rvalue_t(n,INT), - list3(op,rvalue_t(list2(INDIRECT,rvalue_t(n,INT)),t),e3),t,t)); - free_lvar(cadr(n)); - return; -#endif + if (!code_lassop_p) { + /* new = &e2 */ + /* *new = *new op e3 */ + int n = list3(LVAR,new_lvar(size_of_int),0); + g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT)); + g_expr0(assign_expr0(rvalue_t(n,INT), + list3(op,rvalue_t(list2(INDIRECT,rvalue_t(n,INT)),t),e3),t,t)); + free_lvar(cadr(n)); + return; + } } g_expr(e3);