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

Yus*_*suf 5 c++ profiling llvm clang

在分析以下 main.cpp 文件时,我在“test1 Complete”行中得到“0”,表明当我期望得到“1”时该行尚未执行

主程序

#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;
}
Run Code Online (Sandbox Code Playgroud)

为了分析代码,我使用的脚本是:

#!/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
Run Code Online (Sandbox Code Playgroud)

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

  string pdx;
  assert(pdx == "");
Run Code Online (Sandbox Code Playgroud)

分析 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|}

$
Run Code Online (Sandbox Code Playgroud)

任何见解将不胜感激。

Omn*_*ous 1

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

  • 已报告。其他人也重复了这个错误。https://github.com/llvm/llvm-project/issues/57481 (3认同)