0

We build our project with Microsoft Visual Studio Professional 2015, Version 14.0.25431.01 Update 3. Exactly the same code gives us compiler warning C4702 (unreachable code) when the solution is built for x86 platform, but no warning, when it is built for x64 platform.

The code looks like this:

if (is_some_condition)
    Func_1();
else
    Func_2();

LOG_MSG("...some logs...")    // ----> compiler warning C4702 here!

Now, both Func_1 and Func_2 have an endless worker loop inside, like this:

void Func_1()
{
   while(true)
   {
      // ...do something...
   }
}

I understand, what the warning is about, but I do not understand, why it occurs only for x86 target and not for x64. What's the difference here? Is the control flow different in any way and why? Please help.

Software Craftsman
  • 2,999
  • 2
  • 31
  • 47
  • 1
    Is the warning enabled for the x64 build? If it is, the compiler is not obligated to perform the unreachable code static analysis, and perhaps for whatever reason the x64 build is unable to do so. – Eljay Dec 21 '17 at 13:26
  • 1
    Have you checked the warning levels in both project configurations to see if they're different? Each build platform has its own set of project properties. Beyond that without seeing the real code it's impossible to suggest anything further. – TypeIA Dec 21 '17 at 13:28
  • 3
    One reason the compiler may not be emitting a warning, even if it is enabled and could theoretically detect the unreachable code through static analysis, is if the cost (in terms of compile time) exceeds some threshold it may drop the static analysis traversal on the floor and carry on. – Eljay Dec 21 '17 at 13:29
  • I also wonder if LOG_MSG is a macro that is being #defined as a no-op in the one configuration (it would in that case not produce a warning since there is no more unreachable code). – TypeIA Dec 21 '17 at 13:30
  • As far as I know, we have a project-wide header file which specifies via `#pragma warning(...)` which warnings should be handled or ignored. This is identical for both target platforms. – Software Craftsman Dec 21 '17 at 13:33
  • 1
    maybe, the warning depends on Func_X to be inlined or not (with the function not inlined in the x64 build for some reason); did you try to __forceinline ? – Massimiliano Janes Dec 21 '17 at 13:36
  • Another data point of sorts, I was unable to reproduce using CL.EXE version 19.00.24215.1, using both x64 and x86 versions. I used `cl /nologo /EHsc /Wall test.cpp`, with what I assumed is a minimal example of your scenario. – Eljay Dec 21 '17 at 14:09
  • Have you verified that all the properties for C++ are identical? – Jive Dadson Dec 21 '17 at 15:30
  • 2
    @Eljay You need to include optimization (`/Ox` at a minimum) in your test. – 1201ProgramAlarm Dec 21 '17 at 17:16
  • @1201ProgramAlarm • thanks for the tip! Adding `/Ox`, I got C4702 unreachable code for both x86 and x64. – Eljay Dec 21 '17 at 17:30

0 Answers0