Skip to content

Commit f6eb71d

Browse files
committed
[C2C] Extend proof generation.
Add support for non-strict binary expressions with non-pure operands. Also add tests to demonstrate this added support.
1 parent 574de09 commit f6eb71d

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

books/kestrel/c/transformation/proof-generation.lisp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,11 +1414,9 @@
14141414
both argument expressions are pure,
14151415
since the order of evaluation is unspecified in C.")
14161416
(xdoc::p
1417-
"For pure non-strict binary operators,
1418-
for now we also require both argument expressions to be pure
1419-
in order to generate a theorem.
1420-
But this could be relaxed, since in this case
1421-
the order of evaluation is prescribed.")
1417+
"For non-strict binary operators (which are pure),
1418+
the argument expressions may be pure or not,
1419+
because the order of evaluation is always determined.")
14221420
(xdoc::p
14231421
"For the non-pure strict simple assignment operator,
14241422
for theorem generation we require the left expression to be a variable.
@@ -1497,10 +1495,7 @@
14971495
:thm-name thm-name
14981496
:vartys gin.vartys))))
14991497
((member-eq (binop-kind op) '(:logand :logor))
1500-
(b* (((unless (and (expr-purep arg1)
1501-
(expr-purep arg2)))
1502-
(mv expr-new gout-no-thm))
1503-
((mv & old-arg1) (ldm-expr arg1)) ; ERP must be NIL
1498+
(b* (((mv & old-arg1) (ldm-expr arg1)) ; ERP must be NIL
15041499
((mv & old-arg2) (ldm-expr arg2)) ; ERP must be NIL
15051500
((mv & new-arg1) (ldm-expr arg1-new)) ; ERP must be NIL
15061501
((mv & new-arg2) (ldm-expr arg2-new)) ; ERP must be NIL

books/kestrel/c/transformation/tests/simpadd0/logand.lisp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
:content "int logand(short x, long y) {
3737
return x && y;
3838
}
39+
int logand_nonpure(int x, int y, int z) {
40+
return (x = z) && (y = ~z);
41+
}
3942
")
4043

4144
(assert-highest-thm-has-exec-fun *new-code*)

books/kestrel/c/transformation/tests/simpadd0/logor.lisp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
:content "int logor(short x, long y) {
3737
return x || y;
3838
}
39+
int logor_nonpure(int x, int y, int z) {
40+
return (x = !z) || (y = z);
41+
}
3942
")
4043

4144
(assert-highest-thm-has-exec-fun *new-code*)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
int logand(short x, long y) {
22
return x && y;
33
}
4+
5+
int logand_nonpure(int x, int y, int z) {
6+
return (x = z) && (y = ~z);
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
int logor(short x, long y) {
22
return x || y;
33
}
4+
5+
int logor_nonpure(int x, int y, int z) {
6+
return (x = !z + 0) || (y = z);
7+
}

0 commit comments

Comments
 (0)