一、做了啥?

// 定义了一个结构体
typedef struct _A
{UINT32 a1;UINT32 a2;
} A;// 声明了一个结构体变量
A a_temp;// 初始化a_temp
for (i = 0; i < sizeof(A)/sizeof(UINT32); i++)
{*(&(a_temp.a1)+ i) = 0;
}

2.出现了什么现象
用o2编译,没有任何问题。
用o3编译,报-Warray-bounds 警告,警告内容如下:

cc1.exe: warning: '__builtin_memset' offset [x, x] from the object at 'A' is out of the bounds of referenced subobject 'a1' with type 'long unsigned int' at offset 0 [-Warray-bounds]
3.原因
应该是编译器的bug,https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92879
O3优化时,for循环初始化,直接用memset代替了,导致出现bug。但具体啥原因,不清楚编译器咋造成的。

另外类似的问题有

[ 72%] Building CXX object smi_lib/CMakeFiles/vastai_smi_static.dir/C_/msys64/home/haoyf/common/smi/vatools_vacc.cpp.obj
In file included from C:/msys64/mingw64/include/c++/12.1.0/vector:60,from C:\msys64\home\haoyf\common\smi\vatools_smi.h:17,from C:\msys64\home\haoyf\common\smi\vatools_smi.cpp:11:
In static member function 'static _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) [with _Tp = long long unsigned int; bool _IsMove = true]',inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = true; _II = long long unsigned int*; _OI = long long unsigned int*]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_algobase.h:495:30,inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = true; _II = long long unsigned int*; _OI = long long unsigned int*]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_algobase.h:522:42,inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = true; _II = long long unsigned int*; _OI = long long unsigned int*]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_algobase.h:529:31,inlined from '_OI std::copy(_II, _II, _OI) [with _II = move_iterator<long long unsigned int*>; _OI = long long unsigned int*]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_algobase.h:620:7,inlined from 'static _ForwardIterator std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<long long unsigned int*>; _ForwardIterator = long long unsigned int*]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_uninitialized.h:147:27,inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = move_iterator<long long unsigned int*>; _ForwardIterator = long long unsigned int*]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_uninitialized.h:185:15,inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = move_iterator<long long unsigned int*>; _ForwardIterator = long long unsigned int*; _Tp = long long unsigned int]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_uninitialized.h:372:37,inlined from '_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = long long unsigned int*; _ForwardIterator = long long unsigned int*; _Allocator = allocator<long long unsigned int>]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_uninitialized.h:397:2,inlined from 'void std::vector<_Tp, _Alloc>::_M_fill_insert(iterator, size_type, const value_type&) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]' at C:/msys64/mingw64/include/c++/12.1.0/bits/vector.tcc:594:7,inlined from 'void std::vector<_Tp, _Alloc>::resize(size_type, const value_type&) [with _Tp = long long unsigned int; _Alloc = std::allocator<long long unsigned int>]' at C:/msys64/mingw64/include/c++/12.1.0/bits/stl_vector.h:1032:18,inlined from 'std::vector<long long unsigned int> vatools::CSMI::GetPcieBandWidth(u32)' at C:\msys64\home\haoyf\common\smi\vatools_smi.cpp:716:19:
C:/msys64/mingw64/include/c++/12.1.0/bits/stl_algobase.h:431:30: warning: 'void* __builtin_memcpy(void*, const void*, long long unsigned int)' offset 16 is out of the bounds [0, 16] [-Warray-bounds]431 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);|             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

类型错误是在模板展开的过程中出现使用类拷贝类型的类方法导致底层stl编译出错。找到位置,使用其他类型的接口进行替换即可。

__builtin_memset的-Warray-bounds 警告相关推荐

  1. 使用cppcheck检测代码警告、错误

    cppcheck是一个C/C++静态检查工具.它可以帮助我们检测出代码存在(潜在)的问题,比如数组越界.内存申请未释放.文件打开未关闭.注意,cppcheck不是编译器,替代不了gcc. 在ubunt ...

  2. 【GCC】gcc警告选项汇总--编辑中|gcc编译选项

    目录 前言 请求或取消警告选项 GCC编译选项 参考原文:https://blog.csdn.net/qq_17308321/article/details/79979514 前言 警告:不是错误的, ...

  3. gcc警告选项汇总 转

    ---------------- 原文链接:https://blog.csdn.net/qq_17308321/article/details/79979514 参考资料:https://gcc.gn ...

  4. C语言报错警告合集(转)

    C常见错误 附录1 常见错误中英文对照表 fatal error C1003: error count exceeds number; stopping compilation 中文对照:(编译错误) ...

  5. 整理iOS 错误警告

    1. App installation failed A valid provisioning profile for this executable was not found. 原因是测试手机上没 ...

  6. 【iOS紫色警告】GPUImage启动摄像头耗时

    当我们pod下GPUImage 后 如果调用摄像头的代码,到启动摄像头会延迟很久,系统虽然不会报错,但是影响用户体验!!! 总结下来! 一共两个问题!!输出如下!!! Main Thread Chec ...

  7. cppcheck卸载linux,使用cppcheck检测代码警告、错误

    cppcheck是一个C/C++静态检查工具.它可以帮助我们检测出代码存在(潜在)的问题,比如数组越界.内存申请未释放.文件打开未关闭.注意,cppcheck不是编译器,替代不了gcc. 在ubunt ...

  8. .cdata matlab,Matlab:AlphaData的警告尺寸必须与CData匹配

    以下代码会产生错误: Warning: Dimensions of AlphaData must be 1x1, or must match CData. 问题是CData是彩色图像,因此有3个维度, ...

  9. 聚宽mysql,聚宽十万个为什么(常见Bug或者警告)

    1 概述Hello,大家好,我们准备收集并整理常见问题,并在此做出解释. 大家有问题,可以在下面跟帖,我们答复并整理. 感谢您的参与. 温馨提示:大多数的异常或者报错,大家复制下报错代码的最后一行,在 ...

最新文章

  1. Windows程序设计------字体不等宽引出的问题及其细节知识
  2. Serverless 时代前端避坑指南
  3. NickLee.FortuneBase数据库sql server版本系统配置说明
  4. Java浮点数内存存储
  5. access 根据id删除数据_小程序云开发之数据库自动备份丨云开发101
  6. 联想gen系列服务器,Hpe Microserver Gen10 Plus开箱
  7. Java LinkedList公共布尔boolean offerFirst(Object o)方法(带示例)
  8. header python 环境信息_python获取网页header头部信息(python小白学习笔记二)
  9. 苹果本周四将发布 OS X Yosemite 公开测试版
  10. 【Xilinx-Petalinux学习】-02-建立PetaLinux工程
  11. 数学建模可以用python吗_Python中常用的数学建模Scipy
  12. python对称加密_【Python】 基于秘钥的对称加密
  13. Arm汇编 位置无关代码 adr 指令
  14. viper12a电源电路图_viper12a电源维修技巧
  15. 单片机双击 长按 c语言,51单片机按键检测源程序(实现单击、双击、长按等功能)...
  16. 《小QQ 大帝国 马化腾传奇》熊江
  17. [附源码]计算机毕业设计小太阳幼儿园学生管理系统Springboot程序
  18. python爬虫 破解js加密有道词典案列的两种方式以及思路总结
  19. android studio使用雷电模拟器详细过程(或其他)
  20. kali wmap使用教程

热门文章

  1. 【开源】ESP32怎样连接NEO6M模块接收GPS数据并显示在oled小屏幕上并可上传数据至Onenet云平台
  2. oracle av rd ms,Oracle AWR报告生成与查看
  3. java bigdecima 除法_java精确除法运算(BigDecimal)
  4. 第八届山东省大学生网络安全技能大赛部分Writeup
  5. ModuleNotFoundError: No module named ‘fitz‘
  6. IDEA 报错These modules have been removed from Maven stucture
  7. java -jar指定main方法
  8. python 工行e企付、工行签名生成、工行私钥PKCS8转PKCS1例子
  9. 极光推送设置别名setAlias失败
  10. SharePoint Framework 1.15 预览版更新 – 新功能发布