Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is generating unreachable code correct? #13

Closed
David-Gould opened this issue Apr 5, 2021 · 2 comments
Closed

Is generating unreachable code correct? #13

David-Gould opened this issue Apr 5, 2021 · 2 comments

Comments

@David-Gould
Copy link

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
Copy link
Owner

clnhlzmn commented Apr 5, 2021

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.

@clnhlzmn
Copy link
Owner

clnhlzmn commented Apr 5, 2021

Fixed in bfbb885.

@clnhlzmn clnhlzmn closed this as completed Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants