r346642 - [Clang] Add options -fprofile-filter-files and -fprofile-exclude-files to filter the files to instrument with gcov
Author: calixte Date: Mon Nov 12 01:12:27 2018 New Revision: 346642 URL: http://llvm.org/viewvc/llvm-project?rev=346642&view=rev Log: [Clang] Add options -fprofile-filter-files and -fprofile-exclude-files to filter the files to instrument with gcov Summary: These options are taking regex separated by colons to filter files. - if both are empty then all files are instrumented - if -fprofile-filter-files is empty then all the filenames matching any of the regex from exclude are not instrumented - if -fprofile-exclude-files is empty then all the filenames matching any of the regex from filter are instrumented - if both aren't empty then all the filenames which match any of the regex in filter and which don't match all the regex in filter are instrumented - this patch is a follow-up of https://reviews.llvm.org/D52033 Reviewers: marco-c, vsk Reviewed By: marco-c, vsk Subscribers: cfe-commits, sylvestre.ledru Differential Revision: https://reviews.llvm.org/D52034 Added: cfe/trunk/test/CodeGen/Inputs/code-coverage-filter1.h cfe/trunk/test/CodeGen/Inputs/code-coverage-filter2.h cfe/trunk/test/CodeGen/code-coverage-filter.c Modified: cfe/trunk/docs/ReleaseNotes.rst cfe/trunk/docs/UsersManual.rst cfe/trunk/include/clang/Driver/Options.td cfe/trunk/include/clang/Frontend/CodeGenOptions.h cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp Modified: cfe/trunk/docs/ReleaseNotes.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=346642&r1=346641&r2=346642&view=diff == --- cfe/trunk/docs/ReleaseNotes.rst (original) +++ cfe/trunk/docs/ReleaseNotes.rst Mon Nov 12 01:12:27 2018 @@ -64,6 +64,12 @@ Non-comprehensive list of changes in thi New Compiler Flags -- +- ``-fprofile-filter-files=[regexes]`` and ``-fprofile-exclude-files=[regexes]``. + + Clang has now options to filter or exclude some files when + instrumenting for gcov-based profiling. + See the :doc:`UsersManual` for details. + - ... Deprecated Compiler Flags Modified: cfe/trunk/docs/UsersManual.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=346642&r1=346641&r2=346642&view=diff == --- cfe/trunk/docs/UsersManual.rst (original) +++ cfe/trunk/docs/UsersManual.rst Mon Nov 12 01:12:27 2018 @@ -1871,6 +1871,55 @@ using the ``llvm-cxxmap`` and ``llvm-pro following the Itanium C++ ABI mangling scheme. This covers all C++ targets supported by Clang other than Windows. +GCOV-based Profiling + + +GCOV is a test coverage program, it helps to know how often a line of code +is executed. When instrumenting the code with ``--coverage`` option, some +counters are added for each edge linking basic blocks. + +At compile time, gcno files are generated containing information about +blocks and edges between them. At runtime the counters are incremented and at +exit the counters are dumped in gcda files. + +The tool ``llvm-cov gcov`` will parse gcno, gcda and source files to generate +a report ``.c.gcov``. + +.. option:: -fprofile-filter-files=[regexes] + + Define a list of regexes separated by a semi-colon. + If a file name matches any of the regexes then the file is instrumented. + + .. code-block:: console + + $ clang --coverage -fprofile-filter-files=".*\.c$" foo.c + + For example, this will only instrument files finishing with ``.c``, skipping ``.h`` files. + +.. option:: -fprofile-exclude-files=[regexes] + + Define a list of regexes separated by a semi-colon. + If a file name doesn't match all the regexes then the file is instrumented. + + .. code-block:: console + + $ clang --coverage -fprofile-exclude-files="^/usr/include/.*$" foo.c + + For example, this will instrument all the files except the ones in ``/usr/include``. + +If both options are used then a file is instrumented if its name matches any +of the regexes from ``-fprofile-filter-list`` and doesn't match all the regexes +from ``-fprofile-exclude-list``. + +.. code-block:: console + + $ clang --coverage -fprofile-exclude-files="^/usr/include/.*$" \ + -fprofile-filter-files="^/usr/.*$" + +In that case ``/usr/foo/oof.h`` is instrumented since it matches the filter regex and +doesn't match the exclude regex, but ``/usr/include/foo.h`` doesn't since it matches +the exclude regex. + Controlling Debug Information - Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=346642&r1=346641&r2=346642&view=diff == --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Option
r346644 - [GCOV] fix test after patch rL346642
Author: calixte Date: Mon Nov 12 01:52:14 2018 New Revision: 346644 URL: http://llvm.org/viewvc/llvm-project?rev=346644&view=rev Log: [GCOV] fix test after patch rL346642 Summary: Test is failing under windows, so fix it. Should fix: http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/1390/steps/stage%201%20check/logs/stdio Reviewers: marco-c Reviewed By: marco-c Subscribers: cfe-commits, sylvestre.ledru, marco-c Differential Revision: https://reviews.llvm.org/D54416 Modified: cfe/trunk/test/CodeGen/code-coverage-filter.c Modified: cfe/trunk/test/CodeGen/code-coverage-filter.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/code-coverage-filter.c?rev=346644&r1=346643&r2=346644&view=diff == --- cfe/trunk/test/CodeGen/code-coverage-filter.c (original) +++ cfe/trunk/test/CodeGen/code-coverage-filter.c Mon Nov 12 01:52:14 2018 @@ -23,62 +23,62 @@ void test() { test2(); } -// ALL: define void @test1() #0 {{.*}} +// ALL: void @test1() #0 {{.*}} // ALL: {{.*}}__llvm_gcov_ctr{{.*}} // ALL: ret void -// ALL: define void @test2() #0 {{.*}} +// ALL: void @test2() #0 {{.*}} // ALL: {{.*}}__llvm_gcov_ctr{{.*}} // ALL: ret void -// ALL: define void @test() #0 {{.*}} +// ALL: void @test() #0 {{.*}} // ALL: {{.*}}__llvm_gcov_ctr{{.*}} // ALL: ret void -// NO-HEADER: define void @test1() #0 {{.*}} +// NO-HEADER: void @test1() #0 {{.*}} // NO-HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // NO-HEADER: ret void -// NO-HEADER: define void @test2() #0 {{.*}} +// NO-HEADER: void @test2() #0 {{.*}} // NO-HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // NO-HEADER: ret void -// NO-HEADER: define void @test() #0 {{.*}} +// NO-HEADER: void @test() #0 {{.*}} // NO-HEADER: {{.*}}__llvm_gcov_ctr{{.*}} // NO-HEADER: ret void -// NO-HEADER2: define void @test1() #0 {{.*}} +// NO-HEADER2: void @test1() #0 {{.*}} // NO-HEADER2: {{.*}}__llvm_gcov_ctr{{.*}} // NO-HEADER2: ret void -// NO-HEADER2: define void @test2() #0 {{.*}} +// NO-HEADER2: void @test2() #0 {{.*}} // NO-HEADER2-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // NO-HEADER2: ret void -// NO-HEADER2: define void @test() #0 {{.*}} +// NO-HEADER2: void @test() #0 {{.*}} // NO-HEADER2: {{.*}}__llvm_gcov_ctr{{.*}} // NO-HEADER2: ret void -// JUST-C: define void @test1() #0 {{.*}} +// JUST-C: void @test1() #0 {{.*}} // JUST-C-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // JUST-C: ret void -// JUST-C: define void @test2() #0 {{.*}} +// JUST-C: void @test2() #0 {{.*}} // JUST-C-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // JUST-C: ret void -// JUST-C: define void @test() #0 {{.*}} +// JUST-C: void @test() #0 {{.*}} // JUST-C: {{.*}}__llvm_gcov_ctr{{.*}} // JUST-C: ret void -// HEADER: define void @test1() #0 {{.*}} +// HEADER: void @test1() #0 {{.*}} // HEADER: {{.*}}__llvm_gcov_ctr{{.*}} // HEADER: ret void -// HEADER: define void @test2() #0 {{.*}} +// HEADER: void @test2() #0 {{.*}} // HEADER: {{.*}}__llvm_gcov_ctr{{.*}} // HEADER: ret void -// HEADER: define void @test() #0 {{.*}} +// HEADER: void @test() #0 {{.*}} // HEADER-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // HEADER: ret void -// NONE: define void @test1() #0 {{.*}} +// NONE: void @test1() #0 {{.*}} // NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // NONE: ret void -// NONE: define void @test2() #0 {{.*}} +// NONE: void @test2() #0 {{.*}} // NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // NONE: ret void -// NONE: define void @test() #0 {{.*}} +// NONE: void @test() #0 {{.*}} // NONE-NOT: {{.*}}__llvm_gcov_ctr{{.*}} // NONE: ret void ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r346659 - Revert rL346644, rL346642: the added test test/CodeGen/code-coverage-filter.c is failing under windows
Author: calixte Date: Mon Nov 12 06:57:17 2018 New Revision: 346659 URL: http://llvm.org/viewvc/llvm-project?rev=346659&view=rev Log: Revert rL346644, rL346642: the added test test/CodeGen/code-coverage-filter.c is failing under windows Removed: cfe/trunk/test/CodeGen/Inputs/code-coverage-filter1.h cfe/trunk/test/CodeGen/Inputs/code-coverage-filter2.h cfe/trunk/test/CodeGen/code-coverage-filter.c Modified: cfe/trunk/docs/ReleaseNotes.rst cfe/trunk/docs/UsersManual.rst cfe/trunk/include/clang/Driver/Options.td cfe/trunk/include/clang/Frontend/CodeGenOptions.h cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp Modified: cfe/trunk/docs/ReleaseNotes.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=346659&r1=346658&r2=346659&view=diff == --- cfe/trunk/docs/ReleaseNotes.rst (original) +++ cfe/trunk/docs/ReleaseNotes.rst Mon Nov 12 06:57:17 2018 @@ -64,12 +64,6 @@ Non-comprehensive list of changes in thi New Compiler Flags -- -- ``-fprofile-filter-files=[regexes]`` and ``-fprofile-exclude-files=[regexes]``. - - Clang has now options to filter or exclude some files when - instrumenting for gcov-based profiling. - See the :doc:`UsersManual` for details. - - ... Deprecated Compiler Flags Modified: cfe/trunk/docs/UsersManual.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=346659&r1=346658&r2=346659&view=diff == --- cfe/trunk/docs/UsersManual.rst (original) +++ cfe/trunk/docs/UsersManual.rst Mon Nov 12 06:57:17 2018 @@ -1871,55 +1871,6 @@ using the ``llvm-cxxmap`` and ``llvm-pro following the Itanium C++ ABI mangling scheme. This covers all C++ targets supported by Clang other than Windows. -GCOV-based Profiling - - -GCOV is a test coverage program, it helps to know how often a line of code -is executed. When instrumenting the code with ``--coverage`` option, some -counters are added for each edge linking basic blocks. - -At compile time, gcno files are generated containing information about -blocks and edges between them. At runtime the counters are incremented and at -exit the counters are dumped in gcda files. - -The tool ``llvm-cov gcov`` will parse gcno, gcda and source files to generate -a report ``.c.gcov``. - -.. option:: -fprofile-filter-files=[regexes] - - Define a list of regexes separated by a semi-colon. - If a file name matches any of the regexes then the file is instrumented. - - .. code-block:: console - - $ clang --coverage -fprofile-filter-files=".*\.c$" foo.c - - For example, this will only instrument files finishing with ``.c``, skipping ``.h`` files. - -.. option:: -fprofile-exclude-files=[regexes] - - Define a list of regexes separated by a semi-colon. - If a file name doesn't match all the regexes then the file is instrumented. - - .. code-block:: console - - $ clang --coverage -fprofile-exclude-files="^/usr/include/.*$" foo.c - - For example, this will instrument all the files except the ones in ``/usr/include``. - -If both options are used then a file is instrumented if its name matches any -of the regexes from ``-fprofile-filter-list`` and doesn't match all the regexes -from ``-fprofile-exclude-list``. - -.. code-block:: console - - $ clang --coverage -fprofile-exclude-files="^/usr/include/.*$" \ - -fprofile-filter-files="^/usr/.*$" - -In that case ``/usr/foo/oof.h`` is instrumented since it matches the filter regex and -doesn't match the exclude regex, but ``/usr/include/foo.h`` doesn't since it matches -the exclude regex. - Controlling Debug Information - Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=346659&r1=346658&r2=346659&view=diff == --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Options.td Mon Nov 12 06:57:17 2018 @@ -768,12 +768,6 @@ def fno_profile_instr_use : Flag<["-"], HelpText<"Disable using instrumentation data for profile-guided optimization">; def fno_profile_use : Flag<["-"], "fno-profile-use">, Alias; -def fprofile_filter_files_EQ : Joined<["-"], "fprofile-filter-files=">, -Group, Flags<[CC1Option, CoreOption]>, -HelpText<"Instrument only functions from files where names match any regex separated by a semi-colon">; -def fprofile_exclude_files_EQ : Joined<["-"], "fprofile-exclude-files=">, -Group, Flags<[CC1Option, CoreOption]>, -HelpText<"Instrument only functions from files where names don't match all the regexes separated by a semi-colon">; def faddrsig : Flag<["-"],
r347144 - [Clang] Add options -fprofile-filter-files and -fprofile-exclude-files to filter the files to instrument with gcov (after revert https://reviews.llvm.org/rL346659)
Author: calixte Date: Sat Nov 17 11:41:39 2018 New Revision: 347144 URL: http://llvm.org/viewvc/llvm-project?rev=347144&view=rev Log: [Clang] Add options -fprofile-filter-files and -fprofile-exclude-files to filter the files to instrument with gcov (after revert https://reviews.llvm.org/rL346659) Summary: the previous patch (https://reviews.llvm.org/rC346642) has been reverted because of test failure under windows. So this patch fix the test cfe/trunk/test/CodeGen/code-coverage-filter.c. Reviewers: marco-c Reviewed By: marco-c Subscribers: cfe-commits, sylvestre.ledru Differential Revision: https://reviews.llvm.org/D54600 Added: cfe/trunk/test/CodeGen/Inputs/code-coverage-filter1.h cfe/trunk/test/CodeGen/Inputs/code-coverage-filter2.h cfe/trunk/test/CodeGen/code-coverage-filter.c Modified: cfe/trunk/docs/ReleaseNotes.rst cfe/trunk/docs/UsersManual.rst cfe/trunk/include/clang/Driver/Options.td cfe/trunk/include/clang/Frontend/CodeGenOptions.h cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp Modified: cfe/trunk/docs/ReleaseNotes.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=347144&r1=347143&r2=347144&view=diff == --- cfe/trunk/docs/ReleaseNotes.rst (original) +++ cfe/trunk/docs/ReleaseNotes.rst Sat Nov 17 11:41:39 2018 @@ -64,6 +64,12 @@ Non-comprehensive list of changes in thi New Compiler Flags -- +- ``-fprofile-filter-files=[regexes]`` and ``-fprofile-exclude-files=[regexes]``. + + Clang has now options to filter or exclude some files when + instrumenting for gcov-based profiling. + See the :doc:`UsersManual` for details. + - ... Deprecated Compiler Flags Modified: cfe/trunk/docs/UsersManual.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=347144&r1=347143&r2=347144&view=diff == --- cfe/trunk/docs/UsersManual.rst (original) +++ cfe/trunk/docs/UsersManual.rst Sat Nov 17 11:41:39 2018 @@ -1871,6 +1871,55 @@ using the ``llvm-cxxmap`` and ``llvm-pro following the Itanium C++ ABI mangling scheme. This covers all C++ targets supported by Clang other than Windows. +GCOV-based Profiling + + +GCOV is a test coverage program, it helps to know how often a line of code +is executed. When instrumenting the code with ``--coverage`` option, some +counters are added for each edge linking basic blocks. + +At compile time, gcno files are generated containing information about +blocks and edges between them. At runtime the counters are incremented and at +exit the counters are dumped in gcda files. + +The tool ``llvm-cov gcov`` will parse gcno, gcda and source files to generate +a report ``.c.gcov``. + +.. option:: -fprofile-filter-files=[regexes] + + Define a list of regexes separated by a semi-colon. + If a file name matches any of the regexes then the file is instrumented. + + .. code-block:: console + + $ clang --coverage -fprofile-filter-files=".*\.c$" foo.c + + For example, this will only instrument files finishing with ``.c``, skipping ``.h`` files. + +.. option:: -fprofile-exclude-files=[regexes] + + Define a list of regexes separated by a semi-colon. + If a file name doesn't match all the regexes then the file is instrumented. + + .. code-block:: console + + $ clang --coverage -fprofile-exclude-files="^/usr/include/.*$" foo.c + + For example, this will instrument all the files except the ones in ``/usr/include``. + +If both options are used then a file is instrumented if its name matches any +of the regexes from ``-fprofile-filter-list`` and doesn't match all the regexes +from ``-fprofile-exclude-list``. + +.. code-block:: console + + $ clang --coverage -fprofile-exclude-files="^/usr/include/.*$" \ + -fprofile-filter-files="^/usr/.*$" + +In that case ``/usr/foo/oof.h`` is instrumented since it matches the filter regex and +doesn't match the exclude regex, but ``/usr/include/foo.h`` doesn't since it matches +the exclude regex. + Controlling Debug Information - Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=347144&r1=347143&r2=347144&view=diff == --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Options.td Sat Nov 17 11:41:39 2018 @@ -768,6 +768,12 @@ def fno_profile_instr_use : Flag<["-"], HelpText<"Disable using instrumentation data for profile-guided optimization">; def fno_profile_use : Flag<["-"], "fno-profile-use">, Alias; +def fprofile_filter_files_EQ : Joined<["-"], "fprofile-filter-files=">, +Group, Flags<[CC1Opti
r342717 - [CodeGen] Add to emitted DebugLoc information about coverage when it's required
Author: calixte Date: Fri Sep 21 02:17:06 2018 New Revision: 342717 URL: http://llvm.org/viewvc/llvm-project?rev=342717&view=rev Log: [CodeGen] Add to emitted DebugLoc information about coverage when it's required Summary: Some lines have a hit counter where they should not have one. Cleanup stuff is located to the last line of the body which is most of the time a '}'. And Exception stuff is added at the beginning of a function and at the end (represented by '{' and '}'). So in such cases, the DebugLoc used in GCOVProfiling.cpp must be marked as not covered. This patch is a followup of https://reviews.llvm.org/D49915. Tests in projects/compiler_rt are fixed by: https://reviews.llvm.org/D49917 Reviewers: marco-c, davidxl Reviewed By: marco-c Subscribers: dblaikie, cfe-commits, sylvestre.ledru Differential Revision: https://reviews.llvm.org/D49916 Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/lib/CodeGen/CGException.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h cfe/trunk/test/CodeGen/debug-info-scope-file.c cfe/trunk/test/CodeGenCXX/debug-info-inheriting-constructor.cpp cfe/trunk/test/CodeGenCXX/linetable-virtual-variadic.cpp cfe/trunk/test/CodeGenObjC/arc-linetable.m cfe/trunk/test/CodeGenObjC/debug-info-blocks.m Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=342717&r1=342716&r2=342717&view=diff == --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Sep 21 02:17:06 2018 @@ -76,20 +76,22 @@ CGDebugInfo::~CGDebugInfo() { } ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, - SourceLocation TemporaryLocation) + SourceLocation TemporaryLocation, + bool ImplicitCode) : CGF(&CGF) { - init(TemporaryLocation); + init(TemporaryLocation, false /* DefaultToEmpty */, ImplicitCode); } ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty, - SourceLocation TemporaryLocation) + SourceLocation TemporaryLocation, + bool ImplicitCode) : CGF(&CGF) { - init(TemporaryLocation, DefaultToEmpty); + init(TemporaryLocation, DefaultToEmpty, ImplicitCode); } void ApplyDebugLocation::init(SourceLocation TemporaryLocation, - bool DefaultToEmpty) { + bool DefaultToEmpty, bool ImplicitCode) { auto *DI = CGF->getDebugInfo(); if (!DI) { CGF = nullptr; @@ -102,7 +104,7 @@ void ApplyDebugLocation::init(SourceLoca return; if (TemporaryLocation.isValid()) { -DI->EmitLocation(CGF->Builder, TemporaryLocation); +DI->EmitLocation(CGF->Builder, TemporaryLocation, ImplicitCode); return; } @@ -3484,7 +3486,8 @@ void CGDebugInfo::EmitInlineFunctionEnd( setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt()); } -void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) { +void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, + bool ImplicitCode) { // Update our current location setLocation(Loc); @@ -3492,8 +3495,9 @@ void CGDebugInfo::EmitLocation(CGBuilder return; llvm::MDNode *Scope = LexicalBlockStack.back(); - Builder.SetCurrentDebugLocation(llvm::DebugLoc::get( - getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt)); + Builder.SetCurrentDebugLocation( + llvm::DebugLoc::get(getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, + CurInlinedAt, ImplicitCode)); } void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) { @@ -3540,7 +3544,7 @@ void CGDebugInfo::EmitLexicalBlockEnd(CG assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); // Provide an entry in the line table for the end of the block. - EmitLocation(Builder, Loc); + EmitLocation(Builder, Loc, true /* ImplicitCode */); if (DebugKind <= codegenoptions::DebugLineTablesOnly) return; @@ -3556,7 +3560,7 @@ void CGDebugInfo::EmitFunctionEnd(CGBuil // Pop all regions for this function. while (LexicalBlockStack.size() != RCount) { // Provide an entry in the line table for the end of the block. -EmitLocation(Builder, CurLoc); +EmitLocation(Builder, CurLoc, true /* ImplicitCode */); LexicalBlockStack.pop_back(); } FnBeginRegionCount.pop_back(); Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=342717&r1=342716&r2=342717&view=diff ==
r342912 - [CodeGen] Revert commit https://reviews.llvm.org/rL342717
Author: calixte Date: Mon Sep 24 11:24:18 2018 New Revision: 342912 URL: http://llvm.org/viewvc/llvm-project?rev=342912&view=rev Log: [CodeGen] Revert commit https://reviews.llvm.org/rL342717 Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/lib/CodeGen/CGException.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h cfe/trunk/test/CodeGen/debug-info-scope-file.c cfe/trunk/test/CodeGenCXX/debug-info-inheriting-constructor.cpp cfe/trunk/test/CodeGenCXX/linetable-virtual-variadic.cpp cfe/trunk/test/CodeGenObjC/arc-linetable.m cfe/trunk/test/CodeGenObjC/debug-info-blocks.m Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=342912&r1=342911&r2=342912&view=diff == --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Sep 24 11:24:18 2018 @@ -76,22 +76,20 @@ CGDebugInfo::~CGDebugInfo() { } ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, - SourceLocation TemporaryLocation, - bool ImplicitCode) + SourceLocation TemporaryLocation) : CGF(&CGF) { - init(TemporaryLocation, false /* DefaultToEmpty */, ImplicitCode); + init(TemporaryLocation); } ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty, - SourceLocation TemporaryLocation, - bool ImplicitCode) + SourceLocation TemporaryLocation) : CGF(&CGF) { - init(TemporaryLocation, DefaultToEmpty, ImplicitCode); + init(TemporaryLocation, DefaultToEmpty); } void ApplyDebugLocation::init(SourceLocation TemporaryLocation, - bool DefaultToEmpty, bool ImplicitCode) { + bool DefaultToEmpty) { auto *DI = CGF->getDebugInfo(); if (!DI) { CGF = nullptr; @@ -104,7 +102,7 @@ void ApplyDebugLocation::init(SourceLoca return; if (TemporaryLocation.isValid()) { -DI->EmitLocation(CGF->Builder, TemporaryLocation, ImplicitCode); +DI->EmitLocation(CGF->Builder, TemporaryLocation); return; } @@ -3486,8 +3484,7 @@ void CGDebugInfo::EmitInlineFunctionEnd( setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt()); } -void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, - bool ImplicitCode) { +void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) { // Update our current location setLocation(Loc); @@ -3495,9 +3492,8 @@ void CGDebugInfo::EmitLocation(CGBuilder return; llvm::MDNode *Scope = LexicalBlockStack.back(); - Builder.SetCurrentDebugLocation( - llvm::DebugLoc::get(getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, - CurInlinedAt, ImplicitCode)); + Builder.SetCurrentDebugLocation(llvm::DebugLoc::get( + getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt)); } void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) { @@ -3544,7 +3540,7 @@ void CGDebugInfo::EmitLexicalBlockEnd(CG assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); // Provide an entry in the line table for the end of the block. - EmitLocation(Builder, Loc, true /* ImplicitCode */); + EmitLocation(Builder, Loc); if (DebugKind <= codegenoptions::DebugLineTablesOnly) return; @@ -3560,7 +3556,7 @@ void CGDebugInfo::EmitFunctionEnd(CGBuil // Pop all regions for this function. while (LexicalBlockStack.size() != RCount) { // Provide an entry in the line table for the end of the block. -EmitLocation(Builder, CurLoc, true /* ImplicitCode */); +EmitLocation(Builder, CurLoc); LexicalBlockStack.pop_back(); } FnBeginRegionCount.pop_back(); Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=342912&r1=342911&r2=342912&view=diff == --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Sep 24 11:24:18 2018 @@ -377,9 +377,7 @@ public: /// Emit metadata to indicate a change in line/column information in /// the source file. If the location is invalid, the previous /// location will be reused. - /// \param ImplicitCode True if the Loc must have coverage information - void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, -bool ImplicitCode = false); + void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc); /// Emit a call to llvm.dbg.function.sta
[clang] bec223a - [profile] Don't crash when forking in several threads
Author: Calixte Denizet Date: 2020-05-07T14:13:11+02:00 New Revision: bec223a9bc4eb9747993ee9a4c1aa135c32123e6 URL: https://github.com/llvm/llvm-project/commit/bec223a9bc4eb9747993ee9a4c1aa135c32123e6 DIFF: https://github.com/llvm/llvm-project/commit/bec223a9bc4eb9747993ee9a4c1aa135c32123e6.diff LOG: [profile] Don't crash when forking in several threads Summary: When forking in several threads, the counters were written out in using the same global static variables (see GCDAProfiling.c): that leads to crashes. So when there is a fork, the counters are resetted in the child process and they will be dumped at exit using the interprocess file locking. When there is an exec, the counters are written out and in case of failures they're resetted. Reviewers: jfb, vsk, marco-c, serge-sans-paille Reviewed By: marco-c, serge-sans-paille Subscribers: llvm-commits, serge-sans-paille, dmajor, cfe-commits, hiraditya, dexonsmith, #sanitizers, marco-c, sylvestre.ledru Tags: #sanitizers, #clang, #llvm Differential Revision: https://reviews.llvm.org/D78477 Added: compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp compiler-rt/test/profile/instrprof-gcov-multithread_fork.test Modified: clang/lib/Driver/ToolChains/Darwin.cpp compiler-rt/lib/profile/GCDAProfiling.c llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index a113d05cc579..df340145f9fa 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1173,6 +1173,7 @@ void Darwin::addProfileRTLibs(const ArgList &Args, addExportedSymbol(CmdArgs, "___gcov_flush"); addExportedSymbol(CmdArgs, "_flush_fn_list"); addExportedSymbol(CmdArgs, "_writeout_fn_list"); + addExportedSymbol(CmdArgs, "_reset_fn_list"); } else { addExportedSymbol(CmdArgs, "___llvm_profile_filename"); addExportedSymbol(CmdArgs, "___llvm_profile_raw_version"); diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c index 5ff1e9cd8070..d9e1fb3cdc4e 100644 --- a/compiler-rt/lib/profile/GCDAProfiling.c +++ b/compiler-rt/lib/profile/GCDAProfiling.c @@ -32,8 +32,10 @@ #include #include "WindowsMMap.h" #else -#include #include +#include +#include +#include #endif #if defined(__FreeBSD__) && defined(__i386__) @@ -119,6 +121,11 @@ struct fn_list writeout_fn_list; */ struct fn_list flush_fn_list; +/* + * A list of reset functions, shared between all dynamic objects. + */ +struct fn_list reset_fn_list; + static void fn_list_insert(struct fn_list* list, fn_ptr fn) { struct fn_node* new_node = malloc(sizeof(struct fn_node)); new_node->fn = fn; @@ -643,7 +650,46 @@ void llvm_delete_flush_function_list(void) { } COMPILER_RT_VISIBILITY -void llvm_gcov_init(fn_ptr wfn, fn_ptr ffn) { +void llvm_register_reset_function(fn_ptr fn) { + fn_list_insert(&reset_fn_list, fn); +} + +COMPILER_RT_VISIBILITY +void llvm_delete_reset_function_list(void) { fn_list_remove(&reset_fn_list); } + +COMPILER_RT_VISIBILITY +void llvm_reset_counters(void) { + struct fn_node *curr = reset_fn_list.head; + + while (curr) { +if (curr->id == CURRENT_ID) { + curr->fn(); +} +curr = curr->next; + } +} + +#if !defined(_WIN32) +COMPILER_RT_VISIBILITY +pid_t __gcov_fork() { + pid_t parent_pid = getpid(); + pid_t pid = fork(); + + if (pid == 0) { +pid_t child_pid = getpid(); +if (child_pid != parent_pid) { + // The pid changed so we've a fork (one could have its own fork function) + // Just reset the counters for this child process + // threads. + llvm_reset_counters(); +} + } + return pid; +} +#endif + +COMPILER_RT_VISIBILITY +void llvm_gcov_init(fn_ptr wfn, fn_ptr ffn, fn_ptr rfn) { static int atexit_ran = 0; if (wfn) @@ -652,10 +698,14 @@ void llvm_gcov_init(fn_ptr wfn, fn_ptr ffn) { if (ffn) llvm_register_flush_function(ffn); + if (rfn) +llvm_register_reset_function(rfn); + if (atexit_ran == 0) { atexit_ran = 1; /* Make sure we write out the data and delete the data structures. */ +atexit(llvm_delete_reset_function_list); atexit(llvm_delete_flush_function_list); atexit(llvm_delete_writeout_function_list); atexit(llvm_writeout_files); diff --git a/compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp b/compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp new file mode 100644 index ..94db50fc8265 --- /dev/null +++ b/compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +template +void launcher(T func) { + std::vector pool; + + for (int i = 0; i < 10; i++) { +pool.emplace_back(std::thread(func)); + } + + for (auto