From c8b082a3abe44138fff4ef824300270dd6e8bc77 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 17 Jun 2020 10:17:15 -0700 Subject: [PATCH] [llvm-cov gcov] Support clang<11 fake 4.2 format Test cases are restored from a3bed4bd3743b5fee1e66116a63089df742bcae1 --- llvm/lib/ProfileData/GCOV.cpp | 16 +++++-- .../tools/llvm-cov/Inputs/gcov-fake-4.2.gcda | Bin 0 -> 904 bytes .../tools/llvm-cov/Inputs/gcov-fake-4.2.gcno | Bin 0 -> 3552 bytes llvm/test/tools/llvm-cov/gcov-fake-4.2.c | 39 ++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 llvm/test/tools/llvm-cov/Inputs/gcov-fake-4.2.gcda create mode 100644 llvm/test/tools/llvm-cov/Inputs/gcov-fake-4.2.gcno create mode 100644 llvm/test/tools/llvm-cov/gcov-fake-4.2.c diff --git a/llvm/lib/ProfileData/GCOV.cpp b/llvm/lib/ProfileData/GCOV.cpp index 35d40db11716..71ea44a1a722 100644 --- a/llvm/lib/ProfileData/GCOV.cpp +++ b/llvm/lib/ProfileData/GCOV.cpp @@ -175,16 +175,24 @@ bool GCOVFile::readGCDA(GCOVBuffer &buf) { if (tag == GCOV_TAG_OBJECT_SUMMARY) { buf.readInt(RunCount); buf.readInt(dummy); + // clang<11 uses a fake 4.2 format which sets length to 9. + if (length == 9) + buf.readInt(RunCount); } else if (tag == GCOV_TAG_PROGRAM_SUMMARY) { - buf.readInt(dummy); - buf.readInt(dummy); - buf.readInt(RunCount); + // clang<11 uses a fake 4.2 format which sets length to 0. + if (length > 0) { + buf.readInt(dummy); + buf.readInt(dummy); + buf.readInt(RunCount); + } ++ProgramCount; } else if (tag == GCOV_TAG_FUNCTION) { if (length == 0) // Placeholder continue; // As of GCC 10, GCOV_TAG_FUNCTION_LENGTH has never been larger than 3. - if ((length != 2 && length != 3) || !buf.readInt(ident)) + // However, clang<11 uses a fake 4.2 format which may set length larger + // than 3. + if (length < 2 || !buf.readInt(ident)) return false; auto It = IdentToFunction.find(ident); uint32_t linenoChecksum, cfgChecksum = 0; diff --git a/llvm/test/tools/llvm-cov/Inputs/gcov-fake-4.2.gcda b/llvm/test/tools/llvm-cov/Inputs/gcov-fake-4.2.gcda new file mode 100644 index 0000000000000000000000000000000000000000..613e3a85c02678566e12df9cf0487adea393c222 GIT binary patch literal 904 zcmYdHNlw=?GB7cSb5LYpU|?he5+ERVLR^CxNXJL{89Ev|xt4)N7c#PdX$A%+R2r<0 z5h!+iWA-A5KJ(Jz)ST4fVvtURKBzVr#mE6HT7Z8BaKqez6kN|~g`7awW5DoO7X=Yw#NoHbBW>so@dQoNy zBxr$VNC4&0-HRUHFh0x}-gV oo?+&|XrOYiK2Y2p{!%jso)4Uj2BYz#0O(&w6aWAK literal 0 HcmV?d00001 diff --git a/llvm/test/tools/llvm-cov/Inputs/gcov-fake-4.2.gcno b/llvm/test/tools/llvm-cov/Inputs/gcov-fake-4.2.gcno new file mode 100644 index 0000000000000000000000000000000000000000..24f1c82476b2cc2cbab056e962a919771042cdd7 GIT binary patch literal 3552 zcmd5zy+2`j5(3mmd^wU@hd2(s3@qA z5H%7_3Mlv!{D)Lfz6`6M7`{4r$bY33WHbnVIP!=wfXh|+o12Tw!q@7$qW4b zq{upVOp7*rf&KRR`FrNO^df4kH=<}W#W!P?O_ndmjQJjaNG3rRe zsAo&XM?SIl$R`Bn3Jd#y9W}zjc<5LM*~>Q?84o+&k%ev0lRn@R>-I5-M#e!07Z$dG z51*m1{`*-t%g*{EpPLc`Jd$U%3oCii*b5H7@{XfmC4U-w(cxF}sj)5&vL71j@+rESpTZ!G(R zo_r6yE4cG_lqUV0L6`5`QJ9Ue57>|NEy5jo(g*xv9e?uxcK0y&$bRWsxkAsb(KScc zb-H2+OpcR#n(XHr1iVRCHeNupz<#G;*0FMA%j1C+J~N~aG=ARVFk!6ZbrkHd-YzM> z*jK3^?RSx$EjjQ~UmAalu(us}sY8vwOW1o3ywtVEFB7(`@X1=$_!S3M>Q!TPzQI9y zPGj%Wv%uk7>Qm!gSgC!Dec