From f60f7f06ece056d14cba24a7395f33698d727705 Mon Sep 17 00:00:00 2001
From: Erwan Jahier <jahier@imag.fr>
Date: Fri, 22 Aug 2014 14:43:52 +0200
Subject: [PATCH] soc2c: fix the code generated for array concatenation (which
 was raising a warning and a Seg fault).

---
 src/socPredef2c.ml                |  6 +++---
 test/Makefile                     |  2 +-
 test/lus2lic.sum                  | 30 +++++++++++++++---------------
 test/lus2lic.time                 | 16 +++++++---------
 test/should_work/array_concat.lus |  4 ++++
 todo.org                          |  8 ++++----
 6 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/src/socPredef2c.ml b/src/socPredef2c.ml
index 659ee1eb..49bab233 100644
--- a/src/socPredef2c.ml
+++ b/src/socPredef2c.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 14/08/2014 (at 16:37) by Erwan Jahier> *)
+(* Time-stamp: <modified the 22/08/2014 (at 14:34) by Erwan Jahier> *)
 
 open Data
 open Soc
@@ -106,8 +106,8 @@ let (lustre_concat: Soc.key -> string) =
     let t1 = Printf.sprintf "%s.x" ctx
     and t2 = Printf.sprintf "%s.y" ctx  
     and t12 = Printf.sprintf "%s.z" ctx in  
-    (Printf.sprintf "  memcpy(%s, %s, sizeof(%s));\n" t12 t1 t1)^ 
-      (Printf.sprintf "  memcpy(%s[%d], %s, sizeof(%s));\n" t12 s1 t2 t2) 
+    (Printf.sprintf "  memcpy(&%s, &%s, sizeof(%s));\n" t12 t1 t1)^ 
+      (Printf.sprintf "  memcpy(&%s[%d], &%s, sizeof(%s));\n" t12 s1 t2 t2) 
 (* Both seems to work *)
 (*      let buff = ref "" in  *)
 (*      for j=0 to s1-1 do  *)
diff --git a/test/Makefile b/test/Makefile
index d8dccd89..439845f1 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -36,7 +36,7 @@ lus2lic.diff:
 	(cat lus2lic.diff; echo "make utest if it is fine"; exit 1)
 
 time:lus2lic.time
-lus2lic.time:
+lus2lic.time:lus2lic.sum
 	grep "testcase \./lus2lic" lus2lic*.log > lus2lic.time
 	echo "* Ref time: " >> lus2lic.time
 	cat lus2lic.ref_time >> lus2lic.time || true 
diff --git a/test/lus2lic.sum b/test/lus2lic.sum
index a4f2a8e6..757e5d91 100644
--- a/test/lus2lic.sum
+++ b/test/lus2lic.sum
@@ -1,4 +1,4 @@
-Test Run By jahier on Fri Aug 22 14:22:57 
+Test Run By jahier on Fri Aug 22 14:36:14 
 Native configuration is i686-pc-linux-gnu
 
 		=== lus2lic0 tests ===
@@ -64,7 +64,7 @@ XFAIL: Test bad programs (assert): test_lus2lic_no_node should_fail/assert/eq1.l
 
 # of expected passes		1
 # of expected failures		50
-Test Run By jahier on Fri Aug 22 14:23:02 
+Test Run By jahier on Fri Aug 22 14:36:20 
 Native configuration is i686-pc-linux-gnu
 
 		=== lus2lic1 tests ===
@@ -94,7 +94,7 @@ PASS: gcc aa_aa.c aa_aa_loop.c
 PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c aa.lus 
 PASS: ./lus2lic {-2c array_concat.lus -n array_concat}
 PASS: gcc array_concat_array_concat.c array_concat_array_concat_loop.c 
-FAIL: Try to compare lus2lic -exec and -2c: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c array_concat.lus 
+PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c array_concat.lus 
 FAIL: Generate c code  : ./lus2lic {-2c activation1.lus -n activation1}
 FAIL: Generate c code  : ./lus2lic {-2c asservi.lus -n asservi}
 PASS: ./lus2lic {-2c alias.lus -n alias}
@@ -423,9 +423,9 @@ PASS: ./lus2lic {-2c Int.lus -n Int}
 
 		=== lus2lic1 Summary ===
 
-# of expected passes		324
-# of unexpected failures	22
-Test Run By jahier on Fri Aug 22 14:23:48 
+# of expected passes		325
+# of unexpected failures	21
+Test Run By jahier on Fri Aug 22 14:37:16 
 Native configuration is i686-pc-linux-gnu
 
 		=== lus2lic2 tests ===
@@ -753,7 +753,7 @@ PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c X.lus
 
 # of expected passes		303
 # of unexpected failures	10
