关于Tornado(GCC)编译器对宏优化的问题(100分)
日期:2007-06-18 荐:
关于Tornado(GCC)编译器对宏优化的问题(100分)/*Some type redefinations*/typedef short WORD;typedef unsigned long DWORD;/*The related macro*/#define VALUE1 (WORD)5#define VALUE2 (DWORD)(VALUE1 * 256) /*VALUE2 = 1280*//*The problem location*/void someproblem(){ DWORD dwTarget = 1279; if(dwTarget >= VALUE2) { /*Do something*/ }}以上代码不使用优化选项时没有问题使用-01时会跳至/*Do something*/目标机是ARM,VxWorks以上问题代码关键处反汇编结果是:ldr r3, someproblem 0x410 ;someproblem 0x410明显在代码段中,保存了宏的值 ;经查询,该处保存的值是1278 ;其实下面的代码已经没有意义了cmp r2, r3 ;r2(dwTarget) = 1279, r3(VALUE2) = 1278BLS someproblem 0x100 ;小于跳转请高手指点改为inline函数试试DWORD dwTarget = 1279;改为volatile DWORD dwTarget = 1279;改为inline函数试试===============-01是不对inline关键字优化的DWORD dwTarget = 1279;改为volatile DWORD dwTarget = 1279;================cmp r2, r3 ;r2(dwTarget) = 1279, r3(VALUE2) = 1278很显然,dwTarget没有变化,不需要volatile修饰up一下期待高手出现VALUE2的值不是1280吗? 怎么会是1278,不解.看半天也没看出有什么问题,一切正常,关注...看来只能解释为编译器的bug持续期待高手mk期待期待啊南无阿弥陀佛高手快快出来~~~我是80x86的cpu,我用gcc -O1 -S xxx.c得到(见下面注释):file"wingforce.c".text.globl someproblem.typesomeproblem, @functionsomeproblem:pushl雙 movl%esp, 雙 // 进入函数后马上就退出了.可见优化起了作用.// 所以, if(dwTarget > VALUE2) ... 都省略了.leaveret.sizesomeproblem, .-someproblem.section.note.GNU-stack,"",@progbits
标签: