Frama-c不能证明后藤实现的循环

ztmd8pv5  于 2024-01-06  发布在  其他
关注(0)|答案(1)|浏览(119)
  • 环境:24.0( chrome )
  • 命令:frama-c -wp -wp-legacy xx. c
  1. #include <stdlib.h>
  2. int r;
  3. /*@
  4. requires \valid_read(a + (0 .. length-1)) && length > 0;
  5. assigns r;
  6. ensures \forall size_t off ; 0 <= off < length ==> a[off] != r;
  7. */
  8. void notin(int* a, size_t length) {
  9. int result = 0;
  10. int max = 0;
  11. size_t i = 0;
  12. assign_part:
  13. if (a[i] >= max) {
  14. max = a[i];
  15. }
  16. result = max + 1;
  17. i = i + 1;
  18. if (i < length) {
  19. goto assign_part;
  20. }
  21. r = result;
  22. }

字符串
错误消息显示:

  1. [kernel] Parsing goto_test/while_2_goto_version.c (with preprocessing)
  2. [wp] Warning: Missing RTE guards
  3. [wp] goto_test/while_2_goto_version.c:14: Warning:
  4. Missing assigns clause (assigns 'everything' instead)
  5. [wp] 6 goals scheduled
  6. [wp] [Alt-Ergo ] Goal typed_notin_assigns_part2 : Timeout (Qed:4ms) (10s)
  7. [wp] Proved goals: 5 / 6
  8. Qed: 4 (3ms-10ms-30ms)
  9. Alt-Ergo : 1 (6ms) (44) (interrupted: 1)
  10. [wp] goto_test/while_2_goto_version.c:8: Warning:
  11. Memory model hypotheses for function 'notin':
  12. /*@ behavior wp_typed:
  13. requires \separated(a + (..), &r


使用while循环实现的等效代码可以通过frama-c证明:

  1. #include <stdlib.h>
  2. int r;
  3. /*@
  4. requires \valid_read(a + (0 .. length-1)) && length > 0;
  5. assigns r;
  6. ensures \forall size_t off ; 0 <= off < length ==> a[off] != r;
  7. */
  8. void notin(int* a, size_t length) {
  9. int result = 0;
  10. int max = 0;
  11. size_t i = 0;
  12. /*@ loop invariant 0 <= i <= length;
  13. @ loop invariant \forall size_t j; 0 <= j < i ==> a[j] <= max;
  14. @ loop invariant \forall size_t k; 0 <= k < i ==> a[k] != result;
  15. @ loop assigns i, result, max;
  16. */
  17. while (i < length) {
  18. if (a[i] >= max) {
  19. max = a[i];
  20. }
  21. result = max + 1;
  22. i = i + 1;
  23. }
  24. r = result;
  25. }

l2osamch

l2osamch1#

从Frama-C 23开始,使用gotos实现的循环(称为“非自然循环”)的支持已被删除。主要是因为它在旧的WP引擎中可能是错误的。这是WP手册中列出的已知限制(第1.6节):
https://frama-c.com/download/wp-manual-28.0-Nickel.pdf
在新的WP引擎中添加此支持是可能的,但需要大量的工作。

相关问题