工具/软件:
我们观察到、如果写入地址 0x00000000 (NULL)、编译器不会继续编译函数。
使用优化级别“O1"进行“进行编译时会发生此行为(我们尚未使用更高的优化级别进行测试):

优化级别“-O0"不“不受以下影响:

我们知道不允许写入地址 0x00000000(复位向量)、但我们不会假定出现此类行为。
特别是、在这种情况下、编译器不会报告任何警告或错误。
为了在您这边重现此问题、 我们修改了 SDK 的示例“led_ex1_blinky.c":“:
#include "board.h"
int main (void)
{
Device_init();
Board_init();
/* Compiler stops compilation of `main()` at this point when compiling with optimization level `-O1`.
* No compilation warning or error is reported. However, compiling with `-O0` works as expected. */
uint32_t *const addr = NULL;
(*addr) = 0xdeadbeef;
for(;;)
{
GPIO_writePin(myBoardLED1_GPIO, 0);
DEVICE_DELAY_US(1000000);
GPIO_writePin(myBoardLED1_GPIO, 1);
DEVICE_DELAY_US(1000000);
}
}
我们使用基于 makefile 的构建来构建示例:“gmake -s led_ex1_blinky.c profile={DEBUG_O0|debug_O1}config=flash“
使用的编译器:“TI C29 Clang 编译器 1.0.0.LTS“
提前感谢大家。