__builtin_memset的-Warray-bounds 警告

一、做了啥?

// 定义了一个结构体
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。但具体啥原因,不清楚编译器咋造成的。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值