【发布时间】:2012-12-19 23:43:45
【问题描述】:
我在 Visual Studio 2012 上使用 /opt:ref /VERBOSE 选项,除了激活“整个程序优化 - > 使用链接时间代码生成”。 /opt:ref 应该删除未使用的函数,尽管我的印象是指定“使用链接时间代码生成”应该默认删除未使用的函数。
在我的测试程序中,我使用了一个我希望从最终可执行文件中删除的测试函数,VS 输出似乎证实了这一点:
Discarded "int __cdecl testMe(int)" (?testMe@@YAHH@Z) from Test.obj
但是查看使用 /FAs 生成的 *.asm 文件,我可以看到列出的函数:
; Function compile flags: /Ogtp
; File c:\users\g.m\documents\visual studio 2012\projects\Test.cpp
; COMDAT ?testMe@@YAHH@Z
_TEXT SEGMENT
?testMe@@YAHH@Z PROC ; testMe, COMDAT
...
那么,它是否从最终图像中删除?
编辑:
需要优化的琐碎代码
static int testMe(int i)
{
return i + 1;
}
int main()
{
auto res = testMe(0);
}
我觉得很可疑的是,即使在 case 函数是“静态”的情况下,它仍然出现在 *.asm 文件中
【问题讨论】: