编译简单C++程序时,llvm中的分析数据无法解释



在分析以下main.cpp文件时,我得到了"0";对于";test1 complete";指示当我期望得到"0"时该行还没有被执行的行;1〃;

main.cpp

#include <cassert>
#include <iostream>
using namespace std;
void test1() {
cout << "test1 start" << endl;
string pdx;
assert(pdx == "");
cout << "test1 complete" << endl;
}
int main() {
test1();
cout << "Done." << endl;
}

为了评测代码,我使用的脚本是:

#!/bin/bash
clang++ -g -std=c++11 -fprofile-instr-generate -fcoverage-mapping main.cpp
# Execute the program
./a.out
llvm-profdata merge default.profraw -output=merged.profraw
llvm-cov report -show-functions=1  ./a.out -instr-profile=merged.profraw main.cpp
llvm-cov show ./a.out -instr-profile=merged.profraw 
rm a.out *.profraw
# $ clang++ --version
# clang version 13.0.1 (Red Hat 13.0.1-2.module+el8.6.0+987+d36ea6a1)
# Target: x86_64-unknown-linux-gnu
# Thread model: posix
# InstalledDir: /usr/bin

如果我去掉下面的行,我会得到预期的结果

string pdx;
assert(pdx == "");

分析main.cpp 的输出

$ ./check-code-coverage.sh 
test1 start
test1 complete
Done.
File '/home/cssuwbstudent/pisan/bitbucket/pisan342/check-overage/main.cpp':
Name                        Regions    Miss   Cover     Lines    Miss   Cover  Branches    Miss   Cover
-------------------------------------------------------------------------------------------------------
_Z5test1v                         1       0 100.00%         6       1  83.33%         0       0   0.00%
main                              1       0 100.00%         4       0 100.00%         0       0   0.00%
-------------------------------------------------------------------------------------------------------
TOTAL                             2       0 100.00%        10       1  90.00%         0       0   0.00%
1|       |#include <cassert>
2|       |#include <iostream>
3|       |
4|       |using namespace std;
5|       |
6|      1|void test1() {
7|      1|  cout << "test1 start" << endl;
8|      1|  string pdx;
9|      1|  assert(pdx == "");
10|      0|  cout << "test1 complete" << endl;
11|      1|}
12|       |
13|      1|int main() {
14|      1|  test1();
15|      1|  cout << "Done." << endl;
16|      1|}
$

任何见解都将不胜感激。

这是一个错误,应该向制作clang的人报告。

最新更新