移动std::ostringstream时出现Clang C++ UBSAN异常问题
确认是否为LLVM Bug并寻求建议
不确定这是不是发布问题的正确论坛,感觉这应该是个要向LLVM团队报告的Bug。如果你们也这么觉得,麻烦告诉我,我会去提交报告。
以下是触发UBSAN错误的相关信息,供判断参考:
环境信息
- 系统:MacOS Ventura
- 编译器:Clang 16.0.0(手动编译LLVM,使用默认选项)
复现步骤
clang++ -fsanitize=undefined main.cpp ./a.out
测试代码(main.cpp)
#include <sstream> struct MyStruct { static MyStruct create() noexcept { return MyStruct{}; } private: std::ostringstream oss_; }; int main() { MyStruct::create(); }
UBSAN错误输出
~/usr/bin/../include/c++/v1/sstream:730:43: 运行时错误:在地址0x7ff7b265a298处进行成员访问,但该地址未指向'std::ostringstream'类型的对象 0x7ff7b265a298: 注意:对象类型为'std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char>>' f7 7f 00 00 40 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ 'std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char>>'的虚函数表指针 总结:UndefinedBehaviorSanitizer: 未定义行为 ~/usr/bin/../include/c++/v1/sstream:730:43 ~/usr/bin/../include/c++/v1/ostream:198:7: 运行时错误:将地址0x7ff7b265a298转换为虚基类,但该地址未指向'std::ostream'类型的对象 0x7ff7b265a298: 注意:对象类型为'std::__1::basic_ostream<char, std::__1::char_traits<char>>' f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ 'std::__1::basic_ostream<char, std::__1::char_traits<char>>'的虚函数表指针 总结:UndefinedBehaviorSanitizer: 未定义行为 ~/usr/bin/../include/c++/v1/ostream:198:7 ~/usr/bin/../include/c++/v1/ostream:198:13: 运行时错误:在地址0x7ff7b265a308处调用成员,但该地址未指向'std::ios'类型的对象 0x7ff7b265a298: 注意:对象是'std::__1::basic_ostream<char, std::__1::char_traits<char>>'类型对象中偏移量为112的基类子对象 f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ 总结:UndefinedBehaviorSanitizer: 未定义行为 ~/usr/bin/../include/c++/v1/ostream:198:13 ~/usr/bin/../include/c++/v1/ios:711:15: 运行时错误:在地址0x7ff7b265a308处调用成员,但该地址未指向'std::ios_base'类型的对象 0x7ff7b265a298: 注意:对象是'std::__1::basic_ostream<char, std::__1::char_traits<char>>'类型对象中偏移量为112的基类子对象 f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ 总结:UndefinedBehaviorSanitizer: 未定义行为 ~/usr/bin/../include/c++/v1/ios:711:15 ~/usr/bin/../include/c++/v1/ios:712:5: 运行时错误:在地址0x7ff7b265a308处进行成员访问,但该地址未指向'std::ios'类型的对象 0x7ff7b265a298: 注意:对象是'std::__1::basic_ostream<char, std::__1::char_traits<char>>'类型对象中偏移量为112的基类子对象 f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ 总结:UndefinedBehaviorSanitizer: 未定义行为 ~/usr/bin/../include/c++/v1/ios:712:5 ~/usr/bin/../include/c++/v1/ios:713:5: 运行时错误:在地址0x7ff7b265a308处进行成员访问,但该地址未指向'std::ios'类型的对象 0x7ff7b265a298: 注意:对象是'std::__1::basic_ostream<char, std::__1::char_traits<char>>'类型对象中偏移量为112的基类子对象 f7 7f 00 00 c8 11 8b 0d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ 总结:UndefinedBehaviorSanitizer: 未定义行为 ~/usr/bin/../include/c++/v1/ios:713:5
内容的提问来源于stack exchange,提问作者user5406764
相关产品推荐
相关产品推荐

