diff options
-rw-r--r-- | .gitlab-ci.yml | 3 | ||||
-rw-r--r-- | aarch64/Asmexpand.ml | 5 | ||||
-rw-r--r-- | arm/Asmexpand.ml | 4 | ||||
-rw-r--r-- | kvx/SelectOp.vp | 44 | ||||
-rw-r--r-- | kvx/SelectOpproof.v | 108 | ||||
-rw-r--r-- | powerpc/Asmexpand.ml | 4 | ||||
-rw-r--r-- | riscV/Asmexpand.ml | 4 | ||||
-rw-r--r-- | test/gourdinl/builtin_memcpy.c | 9 | ||||
-rw-r--r-- | test/monniaux/codegen/comp0.c | 3 | ||||
-rw-r--r-- | test/monniaux/csmith/Makefile | 29 | ||||
-rwxr-xr-x | test/monniaux/csmith/reduce/reduce.sh | 15 | ||||
-rwxr-xr-x | test/monniaux/csmith/reduce/reduce_wrt_host.sh | 37 | ||||
-rw-r--r-- | test/regression/Makefile | 2 | ||||
-rw-r--r-- | test/regression/Results/many_parameters | 1 | ||||
-rw-r--r-- | test/regression/many_parameters.c (renamed from test/monniaux/params/call_many.c) | 0 | ||||
-rw-r--r-- | test/regression/ran000373_reduced.c | 36 |
16 files changed, 271 insertions, 33 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1ecdafdf..69965541 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -220,6 +220,7 @@ build_rv64: - make -j "$NJOBS" - make -C test SIMU='qemu-riscv64 -L /usr/riscv64-linux-gnu' EXECUTE='qemu-riscv64 -L /usr/riscv64-linux-gnu' all test - ulimit -s65536 && make -C test/monniaux/yarpgen TARGET_CC='riscv64-linux-gnu-gcc' EXECUTE='qemu-riscv64 -L /usr/riscv64-linux-gnu' + # disabled until https://github.com/AbsInt/CompCert/issues/412 is fixed - ulimit -s65536 && make -C test/monniaux/csmith TARGET_CC='riscv64-linux-gnu-gcc' EXECUTE='timeout 10s qemu-riscv64 -L /usr/riscv64-linux-gnu' CCOMPOPTS='-static' TARGET_CFLAGS='-static' rules: - if: '$CI_COMMIT_BRANCH == "kvx-work"' @@ -272,8 +273,8 @@ build_kvx: - source /opt/kalray/accesscore/kalray.sh && ./config_kvx.sh - source /opt/kalray/accesscore/kalray.sh && make -j "$NJOBS" - source /opt/kalray/accesscore/kalray.sh && make -C test CCOMPOPTS=-static SIMU='kvx-cluster -- ' EXECUTE='kvx-cluster -- ' all test + - source /opt/kalray/accesscore/kalray.sh && ulimit -s65536 && make -C test/monniaux/csmith TARGET_CC='kvx-cos-gcc' CCOMPOPTS="-Wl,--defsym=USER_STACK_SIZE=0x80000" EXECUTE="timeout 15s kvx-cluster -- " - source /opt/kalray/accesscore/kalray.sh && ulimit -s65536 && make -C test/monniaux/yarpgen TARGET_CC='kvx-cos-gcc' EXECUTE='kvx-cluster -- ' CCOMPOPTS='-static' TARGET_CFLAGS='-static' - - source /opt/kalray/accesscore/kalray.sh && ulimit -s65536 && make -C test/monniaux/csmith TARGET_CC='kvx-cos-gcc' EXECUTE='timeout 10s kvx-cluster -- ' CCOMPOPTS='-static' TARGET_CFLAGS='-static' rules: - if: '$CI_COMMIT_BRANCH == "kvx-work"' when: always diff --git a/aarch64/Asmexpand.ml b/aarch64/Asmexpand.ml index 828c96d6..20262fe8 100644 --- a/aarch64/Asmexpand.ml +++ b/aarch64/Asmexpand.ml @@ -185,14 +185,15 @@ let memcpy_small_arg sz arg tmp = | BA_addrstack ofs -> if offset_in_range ofs && offset_in_range (Ptrofs.add ofs (Ptrofs.repr (Z.of_uint sz))) + && (Z.to_int ofs) mod 8 = 0 then (XSP, ofs) else begin expand_addimm64 (RR1 tmp) XSP ofs; (RR1 tmp, _0) end | _ -> assert false let expand_builtin_memcpy_small sz al src dst = - let (tsrc, tdst) = - if dst <> BA (DR(IR(RR1 X17))) then (X17, X29) else (X29, X17) in + let tsrc = if dst <> BA (DR(IR(RR1 X17))) then X17 else X29 in + let tdst = if src <> BA (DR(IR(RR1 X29))) then X29 else X17 in let (rsrc, osrc) = memcpy_small_arg sz src tsrc in let (rdst, odst) = memcpy_small_arg sz dst tdst in let rec copy osrc odst sz = diff --git a/arm/Asmexpand.ml b/arm/Asmexpand.ml index 629d0fcc..b81ae74b 100644 --- a/arm/Asmexpand.ml +++ b/arm/Asmexpand.ml @@ -111,8 +111,8 @@ let memcpy_small_arg sz arg tmp = assert false let expand_builtin_memcpy_small sz al src dst = - let (tsrc, tdst) = - if dst <> BA (IR IR2) then (IR2, IR3) else (IR3, IR2) in + let tsrc = if dst <> BA (IR IR2) then IR2 else IR3 in + let tdst = if src <> BA (IR IR3) then IR3 else IR2 in let (rsrc, osrc) = memcpy_small_arg sz src tsrc in let (rdst, odst) = memcpy_small_arg sz dst tdst in let rec copy osrc odst sz = diff --git a/kvx/SelectOp.vp b/kvx/SelectOp.vp index aa241c1e..16607cf5 100644 --- a/kvx/SelectOp.vp +++ b/kvx/SelectOp.vp @@ -64,29 +64,49 @@ Section SELECT. Context {hf: helper_functions}. +Inductive to_cond0 := +| Cond0_some : condition0 -> expr -> to_cond0 +| Cond0_none : to_cond0 +| Cond0_true : to_cond0 +| Cond0_false : to_cond0. + +Definition compu0 c e1 := + match c with + | Clt => Cond0_false + | Cge => Cond0_true + | _ => Cond0_some (Ccompu0 c) e1 + end. + +Definition complu0 c e1 := + match c with + | Clt => Cond0_false + | Cge => Cond0_true + | _ => Cond0_some (Ccomplu0 c) e1 + end. + Nondetfunction cond_to_condition0 (cond : condition) (args : exprlist) := match cond, args with | (Ccompimm c x), (e1 ::: Enil) => if Int.eq_dec x Int.zero - then Some ((Ccomp0 c), e1) - else None + then Cond0_some (Ccomp0 c) e1 + else Cond0_none | (Ccompuimm c x), (e1 ::: Enil) => if Int.eq_dec x Int.zero - then Some ((Ccompu0 c), e1) - else None + then compu0 c e1 + else Cond0_none | (Ccomplimm c x), (e1 ::: Enil) => if Int64.eq_dec x Int64.zero - then Some ((Ccompl0 c), e1) - else None + then Cond0_some (Ccompl0 c) e1 + else Cond0_none | (Ccompluimm c x), (e1 ::: Enil) => if Int64.eq_dec x Int64.zero - then Some ((Ccomplu0 c), e1) - else None + then complu0 c e1 + else Cond0_none - | _, _ => None + | _, _ => Cond0_none end. (** Ternary operator *) @@ -112,8 +132,10 @@ Definition same_expr_pure (e1 e2: expr) := Definition select (ty : typ) (cond : condition) (args : exprlist) (e1 e2: expr) : option expr := Some (if same_expr_pure e1 e2 then e1 else match cond_to_condition0 cond args with - | None => select0 ty (Ccomp0 Cne) e1 e2 (Eop (Ocmp cond) args) - | Some(cond0, ec) => select0 ty cond0 e1 e2 ec + | Cond0_none => select0 ty (Ccomp0 Cne) e1 e2 (Eop (Ocmp cond) args) + | Cond0_some cond0 ec => select0 ty cond0 e1 e2 ec + | Cond0_true => e1 + | Cond0_false => e2 end). diff --git a/kvx/SelectOpproof.v b/kvx/SelectOpproof.v index a7169881..45aa3343 100644 --- a/kvx/SelectOpproof.v +++ b/kvx/SelectOpproof.v @@ -1533,6 +1533,70 @@ Proof. apply Val.swap_cmplu_bool. Qed. +Lemma int_ltu_zero : forall i, Int.ltu i Int.zero = false. +Proof. + intro. + unfold Int.ltu. + apply zlt_false. + rewrite Int.unsigned_zero. + pose proof (Int.unsigned_range i). + lia. +Qed. + +Lemma cmpu_bool_Clt : forall pred v0 b, + Val.cmpu_bool pred Clt v0 (Vint Int.zero) = Some b -> b = false. +Proof. + intros until b. intro CMP. + destruct v0; cbn in CMP; try discriminate. + inv CMP. + apply int_ltu_zero. +Qed. + +Lemma cmpu_bool_Cge : forall pred v0 b, + Val.cmpu_bool pred Cge v0 (Vint Int.zero) = Some b -> b = true. +Proof. + intros until b. intro CMP. + destruct v0; cbn in CMP; try discriminate. + inv CMP. + rewrite int_ltu_zero. + reflexivity. +Qed. + +Lemma int64_ltu_zero : forall i, Int64.ltu i Int64.zero = false. +Proof. + intro. + unfold Int64.ltu. + apply zlt_false. + rewrite Int64.unsigned_zero. + pose proof (Int64.unsigned_range i). + lia. +Qed. + +Lemma cmplu_bool_Clt : forall pred v0 b, + Val.cmplu_bool pred Clt v0 (Vlong Int64.zero) = Some b -> b = false. +Proof. + intros until b. intro CMP. + destruct v0; cbn in CMP; try discriminate. + { inv CMP. + apply int64_ltu_zero. + } + repeat rewrite if_same in CMP. + discriminate. +Qed. + +Lemma cmplu_bool_Cge : forall pred v0 b, + Val.cmplu_bool pred Cge v0 (Vlong Int64.zero) = Some b -> b = true. +Proof. + intros until b. intro CMP. + destruct v0; cbn in CMP; try discriminate. + { inv CMP. + rewrite int64_ltu_zero. + reflexivity. + } + repeat rewrite if_same in CMP. + discriminate. +Qed. + Theorem eval_select: forall le ty cond al vl a1 v1 a2 v2 a b, select ty cond al a1 a2 = Some a -> @@ -1581,8 +1645,27 @@ Proof. simpl. change (Val.cmpu_bool (Mem.valid_pointer m) c v0 (Vint Int.zero)) with (eval_condition0 (Ccompu0 c) v0 m). - eapply eval_select0; eassumption. - } + destruct c. + all: try (eapply eval_select0; eassumption). + all: cbn. + all: cbn in HeC. + { + destruct (Val.cmpu_bool (Mem.valid_pointer m) Clt v0 (Vint Int.zero)) eqn:CMP; try discriminate. + inv HeC. + rewrite (cmpu_bool_Clt (Mem.valid_pointer m) v0 b CMP). + cbn. + exists v2. + split; auto using Val.lessdef_normalize. + } + { + destruct (Val.cmpu_bool (Mem.valid_pointer m) Cge v0 (Vint Int.zero)) eqn:CMP; try discriminate. + inv HeC. + rewrite (cmpu_bool_Cge (Mem.valid_pointer m) v0 b CMP). + cbn. + exists v1. + split; auto using Val.lessdef_normalize. + } + } simpl. erewrite <- (bool_cond0_ne (Val.cmpu_bool (Mem.valid_pointer m) c v0 (Vint x))). eapply eval_select0; repeat (try econstructor; try eassumption). @@ -1609,7 +1692,26 @@ Proof. simpl. change (Val.cmplu_bool (Mem.valid_pointer m) c v0 (Vlong Int64.zero)) with (eval_condition0 (Ccomplu0 c) v0 m). - eapply eval_select0; eassumption. + destruct c. + all: try (eapply eval_select0; eassumption). + all: cbn. + all: cbn in HeC. + { + destruct (Val.cmplu_bool (Mem.valid_pointer m) Clt v0 (Vlong Int64.zero)) eqn:CMP; try discriminate. + inv HeC. + rewrite (cmplu_bool_Clt (Mem.valid_pointer m) v0 b CMP). + cbn. + exists v2. + split; auto using Val.lessdef_normalize. + } + { + destruct (Val.cmplu_bool (Mem.valid_pointer m) Cge v0 (Vlong Int64.zero)) eqn:CMP; try discriminate. + inv HeC. + rewrite (cmplu_bool_Cge (Mem.valid_pointer m) v0 b CMP). + cbn. + exists v1. + split; auto using Val.lessdef_normalize. + } } simpl. erewrite <- (bool_cond0_ne (Val.cmplu_bool (Mem.valid_pointer m) c v0 (Vlong x))). diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index e663226f..63bcfeea 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -104,8 +104,8 @@ let memcpy_small_arg sz arg tmp = assert false let expand_builtin_memcpy_small sz al src dst = - let (tsrc, tdst) = - if dst <> BA (IR GPR11) then (GPR11, GPR12) else (GPR12, GPR11) in + let tsrc = if dst <> BA (IR GPR11) then GPR11 else GPR12 in + let tdst = if dst <> BA (IR GPR12) then GPR12 else GPR11 in let (rsrc, osrc) = memcpy_small_arg sz src tsrc in let (rdst, odst) = memcpy_small_arg sz dst tdst in let rec copy osrc odst sz = diff --git a/riscV/Asmexpand.ml b/riscV/Asmexpand.ml index 50dc20be..329dd34c 100644 --- a/riscV/Asmexpand.ml +++ b/riscV/Asmexpand.ml @@ -170,8 +170,8 @@ let memcpy_small_arg sz arg tmp = assert false let expand_builtin_memcpy_small sz al src dst = - let (tsrc, tdst) = - if dst <> BA (IR X5) then (X5, X6) else (X6, X5) in + let tsrc = if dst <> BA (IR X5) then X5 else X6 in + let tdst = if src <> BA (IR X6) then X6 else X5 in let (rsrc, osrc) = memcpy_small_arg sz src tsrc in let (rdst, odst) = memcpy_small_arg sz dst tdst in let rec copy osrc odst sz = diff --git a/test/gourdinl/builtin_memcpy.c b/test/gourdinl/builtin_memcpy.c new file mode 100644 index 00000000..421f543c --- /dev/null +++ b/test/gourdinl/builtin_memcpy.c @@ -0,0 +1,9 @@ +struct a b; +struct a { + short; + int; + short; +} c() { + struct a d[2][16]; + b = d[1][7]; +} diff --git a/test/monniaux/codegen/comp0.c b/test/monniaux/codegen/comp0.c new file mode 100644 index 00000000..60f8ba77 --- /dev/null +++ b/test/monniaux/codegen/comp0.c @@ -0,0 +1,3 @@ +int toto(unsigned x) { + return (x < 0) ? 1 : 2; +} diff --git a/test/monniaux/csmith/Makefile b/test/monniaux/csmith/Makefile index aa4eccab..1412921d 100644 --- a/test/monniaux/csmith/Makefile +++ b/test/monniaux/csmith/Makefile @@ -1,9 +1,16 @@ +all: + +.SECONDARY: + INCLUDES=-I csmith/include/csmith-2.3.0/ TARGET_CCOMP=../../../ccomp + +ifndef TARGET_CC TARGET_CC=gcc +endif ifndef EXECUTE -EXECUTE=timeout 2s +EXECUTE=timeout 10s endif CFLAGS += -Wno-incompatible-pointer-types @@ -11,12 +18,13 @@ CFLAGS += -Wno-incompatible-pointer-types ifndef CSMITH CSMITH=csmith/bin/csmith endif +CSMITHOPT=--max-funcs 10 --no-packed-struct -MAX=300 +MAX=500 PREFIX=ran%06.f -CCOMPOTS=-static -CCOMPFLAGS+= -fstruct-passing -fbitfields -fno-cse2 -stdlib ../../../runtime +# CCOMPOPTS=-Wl,--defsym=USER_STACK_SIZE=0x80000 +CCOMPFLAGS+= -fstruct-passing -fbitfields -fno-cse2 -fno-cse -fno-cse3 -stdlib ../../../runtime TESTS_C=$(shell seq --format $(PREFIX)/source.c 1 $(MAX)) @@ -69,12 +77,13 @@ ran%/example.gcc.host: ran%/source.gcc.host.o ran%/source.c: mkdir -p ran$* - $(CSMITH) --seed $* --output ran$*/source.c + $(CSMITH) $(CSMITHOPT) --seed $* --output ran$*/source.c -ran%/example.target.cmp : ran%/example.gcc.target.out ran%/example.ccomp.target.out +ran%/example.target.cmp : ran%/example.ccomp.target.out ran%/example.gcc.target.out cmp $+ > $@ + cat $< -ran%/example.host_target.cmp : ran%/example.gcc.host.out ran%/example.ccomp.target.out +ran%/example.host_target.cmp : ran%/example.ccomp.target.out ran%/example.gcc.host.out cmp $+ > $@ .PHONY: all clean tests_c tests_c @@ -82,7 +91,9 @@ ran%/example.host_target.cmp : ran%/example.gcc.host.out ran%/example.ccomp.targ clean: -rm -rf ran* -csmith/bin/csmith: - curl -L -o csmith-2.3.0.tar.gz https://embed.cs.utah.edu/csmith/csmith-2.3.0.tar.gz +csmith-2.3.0.tar.gz: + curl -L -o $@ https://embed.cs.utah.edu/csmith/csmith-2.3.0.tar.gz + +csmith/bin/csmith: csmith-2.3.0.tar.gz tar xfz csmith-2.3.0.tar.gz WD=`pwd` && cd csmith-2.3.0 && ./configure --prefix=$$WD/csmith && make install diff --git a/test/monniaux/csmith/reduce/reduce.sh b/test/monniaux/csmith/reduce/reduce.sh new file mode 100755 index 00000000..d8df11a5 --- /dev/null +++ b/test/monniaux/csmith/reduce/reduce.sh @@ -0,0 +1,15 @@ +#!/bin/bash +INCLUDE=-I$COMPCERT/test/monniaux/csmith/csmith/include/csmith-2.3.0 +if kvx-cos-gcc $INCLUDE -Werror=uninitialized -Werror=implicit source.c -o source.gcc.target && kvx-cluster -- source.gcc.target >& source.gcc.log +then + if $COMPCERT/ccomp $INCLUDE -fall -fno-cse -fno-cse2 -fno-cse3 source.c -o source.ccomp.target + then + kvx-cluster -- source.ccomp.target >& source.ccomp.log + grep OPCODE source.ccomp.log + else + exit 2 + fi +else + exit 1 +fi + diff --git a/test/monniaux/csmith/reduce/reduce_wrt_host.sh b/test/monniaux/csmith/reduce/reduce_wrt_host.sh new file mode 100755 index 00000000..7a11596f --- /dev/null +++ b/test/monniaux/csmith/reduce/reduce_wrt_host.sh @@ -0,0 +1,37 @@ +#!/bin/bash +INCLUDE=-I$COMPCERT/test/monniaux/csmith/csmith/include/csmith-2.3.0 +if /usr/bin/clang $INCLUDE -O -Werror=int-conversion -Werror=format -Werror=strict-prototypes -Werror=uninitialized -Werror=implicit -Werror=return-type source.c -o source.clang.host && valgrind --exit-on-first-error=yes --error-exitcode=120 --log-file=valgrind.out ./source.clang.host > source.clang.host.out ; +then + if gcc $INCLUDE -Werror=int-conversion -Werror=format -Werror=strict-prototypes -Werror=uninitialized -Werror=implicit -Werror=return-type -fsanitize=undefined -fsanitize=address source.c -o source.gcc+san.host && ./source.gcc+san.host > source.gcc+san.host.out ; + then + if grep "runtime error" source.gcc+san.host.out + then + exit 66 + fi + if cmp source.clang.host.out source.gcc+san.host.out && riscv64-linux-gnu-gcc $INCLUDE -Werror=format -Werror=uninitialized -Werror=implicit source.c -Werror=return-type -o source.gcc.target && qemu-riscv64 -L /usr/riscv64-linux-gnu source.gcc.target >& source.gcc.target.out && grep checksum source.gcc.target.out > source.gcc.target.check && diff source.clang.host.out source.gcc.target.out + then + if $COMPCERT/ccomp $INCLUDE -Werror=missing-declarations -fall -fno-cse -fno-cse2 -fno-cse3 source.c -o source.ccomp.target + then + qemu-riscv64 -L /usr/riscv64-linux-gnu source.ccomp.target >& source.ccomp.target.out + if grep checksum source.ccomp.target.out > source.ccomp.target.check + then + if diff source.ccomp.target.check source.gcc.target.check + then exit 40 + else exit 0 + fi + else + exit 50 + fi + else + exit 2 + fi + else + exit 1 + fi + else + exit 4 + fi +else + exit 5 +fi + diff --git a/test/regression/Makefile b/test/regression/Makefile index c56532ff..69d25980 100644 --- a/test/regression/Makefile +++ b/test/regression/Makefile @@ -18,7 +18,7 @@ TESTS?=int32 int64 floats floats-basics floats-lit \ funct3 expr5 struct7 struct8 struct11 struct12 casts1 casts2 char1 \ sizeof1 sizeof2 binops bool for1 for2 switch switch2 compound \ decl1 bitfields9 ptrs3 \ - parsing krfun ifconv union_passing + parsing krfun ifconv many_parameters union_passing # Can run, but only in compiled mode, and have reference output in Results diff --git a/test/regression/Results/many_parameters b/test/regression/Results/many_parameters new file mode 100644 index 00000000..838cfd7e --- /dev/null +++ b/test/regression/Results/many_parameters @@ -0,0 +1 @@ +1780 diff --git a/test/monniaux/params/call_many.c b/test/regression/many_parameters.c index 4d2529c0..4d2529c0 100644 --- a/test/monniaux/params/call_many.c +++ b/test/regression/many_parameters.c diff --git a/test/regression/ran000373_reduced.c b/test/regression/ran000373_reduced.c new file mode 100644 index 00000000..3f26e88a --- /dev/null +++ b/test/regression/ran000373_reduced.c @@ -0,0 +1,36 @@ +#include <stdint.h> +#include <stdio.h> +uint32_t au, cc, bk; +union ba { + int64_t bb; +}; +int32_t *ck; +int32_t **cr = &ck; +void a(uint32_t c, int d) { printf("checksum = %X\n", c); } +void av(uint8_t b) { au = b; } +void aw(uint64_t ax) { av(ax); } +void ay(uint64_t ax, char *az, int d) { aw(ax); } +static const int32_t df(int64_t, union ba, uint16_t, uint8_t); +const int32_t dh(int32_t, int32_t, uint32_t); +int16_t e(void) { + union ba f = {5}; + int32_t g = 5; + int32_t i[90269]; + uint32_t s = df(dh(0, 0, cc), f, g, 7); + return s; +} +const int32_t df(int64_t j, union ba k, uint16_t l, uint8_t m) { + *ck = k.bb; + return l; +} +const int32_t dh(int32_t n, int32_t o, uint32_t p) { + int32_t *t = &bk; + uint64_t q = 3; + *cr = t; + return q; +} +int main(void) { + int r = e(); + ay(bk, "", r); + a(au, r); +} |