Bug 110395 - GCOV stuck in an infinite loop with large std::array
Summary: GCOV stuck in an infinite loop with large std::array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: compile-time-hog
Depends on:
Blocks:
 
Reported: 2023-06-24 16:09 UTC by Carlos Galvez
Modified: 2023-06-25 00:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 12.1.0, 12.3.0, 13.1.0
Known to fail: 11.4.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Galvez 2023-06-24 16:09:37 UTC
Hi!

We are bumping from GCC 7.5.0 to GCC 9.4.0 (Ubuntu 20.04) and observe that GCOV is stuck when analyzing the following minimal repro code:

#include <vector>
#include <array>

template <typename T, std::size_t n>
class StaticVector
{
 public:
    StaticVector() = default;
    void foo(){}

 private:
    std::array<T, n> data{};
};

class Foo
{
    StaticVector<std::vector<std::size_t>, 40000> data_{};
};

int main()
{
    Foo f;
    return 0;
}


$ g++ --coverage main.cpp
$ ./a.out
$ gcov main.cpp

The problem goes away if I remove the value initialization for std::array in the StaticVector class (i.e. I leave the member "data" uninitialized).

The same problem happens also on GCC 11 

What might be the reason for this? 

Thanks!
Comment 1 Andrew Pinski 2023-06-25 00:03:31 UTC
On the trunk it takes no time at all:
[apinski@xeond2 upstream-gcc-git]$ ~/upstream-gcc/bin/g++  t.cc --coverage
[apinski@xeond2 upstream-gcc-git]$ LD_LIBRARY_PATH=~/upstream-gcc/lib64 ./a.out
[apinski@xeond2 upstream-gcc-git]$ LD_LIBRARY_PATH=~/upstream-gcc/lib64 ~/upstream-gcc/bin/gcov t.cc
t.gcno:cannot open notes file
t.gcda:cannot open data file, assuming not executed
No executable lines
[apinski@xeond2 upstream-gcc-git]$ LD_LIBRARY_PATH=~/upstream-gcc/lib64 ~/upstream-gcc/bin/gcov a-t.cc
File '/home/apinski/upstream-gcc/include/c++/14.0.0/bits/stl_construct.h'
Lines executed:100.00% of 4
Creating 'stl_construct.h.gcov'

File '/home/apinski/upstream-gcc/include/c++/14.0.0/bits/new_allocator.h'
Lines executed:50.00% of 4
Creating 'new_allocator.h.gcov'

File '/home/apinski/upstream-gcc/include/c++/14.0.0/bits/stl_vector.h'
Lines executed:95.45% of 22
Creating 'stl_vector.h.gcov'

File '/home/apinski/upstream-gcc/include/c++/14.0.0/bits/alloc_traits.h'
Lines executed:66.67% of 3
Creating 'alloc_traits.h.gcov'

File '/home/apinski/upstream-gcc/include/c++/14.0.0/bits/allocator.h'
Lines executed:100.00% of 1
Creating 'allocator.h.gcov'

File 't.cc'
Lines executed:100.00% of 5
Creating 't.cc.gcov'

File '/home/apinski/upstream-gcc/include/c++/14.0.0/array'
No executable lines
Removing 'array.gcov'

Lines executed:89.74% of 39

real    0m0.043s
user    0m0.004s
sys     0m0.002s
Comment 2 Andrew Pinski 2023-06-25 00:11:38 UTC
Fixed in GCC 12.1.0 by the same patch which fixed PR 92385 .
Comment 3 Andrew Pinski 2023-06-25 00:12:50 UTC
Note it is not an infinite loop, just many basic blocks (over 40000 of them) causing the performance to be very very slow.