itemisCREATE / statecharts

YAKINDU Statechart Tools (http://www.statecharts.org)
Eclipse Public License 1.0
174 stars 84 forks source link

[C Generator] Enable -Wunreachable-code #3122

Closed rherrmannr closed 4 years ago

rherrmannr commented 4 years ago

-WAll -WExtra and -pedantic do not detect unreachable code. We need to activate -Wunreachable-code to detect cases like this:

static sc_boolean react(Machine* handle) {
  return false;
  SC_UNUSED(handle);
}
rherrmannr commented 4 years ago

-Wunreachable-code has been removed from GCC: https://gcc.gnu.org/legacy-ml/gcc-help/2011-05/msg00360.html

rherrmannr commented 4 years ago

The unreachable code warning occurs at the react methods. They only use local variables. Thus, we cannot put the SC_UNUSED call in front of the body, as we are defining variables. One way could be creating a new block:

fun react(handle) {
SC_UNUSED(handle)
   { 
      body
   }
}

I don't like this solution at all.

Instead I've improved the check if the handle is required. As we can't test this on the build server, I'm not 100% sure if I got every case. However, this PR will avoid several unreachable-code warnings.