How to make Visual C ++ 9 not emit code that actually never gets called?

My native C ++ COM component uses ATL. In DllRegisterServer()I call CComModule::RegisterServer():

STDAPI DllRegisterServer()
{
    return _Module.RegisterServer(FALSE); // <<< notice FALSE here
}

FALSE passed to indicate not to register a type library.

ATL is available as sources, so I am actually compiling the implementation CComModule::RegisterServer(). Somewhere in the call stack there is an instruction if:

if( doRegisterTypeLibrary ) { //<< FALSE goes here
  // do some stuff, then call RegisterTypeLib()
}

The compiler sees all the above code and therefore can see that in fact the condition is ifalways false, but when I check the linker promotion messages, I see that the link to the link RegisterTypeLib()still exists, so the statement is ifnot resolved.

Visual ++ 9 , - ?

+3
5

, .

"". " ". ++ → Optimization - " * " ". Linker → Optimization - Time Time Code Generation " ". /OPT: REF /OPT: ICF (, * Linker → Optimization) .

RegisterTypeLib() - .

0

[/GL]? , .

+1

, /? ASM?

RegisterTypeLib? , - dllexport , , ( ), , . , , ( , ), - , , .

+1

, , . , . inline - ,

+1

AtlComModuleRegisterServer , , , bRegTypeLib . .

DllInstall(...) CAtlDllModuleT::RegisterServer(0). :

push    0
call    ?DllRegisterServer@?$CAtlDllModuleT@VCAtlTestModule@@@ATL@@QAEJH@Z

, CAtlDllModuleT::DllRegisterServer , 0/FALSE ... AtlComModuleRegisterServer, ( ) . , cdecl...

?DllRegisterServer@?$CAtlDllModuleT@VCAtlTestModule@@@ATL@@QAEJH@Z proc near
<trimmed>
push    0
push    edx
push    offset ATL::_AtlComModule
call    _AtlComModuleRegisterServer@12

- , . , , .

+1

Source: https://habr.com/ru/post/1737120/


All Articles