---
title: 选项 -fchrec-mul-fold-strict-overflow
description: "乘法折叠优化可正确处理可能引发未定义行为（如整数溢出）的乘法运算。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevkithistory/hgcc/hist-hgcc/kunpenghgcc_06_0049.html
sourcePath: /source/zh/kunpengdevkithistory/hgcc/hist-hgcc/kunpenghgcc_06_0049.html
indexId: 82a54f7e3c8b345f568598a59a0ba85ca9c3b722175d2b037004d2243be18b8771
---
# 选项 -fchrec-mul-fold-strict-overflow

#### 说明

乘法折叠优化可正确处理可能引发未定义行为（如整数溢出）的乘法运算。


#### 使用方法

需开启 -O2 或以上优化等级，同时增加编译选项 -fchrec-mul-fold-strict-overflow。


#### 结果

测试用例如下：


```
typedef int int32_t __attribute__((mode (__SI__)));
 
void bar (int32_t);
 
void
foo ()
{
    int32_t index = 0;
 
    for (index; index <= 10; index--)
    /* Result of the following multiply will overflow
       when converted to signed int32_t.  */
    bar ((0xcafe + index) * 0xdead);
}
```

测试命令：

```
gcc -O2 -fdisable-tree-ethread -fchrec-mul-fold-strict-overflow test.c -S -o test.s
```

图1 选项未打开

图2 选项已打开
