llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.82k stars 11.91k forks source link

Thread Sanitizer causes false positive on a static array #41114

Open llvmbot opened 5 years ago

llvmbot commented 5 years ago
Bugzilla Link 41769
Version unspecified
OS All
Attachments test case
Reporter LLVM Bugzilla Contributor

Extended Description

The following code causes a false data race detection.

#include <array>
#include <thread>
#include <vector>

class String{
public:
    std::array<unsigned char,16>value;
    String(const char(&s)[2])noexcept:value(){std::memcpy(value.data(),s,1);}
};

void createStaticAndFind(){
    static const std::array<String,3>a={"1","2","3"};
    if(a[2].value==String("3").value){}}

int main(){
    std::vector<std::thread>threads;
    for(size_t i=0;i<100;++i){
        threads.emplace_back(createStaticAndFind);}
    return 0;}

Compiled and linked with -L/usr/local/lib and -fsanitize=thread.

llvmbot commented 5 years ago

The attached test case is a shorter example causing false positives.