小编Yus*_*suf的帖子

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

在分析以下 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 …
Run Code Online (Sandbox Code Playgroud)

c++ profiling llvm clang

5
推荐指数
1
解决办法
220
查看次数

标签 统计

c++ ×1

clang ×1

llvm ×1

profiling ×1