basic_ostream<unsigned char>: Crash at initialization on Arm64 architecture with Clang compiler and STL version 16.9.4
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Describe the bug
Instantiating a derived class from basic_ostream using unsigned char as the character type results in a access violation when compiling with Clang. Crash occurs in the init method of std::basic_ios when accessing the ctype of the std::_Locinfo class (init calls widen then use_facet, etc...)
Command-line test case
#include <iostream>
#include <sstream>
template <class CharT, class Traits = std::char_traits<CharT>>
struct Stream : public std::basic_ostream<CharT, Traits> {
Stream() : std::basic_ostream<CharT, Traits>(&buffer) {
}
std::basic_stringbuf<CharT, Traits> buffer;
};
int main() {
{
// OK
Stream<char> stream;
// Prevent optimization
std::cout << &stream << std::endl;
}
{
// KO
Stream<unsigned char> stream;
// Prevent optimization
std::cout << &stream << std::endl;
}
return 0;
}
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\x64\bin\clang-cl.exe /c /nologo /W1 /WX- /diagnostics:column /O2 /Ob2
/D WIN32 /D _WINDOWS /D NDEBUG /D "CMAKE_INTDIR=\"Release\"" /D _MBCS /EHsc /MD /GS /fp:precise /GR /Fo"TestArmStd.dir\Release\\" /Gd /TP --target
=arm64-pc-windows-msvc C:\Users\ARTHUR\Documents\code\TestArmStd\main.cpp
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\x64\bin\lld-link.exe /OUT:"C:\Users\ARTHUR\Documents\code\TestArmStd\b
uild-clang-arm64-windows\Release\TestArmStd.exe" /INCREMENTAL:NO kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib
uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"C:/Users/ARTHUR/Documents/co
de/TestArmStd/build-clang-arm64-windows/Release/TestArmStd.pdb" /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/Users/ARTHUR/Documents/code/
TestArmStd/build-clang-arm64-windows/Release/TestArmStd.lib" /machine:ARM64 TestArmStd.dir\Release\main.obj
TestArmStd.vcxproj -> C:\Users\ARTHUR\Documents\code\TestArmStd\build-clang-arm64-windows\Release\TestArmStd.exe
Expected behavior
This code should not crash
STL version
Microsoft Visual Studio Community 2019
Version 16.9.4
Additional context
Hope this is the good place to report this, that this code is valid and that I'm using the correct compile options for ClangCl.
Please note that this crash does not occur with MSVC compiler.
I'm cross-compiling this code on a x64 Host and deploying it on a fresh Windows installation (Windows 10 Professional, Build 21364.1 emulated on a mac M1 hardware) using the Visual Studio remote debugger.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal command-line reproducer and the std::basic_ios::init path described in the report, comparing char with unsigned char under clang-cl for the ARM64 target. Trace the ctype access through _Locinfo, widen, and use_facet, then verify that the unsigned-char stream initializes without an access violation while the char case remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100