Skip to content

Commit fd48dc8

Browse files
committed
Return Btop for undefined pointer comparisons in non-strict mode
Comparing pointers from different blocks with `< <= > >=` is undefined behavior in CompCert and in ISO C. So, it is sound to analyze such comparisons as `Bnone`. However, these comparisons occur in real code, and produce statically-unpredictable Boolean results, so it is safer and more consistent with other parts of the value analysis to return `Btop` in non-strict mode. Currently, this should make no difference to the generated code, since CompCert does not optimize based on the absence of undefined comparisons.
1 parent 18ecb24 commit fd48dc8

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

backend/ValueDomain.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,19 @@ Definition cmp_different_blocks (c: comparison) : abool :=
373373
match c with
374374
| Ceq => Maybe false
375375
| Cne => Maybe true
376-
| _ => Bnone
376+
| _ => if va_strict tt then Bnone else Btop
377377
end.
378378

379379
Lemma cmp_different_blocks_none:
380380
forall c, cmatch None (cmp_different_blocks c).
381381
Proof.
382-
intros; destruct c; constructor.
382+
unfold cmp_different_blocks. destruct c, (va_strict tt); constructor.
383383
Qed.
384384

385385
Lemma cmp_different_blocks_sound:
386386
forall c, cmatch (Val.cmp_different_blocks c) (cmp_different_blocks c).
387387
Proof.
388-
intros; destruct c; constructor.
388+
unfold cmp_different_blocks. destruct c, (va_strict tt); constructor.
389389
Qed.
390390

391391
Definition pcmp (c: comparison) (p1 p2: aptr) : abool :=

0 commit comments

Comments
 (0)