Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

ThreadSanitizer: data race in std::__1::ios_base::width() #51476

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR52509
Status NEW
Importance P enhancement
Reported by maic (maic23@live.de)
Reported on 2021-11-15 06:14:42 -0800
Last modified on 2021-11-15 06:16:14 -0800
Version unspecified
Hardware All Linux
CC llvm-bugs@lists.llvm.org, maic23@live.de, mclow.lists@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
I can reproduce with all versions of clang.

Steps to reproduce:

$ cat 1.cpp && clang++ -stdlib=libc++ -fsanitize=thread -std=c++20 1.cpp &&
./a.out

#include <iostream>
#include <thread>

void Print() { std::cout << ""; }
int main() {
  std::thread a{Print};
  std::thread b{Print};
  a.join();
  b.join();
}

==================
WARNING: ThreadSanitizer: data race (pid=4144)
  Read of size 4 at 0x000000500d28 by thread T2:
    #0 std::__1::basic_ios<char, std::__1::char_traits<char> >::fill() const <null> (a.out+0x4c301c)
    #1 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) <null> (a.out+0x4c2956)
    #2 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) <null> (a.out+0x4c256d)
    #3 Print() <null> (a.out+0x4c240f)
    #4 decltype(static_cast<void (*>(fp)()) std::__1::__invoke<void (*)()>(void (*&&)()) <null> (a.out+0x4c46d2)
    #5 void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()>&, std::__1::__tuple_indices<>) <null> (a.out+0x4c4615)
    #6 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()> >(void*) <null> (a.out+0x4c3cd2)

  Previous write of size 4 at 0x000000500d28 by thread T1:
    #0 std::__1::basic_ios<char, std::__1::char_traits<char> >::fill() const <null> (a.out+0x4c306a)
    #1 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) <null> (a.out+0x4c2956)
    #2 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) <null> (a.out+0x4c256d)
    #3 Print() <null> (a.out+0x4c240f)
    #4 decltype(static_cast<void (*>(fp)()) std::__1::__invoke<void (*)()>(void (*&&)()) <null> (a.out+0x4c46d2)
    #5 void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()>&, std::__1::__tuple_indices<>) <null> (a.out+0x4c4615)
    #6 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()> >(void*) <null> (a.out+0x4c3cd2)

  Location is global 'std::__1::cout' of size 160 at 0x000000500c90 (a.out+0x000000500d28)

  Thread T2 (tid=4147, running) created by main thread at:
    #0 pthread_create <null> (a.out+0x44c6cd)
    #1 std::__1::__libcpp_thread_create(unsigned long*, void* (*)(void*), void*) <null> (a.out+0x4c3c49)
    #2 std::__1::thread::thread<void (&)(), void>(void (&)()) <null> (a.out+0x4c26b0)
    #3 main <null> (a.out+0x4c2471)

  Thread T1 (tid=4146, finished) created by main thread at:
    #0 pthread_create <null> (a.out+0x44c6cd)
    #1 std::__1::__libcpp_thread_create(unsigned long*, void* (*)(void*), void*) <null> (a.out+0x4c3c49)
    #2 std::__1::thread::thread<void (&)(), void>(void (&)()) <null> (a.out+0x4c26b0)
    #3 main <null> (a.out+0x4c245e)

SUMMARY: ThreadSanitizer: data race (/a.out+0x4c301c) in
std::__1::basic_ios<char, std::__1::char_traits<char> >::fill() const
==================
==================
WARNING: ThreadSanitizer: data race (pid=4144)
  Read of size 8 at 0x000000500cb0 by thread T2:
    #0 std::__1::ios_base::width() const <null> (a.out+0x4c31bd)
    #1 std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) <null> (a.out+0x4c2c83)
    #2 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) <null> (a.out+0x4c298d)
    #3 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) <null> (a.out+0x4c256d)
    #4 Print() <null> (a.out+0x4c240f)
    #5 decltype(static_cast<void (*>(fp)()) std::__1::__invoke<void (*)()>(void (*&&)()) <null> (a.out+0x4c46d2)
    #6 void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()>&, std::__1::__tuple_indices<>) <null> (a.out+0x4c4615)
    #7 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()> >(void*) <null> (a.out+0x4c3cd2)

  Previous write of size 8 at 0x000000500cb0 by thread T1:
    #0 std::__1::ios_base::width(long) <null> (a.out+0x4c33b6)
    #1 std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) <null> (a.out+0x4c2e65)
    #2 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) <null> (a.out+0x4c298d)
    #3 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) <null> (a.out+0x4c256d)
    #4 Print() <null> (a.out+0x4c240f)
    #5 decltype(static_cast<void (*>(fp)()) std::__1::__invoke<void (*)()>(void (*&&)()) <null> (a.out+0x4c46d2)
    #6 void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()>&, std::__1::__tuple_indices<>) <null> (a.out+0x4c4615)
    #7 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)()> >(void*) <null> (a.out+0x4c3cd2)

  Location is global 'std::__1::cout' of size 160 at 0x000000500c90 (a.out+0x000000500cb0)

  Thread T2 (tid=4147, running) created by main thread at:
    #0 pthread_create <null> (a.out+0x44c6cd)
    #1 std::__1::__libcpp_thread_create(unsigned long*, void* (*)(void*), void*) <null> (a.out+0x4c3c49)
    #2 std::__1::thread::thread<void (&)(), void>(void (&)()) <null> (a.out+0x4c26b0)
    #3 main <null> (a.out+0x4c2471)

  Thread T1 (tid=4146, finished) created by main thread at:
    #0 pthread_create <null> (a.out+0x44c6cd)
    #1 std::__1::__libcpp_thread_create(unsigned long*, void* (*)(void*), void*) <null> (a.out+0x4c3c49)
    #2 std::__1::thread::thread<void (&)(), void>(void (&)()) <null> (a.out+0x4c26b0)
    #3 main <null> (a.out+0x4c245e)

SUMMARY: ThreadSanitizer: data race (/a.out+0x4c31bd) in
std::__1::ios_base::width() const
==================
ThreadSanitizer: reported 2 warnings