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

Return Statement Reachability #60

Closed
redbow-kimee opened this issue Jan 23, 2023 · 2 comments
Closed

Return Statement Reachability #60

redbow-kimee opened this issue Jan 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@redbow-kimee
Copy link
Contributor

Possibly related to #10

Go enforces a syntactic reachability analysis for returns, while C never required that returns be reachable and C compilers which do reachability use more sophisticated algorighms.
Some situations where the return statement is considered reachable (or at least not an issue) by C are not considered reachable by Go.

It appears that cxgo has implemented a bit of checking to implicitly add missing returns (see postproc.go:fixImplicitReturnStmts).
However, I've found a test case which is improperly handled.

#include <stdio.h>

#define TRUE 1
#define FALSE 0

int implicit_return(char* str)
{
    while(TRUE)
    {
        while(TRUE)
        {
            if(*str == '\0') { return 0; }
            else if(*str != 'a') { break; }
            str++;
        }

        printf("%c is not a\n", *str);
        str++;
    }
}

int main()
{
    return implicit_return("aaabaababaaaaa");
}

I believe the last line of this function should have an (actually unreachable) return 0 added to fool Go into believing there is a reachable return 0.

DISTRIBUTION STATEMENT “A”. (Approved for public release. Distribution is unlimited.)

This material is based upon work supported by DARPA under Contract No. HR001122C0047. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of DARPA. DISTRIBUTION STATEMENT “A”. (Approved for public release. Distribution is unlimited.)

@dennwc dennwc added the bug Something isn't working label Jan 24, 2023
@dennwc
Copy link
Contributor

dennwc commented Jan 24, 2023

Thank you for providing a reproducer, I will check why reachability analysis fails for this case.

@dennwc
Copy link
Contributor

dennwc commented Nov 9, 2024

It's fixed in the recent versions, but requires implicit_returns: true option in the config.

@dennwc dennwc closed this as completed Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants