changeset 884:f915d5ba033e

struct init in function argument in parse_mode fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 05 Apr 2014 19:37:34 +0900
parents 05c2757853b1
children 1a027275743d
files Changes mc-parse.c test/strinit.c
diffstat 3 files changed, 33 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Thu Apr 03 18:24:45 2014 +0900
+++ b/Changes	Sat Apr 05 19:37:34 2014 +0900
@@ -10004,15 +10004,34 @@
 expr14 の中で LOCAL_STRUCT_INIT_STATIC すると、再帰的に行われるので、local struct を再利用する必要があるが、
 その時の offset を知りえないという問題がある。
 
+もしlocal_structに値を設定しないなら全部同じ comm にしてよい。その方が合理的か?
+local_struct_static 以外だといろいろ動かなくなっているようだ。
 decl_data 側で再帰構造定義を処理してやると、それは避けられるらしい。
-
-local_struct_static 以外だといろいろ動かなくなっているようだ。
-
 でも、局所構造体はゼロ初期化しなければならないので、local_struct_static が正しいだろう。
 ということは、decl_data 側で再帰定義を扱うのが正しいのだろうな。
-
 local_struct_offset を大域変数にしてやれば良い。(いや、それは難しすぎる)
 
-
-
-
+初期化に穴がないならゼロクリアする必要はない。初期化の穴が小さいなら、その場でゼロクリアする方が良い。
+なので、LOCAL_STRUCT_INIT_STATIC はやめたほうが良いのではないか。その代わりzero clear routineを書く。
+emit_copy を使うのが簡単だが。
+
+Sat Apr  5 11:36:03 JST 2014
+
+やっぱりRSTUCTなくすべきだろ?
+
+        } else if((t=car(type))==ARRAY) {       
+            type=list2(POINTER,cadr(type));
+            if(car(e)==INDIRECT) return cadr(e);
+            return list2(ADDRESS,e);
+        } else if(t==STRUCT || t==UNION) { return e;
+
+ARRAYとSTRUCTは、作った時にleft value、つまり ADDRESS なはず。rvalue で、ADDRESSに変換するのはおかしい。
+どちらも同じ扱いなはずなら、そのまま return e が正しいはず。
+
+arrayop ってのがないのは、pointer に対して [] できるからだが、そこで ARRAY を処理するのが正しい。
+ARRAY なら、そこで添字の範囲もチェックできる。
+
+(なのだが、これを修正して、その他の部分の整合性を合わせるのは大変だ…)
+
+inmode と parse_mode の両方をdebugするのが辛い。parse_mode=0 は、もはや使わないのだが。
+
--- a/mc-parse.c	Thu Apr 03 18:24:45 2014 +0900
+++ b/mc-parse.c	Sat Apr 05 19:37:34 2014 +0900
@@ -4252,22 +4252,19 @@
                         e1 = list4(CAST,e1,t,t); // only for cast syntax
                     }
                 } else {
-                    int e2;
                     nptr0 = get_nptr(); // should be freed in a scope?
                                         // in case of inline, we cannot
                     nptr0->nm = "";
                     nptr0->sc = EMPTY;
                     nptr0->attr = 0;
                     type = nptr0->ty = t;
-                    e1 = size(type);
                     def(nptr0,0);
-                    e2 = list3n(nptr0->sc,nptr0->dsp,nptr0);
+                    e1 = list3n(nptr0->sc,nptr0->dsp,nptr0);
 #if LOCAL_STRUCT_INIT_STATIC 
-                    local_struct_static(e2); 
+                    local_struct_static(e1); 
 #else
-                    decl_data_field(type,e2,0);
+                    decl_data_field(type,e1,0);
 #endif
-                    e1 = list3(RSTRUCT,e2,e1);
                 }
                 if (init_vars && mode!=LDECL) {
                     emit_init_vars();
--- a/test/strinit.c	Thu Apr 03 18:24:45 2014 +0900
+++ b/test/strinit.c	Sat Apr 05 19:37:34 2014 +0900
@@ -214,17 +214,19 @@
 
 }
 
+struct arg { int hage, fuga; int aho; };
 
 
-struct arg { int hage, fuga; int aho; };
 
 INLINE void f(struct arg h) {
     printf("#0221:%d %d %d\n",h.hage,h.fuga,h.aho);
 }
 
 INLINE int main8() {
+     struct arg a = {11,22,33};
+     f(a);
      f((struct arg){.fuga = 3,.aho=5});
-     printf("#0226:%d\n",((struct arg){.aho=120, .hage=55}).aho); return 0;
+     printf("#0226:%d %d\n",a.aho,((struct arg){.aho=120, .hage=55}).aho); return 0;
 }
 
 int