热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

clangc++17std::vector在使用-mavx编译时,对齐类型的元素SIGSEGV副本

如何解决《clangc++17std::vector在使用-mavx编译时,对齐类型的元素SIGSEGV副本》经验,您有什么比较好的解决方法?

根据这个问题,我认为在C++ 17中,带有默认分配器的std :: vector应该处理对齐的类型.但是,以下代码

#include 
#include 
#include 
#include 

template
struct alignas(Alignment) AlignedArray : public std::array
{
    friend std::ostream& operator<<(std::ostream& o, const AlignedArray& a)
    {
        std::copy(a.cbegin(), a.cend(), std::ostream_iterator(o, " "));
        return o;
    }
};

int main()
{
    using Array = AlignedArray;
    std::vector v(10);
    for(const auto& e : v)
    {
        auto arr(e);
        std::cout <

arr我用clang 6.0.1编译它时创建的段错误-mavx.没有-mavx开关它运行正常(CPU是E5-2697 v2).我编译了它 clang++ -I/include/c++/v1 -g -mavx -std=c++17 main.cpp -stdlib=libc++ -lc++abi -o alignastest -L/lib -L/lib.我在旧的RHEL 6.9上运行它,我编译了clang 6.0.1和libcxx,libcxxabi.我在另一个系统(Ubuntu 18.10,gcc 8)上进行了测试,它没有任何问题.

子问题

关于对齐,我发现std::aligned_alloclibc ++ 中的实现依赖于C11功能,该功能仅在最近的glibc版本(__config.h)中启用:

#if __GLIBC_PREREQ(2, 17)
#define _LIBCPP_HAS_C11_FEATURES
#endif

不幸的是RHEL 6.9只ldd (GNU libc) 2.12安装了.难道alignas还取决于glibc的版本?


推荐阅读
author-avatar
卢启红
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有