簡體   English   中英

消息“無法到達的入口點”是什么意思?

[英]What does the message “unreachable entry point” mean?

我有包含幾個ACSL斷言(文件file.c ):

#include <stdio.h>
#include <stdlib.h>

void foo()    {
  int a=0;
  //@ assert(a==0);
}

void print(const char* text)   {
    int a=0;
    //@ assert(a==0);
    printf("%s\n",text);
}

int main (int argc, const char* argv[])    {
    const char* a1 = argv[2];

    print(a1);
    foo();

    if (!a1)
      //@ assert(!a1);
        return 0;
    else
        return 1;
}

我想用命令切片所有斷言:

frama-c -slice-assert @all file.c -then-on 'Slicing export' -print -ocode slice.c

但是,切片看起來不符合預期(實際上,它不包含文件中包含的任何功能):

/* Generated by Frama-C */
typedef unsigned int size_t;
/*@ ghost extern int __fc_heap_status __attribute__((__FRAMA_C_MODEL__)); */

/*@
axiomatic dynamic_allocation {
  predicate is_allocable{L}(size_t n) 
    reads __fc_heap_status;

  }
 */
void main(void)
{
  char const *a1;
  return;
}

相反,我得到這樣的輸出:

file.c:16:[kernel] warning: out of bounds read. assert \valid_read(argv+2);
[value] Recording results for main
[value] done for function main
file.c:16:[value] Assertion 'Value,mem_access' got final status invalid.
[slicing] making slicing project 'Slicing'...
[slicing] interpreting slicing requests from the command line...
[pdg] computing for function foo
[pdg] warning: unreachable entry point (sid:1, function foo)
[pdg] Bottom for function foo
[slicing] bottom PDG for function 'foo': ignore selection
[pdg] computing for function main
file.c:21:[pdg] warning: no final state. Probably unreachable...
[pdg] done for function main
[pdg] computing for function print
[pdg] warning: unreachable entry point (sid:5, function print)
[pdg] Bottom for function print
[slicing] bottom PDG for function 'print': ignore selection

這里出了什么問題,特別是unreachable entry point什么? 觀察:如果我將argv[2]更改為argv[1]我沒有這些問題(但仍然在第一行得到警告)。

切片需要計算使用值分析結果的PDG(程序相關圖)。 警告unreachable entry point意味着,在您給出的上下文中,函數foo是不可訪問的(即,從不可訪問的語句調用它)。

沒有示例就很難告訴您更多...


編輯:

在您提供的輸出中,注意以下幾行:

file.c:16:[kernel] warning: out of bounds read. assert \valid_read(argv+2);

file.c:16:[value] Assertion 'Value,mem_access' got final status invalid.

當值分析遇到無效的屬性時,它將無法繼續進行。 因為此處警報來自第一個語句,所以其他所有內容均無法訪問。 無效的屬性為\\valid_read(argv+2); 因為輸入上下文的默認值是argv的寬度為2。 可以通過使用選項-context-width 3或通過使用不帶參數的分析其他入口點(並使用-main my_main指定)來解決此問題,該入口點不帶參數,顯式定義argcargv ,並使用調用真正的main他們。

建議僅在檢查值分析結果是否正確之后才使用切片。 您可以使用-val選項單獨運行它,並根據需要調整其他選項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM