Skip to content

Clang 9.0.0 plus GNU 11.1.0 causes crash when using std::thread #3454

@densamoilov

Description

@densamoilov

Description
After Ubuntu 18.04 image update some tests started failing when using Clang 9.0.0. The reason seems to be incompatibility (probably due to a bug) between Clang 9.0.0 and GNU 11.1.0 headers that are used by Clang. If there are such issues in GNU 11.1.0 then it should probably be opt-in in the image and not the default one.

Area for Triage:
C/C++

Bug?:
Perhaps

Virtual environments affected

  • Ubuntu 16.04
  • Ubuntu 18.04
  • Ubuntu 20.04
  • macOS 10.15
  • macOS 11
  • Windows Server 2016 R2
  • Windows Server 2019

Image version
20210517.1

Expected behavior
The code below compiles with Clang 9.0.0 and works.

#include <thread>
int main() {
    std::thread t([]{});
    t.join();
    return 0;
}

Actual behavior
It crashed at runtime. I narrowed it down to GNU 11.1.0 compiler. When compiling the code snippet above with Clang 9.0.0 it uses GNU header files and in particular thread header file from GNU 11.1.0 which causes the aforementioned crash. When overriding path to the headers so that it points to GNU 10.3.0 everything works as expected.

Repro steps
Having Clang 9.0.0 and GNU 11.1.0 installed just run the following command to compile the code snippet:

clang++ --std=c++11 ./code.cpp -lpthread
./a.out # should crash

I could locally workaround it by using headers from GNU 10.3.0 but this is not a solution. Also, this cannot be overrided by setting the default GNU compiler in the system because Clang searches for header files in the directory of the latest GNU compiler.

clang++ --std=c++11 -I/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 ./code.cpp -lpthread

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions