java代码修改触发编译_gcc -O0仍然优化了“未使用”的代码 . 是否有一个编译标志来改变它?...
當我在this question中提出時,gcc正在移除(是的,使用 -O0 )一行代碼 _mm_div_ss(s1, s2); ,大概是因為結果未保存 . 但是,這應該觸發浮點異常并引發SIGFPE,如果刪除調用則不會發生這種情況 .
Question :是否有一個標志或多個標志傳遞給gcc,以便代碼按原樣編譯?我正在考慮像 fno-remove-unused 這樣的東西,但是我支持使用gcc屬性/ pragma代替嗎?
我嘗試過的事情:
$ gcc --help=optimizers | grep -i remove
沒有結果 .
$ gcc --help=optimizers | grep -i unused
沒有結果 .
并明確禁用所有死代碼/消除標志 - 請注意,沒有關于未使用代碼的警告:
$ gcc -O0 -msse2 -Wall -Wextra -pedantic -Winline \
-fno-dce -fno-dse -fno-tree-dce \
-fno-tree-dse -fno-tree-fre -fno-compare-elim -fno-gcse \
-fno-gcse-after-reload -fno-gcse-las -fno-rerun-cse-after-loop \
-fno-tree-builtin-call-dce -fno-tree-cselim a.c
a.c: In function ‘main’:
a.c:25:5: warning: ISO C90 forbids mixed declarations and code [-Wpedantic]
__m128 s1, s2;
^
$
來源計劃
#include
#include
#include
#include
static void sigaction_sfpe(int signal, siginfo_t *si, void *arg)
{
printf("%d,%d,%d\n", signal, si!=NULL?1:0, arg!=NULL?1:0);
printf("inside SIGFPE handler\nexit now.\n");
exit(1);
}
int main()
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = sigaction_sfpe;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGFPE, &sa, NULL);
_mm_setcsr(0x00001D80);
__m128 s1, s2;
s1 = _mm_set_ps(1.0, 1.0, 1.0, 1.0);
s2 = _mm_set_ps(0.0, 0.0, 0.0, 0.0);
_mm_div_ss(s1, s2);
printf("done (no error).\n");
return 0;
}
編譯上面的程序給出了
$ ./a.out
done (no error).
換線
_mm_div_ss(s1, s2);
至
s2 = _mm_div_ss(s1, s2); // add "s2 = "
產生預期的結果:
$ ./a.out
inside SIGFPE handler
編輯更多細節 .
這似乎與 _mm_div_ss definition上的 __always_inline__ 屬性有關 .
$ cat t.c
int
div(int b)
{
return 1/b;
}
int main()
{
div(0);
return 0;
}
$ gcc -O0 -Wall -Wextra -pedantic -Winline t.c -o t.out
$
(沒有警告或錯誤)
$ ./t.out
Floating point exception
$
vs下面(功能屬性除外)
$ cat t.c
__inline int __attribute__((__always_inline__))
div(int b)
{
return 1/b;
}
int main()
{
div(0);
return 0;
}
$ gcc -O0 -Wall -Wextra -pedantic -Winline t.c -o t.out
$
(沒有警告或錯誤)
$ ./t.out
$
添加函數屬性 __warn_unused_result__ 至少會給出一條有用的消息:
$ gcc -O0 -Wall -Wextra -pedantic -Winline t.c -o t.out
t.c: In function ‘main’:
t.c:9:5: warning: ignoring return value of ‘div’, declared with attribute warn_unused_result [-Wunused-result]
div(0);
^
編輯:
關于gcc mailing list的一些討論 . 最終,我認為一切都按預期工作 .
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的java代码修改触发编译_gcc -O0仍然优化了“未使用”的代码 . 是否有一个编译标志来改变它?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java caller_js中的call
- 下一篇: mfc获取子窗口句柄_前端设计-Java