Issue 127572
Summary [clang-cl] access violation at runtime with clang-cl 20.1.0-rc2 using /std:c++latest
Labels new issue
Assignees
Reporter Mishura4
    ```c++
// test.hpp

#include <vector>
#include <string>

extern const std::vector<std::string>& my_vec;

void init();
```

```c++
// test.cpp
#include "test.hpp"

namespace
{

std::vector<std::string> impl;

}

const std::vector<std::string>& my_vec = impl;

void init() {
 std::vector<std::string> vec_ref;

    vec.push_back("hello");
 vec.push_back("world!");

    impl = std::move(vec);
}
```

```c++
// main.cpp
#include "test.hpp"

#include <iostream>

int main()
{
    init();
    for (auto& str : vec_ref)
    {
        std::cout << str << std::endl;
 }
}
```

Compile with `clang-cl test.cpp main.cpp /std:c++latest`. For some reason either `vec_ref` or `impl` seems to become corrupted and the for loop seems to read garbage data. In the project I initially encountered this, the program crashed with an access violation.

The same code works without an issue with `/std:c++20`, the same code works without an issue on 19.1.0 even with `/std:c++latest`.

clang-cl was compiled with:
```bat
set CXX=clang-cl
set CC=clang-cl
set VECTORIZE="-march=native -mtune=native"

cmake llvm/ -B build ^
 -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb" ^
 -DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx" ^
 -DLLVM_TARGETS_TO_BUILD=Native ^
  -DLLVM_PARALLEL_COMPILE_JOBS=30 ^
 -DLLVM_PARALLEL_LINK_JOBS=3 ^
  -DLLVM_ENABLE_LLD=on ^
 -DCLANG_DEFAULT_LINKER=lld ^
  -DCMAKE_BUILD_TYPE=Release ^
 -DCLANG_ENABLE_BOOTSTRAP=On ^
  -DLLVM_HOST_TRIPLE=x86_64-pc-windows-msvc ^
  -DLLVM_ENABLE_LTO=Thin ^
  -DLLVM_ENABLE_EH=ON ^
 -DLLVM_ENABLE_RTTI=ON ^
  -DLLVM_ENABLE_LIBXML2=ON ^
 -DCMAKE_CXX_STANDARD=20 ^
  -DBOOTSTRAP_CMAKE_CXX_FLAGS=%VECTORIZE% ^
 -DBOOTSTRAP_CMAKE_C_FLAGS=%VECTORIZE% ^
 -DBOOTSTRAP_CMAKE_EXE_LINKER_FLAGS=%VECTORIZE% ^
 -DRUNTIMES_x86_64-pc-windows-msvc_LLVM_ENABLE_EH=ON ^
 -DRUNTIMES_x86_64-pc-windows-msvc_LLVM_ENABLE_RTTI=ON ^
 -DRUNTIMES_x86_64-pc-windows-msvc_LLVM_ENABLE_LIBXML2=ON ^
 -DCMAKE_MT=mt.exe ^
  -G Ninja

ninja -C build
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to