Is generating unreachable code correct?
Closed this issue · 2 comments
David-Gould commented
The generated C for this has unreachable code:
machine unreach;
initial state s {
on TERMINATE -> .done;
on I (guard_foo) clear_foo -> done;
state done {}
state s1 {
on I -> done;
state done {}
}
}
state done {
}
like so:
static int unreach_s_s1_done(struct unreach *self, struct unreach_event *event) {
if (!self || !event) return -1;
switch (event->id) {
case unreach_event_I:
if (1) {
self->state = NULL;
self->state = unreach_s_s1_done;
break;
}
if (guard_foo(self, event)) {
self->state = NULL;
clear_foo(self, event);
self->state = unreach_s_done;
break;
}
break;
The if (guard_foo)
is unreachable and the C compiler complains about it.
clnhlzmn commented
I see why it would do that, and I think the behavior of the generated code is correct. It would definitely be better if it didn't do that so I'll look into it.