Bug 470428

Summary: Kdevelop crashes during background parsing with clang
Product: [Applications] kdevelop Reporter: Andrei Slavoiu <ansla80>
Component: generalAssignee: kdevelop-bugs-null
Status: RESOLVED DUPLICATE    
Severity: crash CC: igorkuo
Priority: NOR Keywords: drkonqi
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: New crash information added by DrKonqi
compiler.info

Description Andrei Slavoiu 2023-05-29 19:47:19 UTC
Application: kdevelop (5.11.230401 (23.04.1))

Qt Version: 5.15.9
Frameworks Version: 5.106.0
Operating System: Linux 6.3.3-gentoo x86_64
Windowing System: X11
Distribution: "Gentoo Linux"
DrKonqi: 5.27.5 [KCrashBackend]

-- Information about the crash:
Started crashing after I changed the active compiler for the project from GCC to Clang.

The crash can be reproduced every time.

-- Backtrace (Reduced):
#6  __memset_avx2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S:328
#7  0x00007f28322a7daf in std::__fill_a1<unsigned short*, int>(unsigned short*, unsigned short*, int const&) (__value=<optimized out>, __last=<optimized out>, __first=<optimized out>) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_algobase.h:930
#8  std::__fill_a<unsigned short*, int>(unsigned short*, unsigned short*, int const&) (__value=<optimized out>, __last=<optimized out>, __first=<optimized out>) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_algobase.h:977
#9  std::__fill_n_a<unsigned short*, int, int>(unsigned short*, int, int const&, std::random_access_iterator_tag) (__value=<optimized out>, __n=3277, __first=<optimized out>) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_algobase.h:1128
#10 std::fill_n<unsigned short*, KDevelop::Bucket<KDevelop::CodeModelRepositoryItem, KDevelop::CodeModelRequestItem, true, 0u>::{unnamed type#3}, int>(KDevelop::Bucket<KDevelop::CodeModelRepositoryItem, KDevelop::CodeModelRequestItem, true, 0u>::{unnamed type#3}, KDevelop::Bucket<KDevelop::CodeModelRepositoryItem, KDevelop::CodeModelRequestItem, true, 0u>::{unnamed type#3}, int const&) (__value=<optimized out>, __n=KDevelop::Bucket<KDevelop::CodeModelRepositoryItem, KDevelop::CodeModelRequestItem, true, 0>::NextBucketHashSize, __first=<optimized out>) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_algobase.h:1157


Reported using DrKonqi
Comment 1 Andrei Slavoiu 2023-05-29 19:47:20 UTC
Created attachment 159329 [details]
New crash information added by DrKonqi

DrKonqi auto-attaching complete backtrace.
Comment 2 Igor Kushnir 2023-05-30 05:51:19 UTC
Cannot reproduce on Manjaro GNU/Linux. My GCC version is: gcc (GCC) 12.2.1 20230201

In my stl_algobase.h I see this code:
```
  template<typename _ForwardIterator, typename _Tp>
    _GLIBCXX20_CONSTEXPR
    inline typename
    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
    __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
	      const _Tp& __value)
    {
      const _Tp __tmp = __value;
      for (; __first != __last; ++__first)
	*__first = __tmp;
    }

  // Specialization: for char types we can use memset.
  template<typename _Tp>
    _GLIBCXX20_CONSTEXPR
    inline typename
    __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, void>::__type
    __fill_a1(_Tp* __first, _Tp* __last, const _Tp& __c)
    {
      const _Tp __tmp = __c;
#if __cpp_lib_is_constant_evaluated
      if (std::is_constant_evaluated())
	{
	  for (; __first != __last; ++__first)
	    *__first = __tmp;
	  return;
	}
#endif
      if (const size_t __len = __last - __first)
	__builtin_memset(__first, static_cast<unsigned char>(__tmp), __len);
    }
```

The line at kdevplatform/serialization/itemrepository.h:734:
            std::fill_n(m_nextBucketHash, NextBucketHashSize, 0);
Declaration:
    unsigned short* m_nextBucketHash
Since `unsigned short` is not a byte type (the size is 2 bytes), the loop overload of __fill_a1 should be called. But your backtrace ends with `__memset_avx2_unaligned_erms`, which suggests that the memset overload is called on your system or the compiler optimizes the loop into a memset instruction. What is your GCC version and the function at stl_algobase.h:930 on your system? Which optimization flags have you built KDevelop with? Is memset-ing a memory-mapped region supported by GCC? If so, maybe there is some memset+memmap bug in your libstdc++ version?
Comment 3 Andrei Slavoiu 2023-05-30 12:01:09 UTC
Hi, first of all, after clearing the cache it no longer crashes. But if it helps to prevent this in the future:

The entire system is built with CFLAGS="-march=native -ggdb3 -O2 -pipe -fdiagnostics-color". See attached compiler.info for what -march=native translates to on my system.

This is the content of stl_algobase.h around that line.

      template<typename _ForwardIterator, typename _Tp>
        _GLIBCXX20_CONSTEXPR
        inline typename
        __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
        __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
                  const _Tp& __value)
        {
          const _Tp __tmp = __value;
930:      for (; __first != __last; ++__first)
            *__first = __tmp;
        }
Comment 4 Andrei Slavoiu 2023-05-30 12:02:05 UTC
Created attachment 159346 [details]
compiler.info
Comment 5 Igor Kushnir 2023-05-30 13:34:22 UTC
(In reply to Andrei Slavoiu from comment #3)
> Hi, first of all, after clearing the cache it no longer crashes.
Did you recently update from a custom-built unreleased KDevelop master version? If yes, perhaps the cache wasn't cleared for some reason. On the other hand, the merge request that introduced the crashing code https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/445 increments KDEV_ITEMREPOSITORY_INCREMENT, which forces clearing the cache. But let us close this bug for now in case this is a cache issue. Reopen if it occurs again.
Comment 6 Igor Kushnir 2025-11-05 18:51:41 UTC

*** This bug has been marked as a duplicate of bug 488043 ***