From 7d9077ccfb7f733d205b90a1729b4e258e88ea5e Mon Sep 17 00:00:00 2001 From: guzhihao4 Date: Mon, 7 Oct 2024 18:23:06 +0800 Subject: [PATCH] [tmp]Fix unexcepted lines in coverage Remove compiler generated cxx global variable initial functions in coverage Should be reverted after llvm-17, the upstream fix this in llvm-17. Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/IAV6FO Signed-off-by: guzhihao4 Change-Id: I4b2d413e449f61bcc5923958d6d2441ee848be5b --- llvm/lib/ProfileData/GCOV.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/llvm/lib/ProfileData/GCOV.cpp b/llvm/lib/ProfileData/GCOV.cpp index feacf40b8d0a..c2dd3dba432b 100644 --- a/llvm/lib/ProfileData/GCOV.cpp +++ b/llvm/lib/ProfileData/GCOV.cpp @@ -111,6 +111,7 @@ bool GCOVFile::readGCNO(GCOVBuffer &buf) { buf.getWord(); // hasUnexecutedBlocks uint32_t tag, length; + bool skip = false; // OHOS_LOCAL GCOVFunction *fn = nullptr; while ((tag = buf.getWord())) { if (!buf.readInt(length)) @@ -144,6 +145,11 @@ bool GCOVFile::readGCNO(GCOVBuffer &buf) { filenames.emplace_back(filename); fn->srcIdx = r.first->second; identToFunction[fn->ident] = fn; + // OHOS_LOCAL + // Compiler generated cxx global variable initial functions is counted into coverage, + // and it is not user code, so we skip it. + // This is fixed in llvm-17, should be revert after that. + skip = (fn->Name.startswith("__cxx_global_var_init") && fn->startLine == 0); } else if (tag == GCOV_TAG_BLOCKS && fn) { if (version < GCOV::V800) { for (uint32_t i = 0; i != length; ++i) { @@ -186,8 +192,10 @@ bool GCOVFile::readGCNO(GCOVBuffer &buf) { GCOVBlock &Block = *fn->blocks[srcNo]; for (;;) { uint32_t line = buf.getWord(); - if (line) - Block.addLine(line); + // OHOS_LOCAL + if (line) { + if (!skip) Block.addLine(line); + } else { StringRef filename; buf.readString(filename); -- Gitee