-Test Run By jahier on Fri Aug 22 14:25:19 
+Test Run By jahier on Fri Aug 22 14:38:53 
 Native configuration is i686-pc-linux-gnu
 
 		=== lus2lic3 tests ===
@@ -1258,7 +1258,7 @@ PASS: ./myec2c {-o Int.c Int.ec}
 
 # of expected passes		475
 # of unexpected failures	15
-Test Run By jahier on Fri Aug 22 14:26:38 
+Test Run By jahier on Fri Aug 22 14:39:54 
 Native configuration is i686-pc-linux-gnu
 
 		=== lus2lic4 tests ===
@@ -1704,12 +1704,12 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node X.lus
 
 # of expected passes		421
 # of unexpected failures	10
-lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 4 seconds
-lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 45 seconds
-lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 89 seconds
-lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 78 seconds
-lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 118 seconds
+lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 5 seconds
+lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 56 seconds
+lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 95 seconds
+lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 60 seconds
+lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 116 seconds
 * Ref time: 
-0.11user 0.07system 5:39.34elapsed 0%CPU (0avgtext+0avgdata 2472maxresident)k
-0inputs+0outputs (0major+12526minor)pagefaults 0swaps
+0.12user 0.06system 5:36.96elapsed 0%CPU (0avgtext+0avgdata 2464maxresident)k
+0inputs+0outputs (0major+12518minor)pagefaults 0swaps
 * Quick time (-j 4):
diff --git a/test/lus2lic.time b/test/lus2lic.time
index 093c5f44..2be98903 100644
--- a/test/lus2lic.time
+++ b/test/lus2lic.time
@@ -1,11 +1,9 @@
-lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 3 seconds
-lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 46 seconds
-lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 80 seconds
-lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 49 seconds
-lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 110 seconds
+lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 5 seconds
+lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 56 seconds
+lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 95 seconds
+lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 60 seconds
+lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 116 seconds
 * Ref time: 
-0.12user 0.07system 4:52.81elapsed 0%CPU (0avgtext+0avgdata 2472maxresident)k
-0inputs+0outputs (0major+12520minor)pagefaults 0swaps
+0.12user 0.06system 5:36.96elapsed 0%CPU (0avgtext+0avgdata 2464maxresident)k
+0inputs+0outputs (0major+12518minor)pagefaults 0swaps
 * Quick time (-j 4):
-0.09user 0.06system 2:43.74elapsed 0%CPU (0avgtext+0avgdata 2476maxresident)k
-0inputs+0outputs (0major+12508minor)pagefaults 0swaps
diff --git a/test/should_work/array_concat.lus b/test/should_work/array_concat.lus
index 84fa41ca..4ebaf3c4 100644
--- a/test/should_work/array_concat.lus
+++ b/test/should_work/array_concat.lus
@@ -2,4 +2,8 @@ node array_concat(x:bool) returns (y: bool^2);
 let
 	y = [x]|[x];
 tel
+node array_concat_bis(x:bool^1) returns (y: bool^2);
+let
+	y = x|x;
+tel
 
diff --git a/todo.org b/todo.org
index e8bfda7b..88944e0d 100644
--- a/todo.org
+++ b/todo.org
@@ -35,18 +35,18 @@ generates incorrect ec code instead of raising an error.
 
 grep "FAIL:" lus2lic*.log | grep "exec" | grep "\-2c" | sed s/'FAIL: Try to compare lus2lic -exec and -2c:'/-/
 
-1. ../utils/compare_exec_and_2c should_work/test_node_expand2.lus
+1. ../utils/compare_exec_and_2c should_work/test_node_expand2.lus 2000
   -> -2110104000 est n'est pas un entier acceptable pour lutin sur les machines 32 bits...
 
-2. ../utils/compare_exec_and_2c should_work/test_node_expand.lus
+2. ../utils/compare_exec_and_2c should_work/test_node_expand.lus 2000
   -> idem
 
 3. ../utils/compare_exec_and_2c should_work/PCOND1.lus 2000
    -> File "../obj-linux/socExecValue.ml", line 243, characters 6-12: Assertion failed
 
-4. ../utils/compare_exec_and_2c should_work/multipar.lus
+4. ../utils/compare_exec_and_2c should_work/multipar.lus 2000
   -> pb  32bits
-5. ../utils/compare_exec_and_2c should_work/array_concat.lus
+5. ../utils/compare_exec_and_2c should_work/array_concat.lus 2000
   -> le a.out fait un segmentation fault
 
 ** TODO lic2c : le jour ou on genere du code C, y'a peut-etre des trucs a recuperer
-- 
GitLab